Spaces:
Sleeping
Sleeping
Commit ·
7432f2e
1
Parent(s): 5a833a9
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
import time
|
|
@@ -5,15 +7,23 @@ import time
|
|
| 5 |
with gr.Blocks() as demo:
|
| 6 |
chatbot = gr.Chatbot()
|
| 7 |
msg = gr.Textbox()
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
def
|
| 12 |
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
msg.submit(
|
|
|
|
|
|
|
|
|
|
| 18 |
|
|
|
|
| 19 |
demo.launch()
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
import random
|
| 5 |
import time
|
|
|
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
chatbot = gr.Chatbot()
|
| 9 |
msg = gr.Textbox()
|
| 10 |
+
clear = gr.ClearButton([msg, chatbot])
|
| 11 |
+
|
| 12 |
+
def user(user_message, history):
|
| 13 |
+
return gr.update(value="", interactive=False), history + [[user_message, None]]
|
| 14 |
|
| 15 |
+
def bot(history):
|
| 16 |
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
| 17 |
+
history[-1][1] = ""
|
| 18 |
+
for character in bot_message:
|
| 19 |
+
history[-1][1] += character
|
| 20 |
+
time.sleep(0.05)
|
| 21 |
+
yield history
|
| 22 |
|
| 23 |
+
response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 24 |
+
bot, chatbot, chatbot
|
| 25 |
+
)
|
| 26 |
+
response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
|
| 27 |
|
| 28 |
+
demo.queue()
|
| 29 |
demo.launch()
|