Antoine245 commited on
Commit
172982e
0 Parent(s):

Duplicate from Antoine245/bot

Browse files
Files changed (4) hide show
  1. .gitattributes +35 -0
  2. README.md +34 -0
  3. app.py +69 -0
  4. requirements.txt +1 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Bot
3
+ emoji: 🦀
4
+ colorFrom: indigo
5
+ colorTo: pink
6
+ sdk: gradio
7
+ app_file: app.py
8
+ pinned: false
9
+ license: openrail
10
+ duplicated_from: Antoine245/bot
11
+ ---
12
+
13
+ # Easy Chatbot with PaLM API
14
+
15
+ 1. go to https://makersuite.google.com/app/home
16
+ 2. create your bot in the chat prompt
17
+ 3. change app.py file with your own context and examples
18
+ 4. add your own palm api key https://makersuite.google.com/app/apikey to your HF environment (cf https://huggingface.co/docs/huggingface_hub/guides/manage-spaces)
19
+ 5. ready to use chatbot that can be used as embedded in any websites (cf https://comparateur-image.web.app/bot/)
20
+
21
+
22
+ ### Errors
23
+
24
+ 1. clear button (gr.ClearButton needs a fix in embedded websites), I use a basic button until fixed
25
+
26
+ ### Use community if any question/request
27
+
28
+ ### Please check mkersuite quickstart
29
+
30
+ Makersuite allows you to change context and examples in order to get the best chatbot and then export the code. You can then try it in gradio by cloning this space and changing context and examples.
31
+
32
+ Check out https://developers.generativeai.google/tutorials/makersuite_quickstart
33
+
34
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import time
4
+ import google.generativeai as palm
5
+
6
+ palm.configure(api_key=os.environ.get("palm_key"))
7
+
8
+ defaults = {
9
+ 'model': 'models/chat-bison-001',
10
+ 'temperature': 0.25,
11
+ 'candidate_count': 1,
12
+ 'top_k': 40,
13
+ 'top_p': 0.95,
14
+ }
15
+
16
+ context = "Your IT assistant"
17
+
18
+ examples = [
19
+ [
20
+ "Hey my computer is broken",
21
+ "Hey, what is the issue with your computer?"
22
+ ]
23
+ ]
24
+
25
+ history = ['']
26
+
27
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
28
+ chatbot = gr.Chatbot()
29
+ msg = gr.Textbox()
30
+ btn = gr.Button("Submit", variant="primary")
31
+ # gr.ClearButton([msg, chatbot])
32
+ clear = gr.Button("Clear")
33
+
34
+ def user(user_message, history):
35
+ return gr.update(value=""), history + [[user_message, None]]
36
+
37
+ def bot(history):
38
+ try:
39
+ bot_message = palm.chat(
40
+ context=context,
41
+ examples=examples,
42
+ messages=history[-1][0]
43
+ )
44
+
45
+ history[-1][1] = ""
46
+ for character in bot_message.last:
47
+ history[-1][1] += character
48
+ time.sleep(0.005)
49
+ except Exception as e:
50
+ # Handle the exception here
51
+ print("Error occurred:", str(e))
52
+ # You can customize the error handling as per your requirements
53
+ # For example, return an error message to the user
54
+
55
+ history[-1][1] = "Incorrect input please retry with a longer sentence in english"
56
+
57
+ return history
58
+
59
+ response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
60
+ bot, chatbot, chatbot
61
+ )
62
+ response = btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
63
+ bot, chatbot, chatbot
64
+ )
65
+ response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
66
+ clear.click(lambda: None, None, chatbot, queue=False)
67
+
68
+ demo.queue()
69
+ demo.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ google-generativeai