Spaces:
Runtime error
Runtime error
Commit
·
8e7e7eb
1
Parent(s):
66e9a55
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.ClearButton([msg, chatbot])
|
| 9 |
+
|
| 10 |
+
def user(user_message, history):
|
| 11 |
+
return gr.update(value="", interactive=False), 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 |
+
response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 22 |
+
bot, chatbot, chatbot
|
| 23 |
+
)
|
| 24 |
+
response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
|
| 25 |
+
|
| 26 |
+
demo.queue()
|
| 27 |
+
demo.launch()
|