Roland Ding commited on
Commit
2d71161
1 Parent(s): 7bd55eb

v0.1.8 updated the chatbot.py into app.py for running in hugging face space.

Browse files
Files changed (3) hide show
  1. .gitignore +2 -0
  2. app.py +59 -0
  3. chatbot.py +0 -59
.gitignore CHANGED
@@ -1,3 +1,5 @@
 
 
1
  venv
2
  __pycache__
3
 
 
1
+ # directories that are local to the server os
2
+ .archive
3
  venv
4
  __pycache__
5
 
app.py CHANGED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from supplier import *
3
+
4
+ background_examples=[
5
+ "This is a friendly chatbot with humour.", # casual setting
6
+ "This is the first date between virtual human and real human.", # romantic setting
7
+ "We are at the mideval castle, I am talking to my chatbot donkey.", # fantasy setting
8
+ ]
9
+
10
+ with gr.Blocks() as settings:
11
+ with gr.Row():
12
+ background = gr.TextArea(sys_msg[0]["content"],lines=5,label="Current background")
13
+ with gr.Column():
14
+ def update_sys(text):
15
+ sys_msg[0].update({"content":text})
16
+ return text
17
+
18
+ background_edit = gr.Textbox(placeholder="change the background here",label="update background",lines = 5)
19
+ background_edit.submit(update_sys,background_edit,background)
20
+ with gr.Row():
21
+ clear = gr.Button("Clear")
22
+ submit = gr.Button("Submit")
23
+
24
+ gr.Examples(background_examples,background_edit,label="Examples")
25
+ clear.click(lambda:None,None,background_edit,queue=False)
26
+ submit.click(update_sys,background_edit,background,queue=False)
27
+
28
+ with gr.Blocks() as chat_window:
29
+ with gr.Row():
30
+ with gr.Column():
31
+ chatbot = gr.Chatbot(initial_msg)
32
+ clear = gr.Button("Clear")
33
+
34
+ with gr.Column():
35
+ msg = gr.Textbox()
36
+ submit = gr.Button("Submit")
37
+ gr.Examples(["Hello","How are you?"],msg,label="Examples")
38
+
39
+ audio = gr.Audio(source="microphone",type="filepath")
40
+ # gr.Interface(translate,inputs=gr.Audio(source="microphone",type="filepath"),outputs = "text")
41
+
42
+ audio.change(translate,audio,msg,queue=False)
43
+ msg.submit(send_chat,[msg,chatbot],[msg,chatbot])
44
+ submit.click(send_chat,[msg,chatbot],[msg,chatbot],queue=False)
45
+
46
+ clear.click(lambda:None,None,chatbot,queue=False)
47
+
48
+ iface = gr.TabbedInterface(
49
+ [chat_window,settings],
50
+ ["Chat","Settings"],
51
+ title="ChatGPT 3.5",
52
+ css="footer {visibility: hidden}")
53
+
54
+ if __name__ == "__main__":
55
+ iface.launch(
56
+ server_name="0.0.0.0",
57
+ ssl_verify=False,
58
+ ssl_certfile="./cert.pem",
59
+ ssl_keyfile="./key.pem")
chatbot.py DELETED
@@ -1,59 +0,0 @@
1
- import gradio as gr
2
- from supplier import *
3
-
4
- background_examples=[
5
- "This is a friendly chatbot with humour.", # casual setting
6
- "This is the first date between virtual human and real human.", # romantic setting
7
- "We are at the mideval castle, I am talking to my chatbot donkey.", # fantasy setting
8
- ]
9
-
10
- with gr.Blocks() as settings:
11
- with gr.Row():
12
- background = gr.TextArea(sys_msg[0]["content"],lines=5,label="Current background")
13
- with gr.Column():
14
- def update_sys(text):
15
- sys_msg[0].update({"content":text})
16
- return text
17
-
18
- background_edit = gr.Textbox(placeholder="change the background here",label="update background",lines = 5)
19
- background_edit.submit(update_sys,background_edit,background)
20
- with gr.Row():
21
- clear = gr.Button("Clear")
22
- submit = gr.Button("Submit")
23
-
24
- gr.Examples(background_examples,background_edit,label="Examples")
25
- clear.click(lambda:None,None,background_edit,queue=False)
26
- submit.click(update_sys,background_edit,background,queue=False)
27
-
28
- with gr.Blocks() as chat_window:
29
- with gr.Row():
30
- with gr.Column():
31
- chatbot = gr.Chatbot(initial_msg)
32
- clear = gr.Button("Clear")
33
-
34
- with gr.Column():
35
- msg = gr.Textbox()
36
- submit = gr.Button("Submit")
37
- gr.Examples(["Hello","How are you?"],msg,label="Examples")
38
-
39
- audio = gr.Audio(source="microphone",type="filepath")
40
- # gr.Interface(translate,inputs=gr.Audio(source="microphone",type="filepath"),outputs = "text")
41
-
42
- audio.change(translate,audio,msg,queue=False)
43
- msg.submit(send_chat,[msg,chatbot],[msg,chatbot])
44
- submit.click(send_chat,[msg,chatbot],[msg,chatbot],queue=False)
45
-
46
- clear.click(lambda:None,None,chatbot,queue=False)
47
-
48
- iface = gr.TabbedInterface(
49
- [chat_window,settings],
50
- ["Chat","Settings"],
51
- title="ChatGPT 3.5",
52
- css="footer {visibility: hidden}")
53
-
54
- if __name__ == "__main__":
55
- iface.launch(
56
- server_name="0.0.0.0",
57
- ssl_verify=False,
58
- ssl_certfile="./cert.pem",
59
- ssl_keyfile="./key.pem")