2023-03-13 22:21:03 +08:00
|
|
|
import gradio as gr
|
|
|
|
import random
|
|
|
|
import time
|
|
|
|
|
|
|
|
with gr.Blocks() as demo:
|
|
|
|
chatbot = gr.Chatbot()
|
|
|
|
msg = gr.Textbox()
|
|
|
|
clear = gr.Button("Clear")
|
|
|
|
|
2023-04-20 02:38:11 +08:00
|
|
|
def respond(message, chat_history):
|
|
|
|
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
2023-06-06 09:11:53 +08:00
|
|
|
chat_history.append((message, bot_message))
|
|
|
|
time.sleep(2)
|
2023-04-20 02:38:11 +08:00
|
|
|
return "", chat_history
|
2023-03-13 22:21:03 +08:00
|
|
|
|
2023-04-20 02:38:11 +08:00
|
|
|
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
2023-03-13 22:21:03 +08:00
|
|
|
clear.click(lambda: None, None, chatbot, queue=False)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
demo.launch()
|