Spaces:
Sleeping
Sleeping
Trying out Blocks with Gradio chat
Browse files
app.py
CHANGED
|
@@ -1,9 +1,18 @@
|
|
| 1 |
-
import time
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
for i in range(len(message)):
|
| 6 |
-
time.sleep(0.3)
|
| 7 |
-
yield "You typed: " + message[: i+1]
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
| 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 respond(message, chat_history):
|
| 11 |
+
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
| 12 |
+
chat_history.append((message, bot_message))
|
| 13 |
+
time.sleep(2)
|
| 14 |
+
return "", chat_history
|
| 15 |
|
| 16 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
demo.launch()
|