Spaces:
Sleeping
Sleeping
A
commited on
Commit
•
120874c
1
Parent(s):
9b87ee5
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import time
|
4 |
+
|
5 |
+
with gr.Blocks() as demo:
|
6 |
+
chatbot = gr.Chatbot()
|
7 |
+
msg = gr.Textbox()
|
8 |
+
clear = gr.Button("Clear")
|
9 |
+
|
10 |
+
def user(user_message, history):
|
11 |
+
return "", history + [[user_message, None]]
|
12 |
+
|
13 |
+
def bot(history):
|
14 |
+
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
15 |
+
history[-1][1] = ""
|
16 |
+
for character in bot_message:
|
17 |
+
history[-1][1] += character
|
18 |
+
time.sleep(0.05)
|
19 |
+
yield history
|
20 |
+
|
21 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
22 |
+
bot, chatbot, chatbot
|
23 |
+
)
|
24 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
25 |
+
|
26 |
+
demo.queue()
|
27 |
+
demo.launch()
|