Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
with gr.Blocks() as demo:
|
| 6 |
+
chatbot = gr.Chatbot(type="messages")
|
| 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?", "Today is a great day", "I'm very hungry"])
|
| 12 |
+
chat_history.append({"role": "user", "content": message})
|
| 13 |
+
chat_history.append({"role": "assistant", "content": bot_message})
|
| 14 |
+
time.sleep(2)
|
| 15 |
+
return "", chat_history
|
| 16 |
+
|
| 17 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 18 |
+
|
| 19 |
+
if __name__ == "__main__":
|
| 20 |
+
demo.launch()
|