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