Spaces:
Runtime error
Runtime error
Commit ·
aa2f1de
1
Parent(s): dc9b0af
Upload chat.py
Browse files
chat.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
+
theme = gr.themes.Base(
|
| 5 |
+
secondary_hue="gray",
|
| 6 |
+
)
|
| 7 |
+
with gr.Blocks(theme=theme) as demo:
|
| 8 |
+
chatbot = gr.Chatbot(label="SRF Interactive Chatbot",show_share_button="true",layout="panel")
|
| 9 |
+
msg = gr.Textbox(label="Ask me any question",placeholder="Send us a message")
|
| 10 |
+
btn = gr.Button(value="Submit")
|
| 11 |
+
clear = gr.ClearButton([msg, chatbot])
|
| 12 |
+
|
| 13 |
+
def respond(message, chat_history):
|
| 14 |
+
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
| 15 |
+
chat_history.append((message, bot_message))
|
| 16 |
+
time.sleep(2)
|
| 17 |
+
return "", chat_history
|
| 18 |
+
|
| 19 |
+
btn.click(respond, [msg, chatbot], [msg, chatbot])
|
| 20 |
+
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
demo.launch()
|