Spaces:
Sleeping
Sleeping
thunder-007
commited on
Commit
•
b8edde2
1
Parent(s):
1fa44fc
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import time
|
4 |
+
from thunder_gpt import get_response
|
5 |
+
|
6 |
+
with gr.Blocks() as demo:
|
7 |
+
gr.Markdown("Chat bot for cranberry task")
|
8 |
+
chatbot = gr.Chatbot()
|
9 |
+
msg = gr.Textbox()
|
10 |
+
clear = gr.Button("Clear")
|
11 |
+
|
12 |
+
|
13 |
+
def user(user_message, history):
|
14 |
+
return "", history + [[user_message, None]]
|
15 |
+
|
16 |
+
|
17 |
+
def bot(history):
|
18 |
+
question = history[-1][0]
|
19 |
+
answer = get_response(question)
|
20 |
+
history[-1][1] = ""
|
21 |
+
for character in answer:
|
22 |
+
history[-1][1] += character
|
23 |
+
time.sleep(0.02)
|
24 |
+
yield history
|
25 |
+
|
26 |
+
|
27 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
28 |
+
bot, chatbot, chatbot
|
29 |
+
)
|
30 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
31 |
+
|
32 |
+
demo.queue()
|
33 |
+
demo.launch()
|