mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-27 01:40:20 +08:00
4729457929
* clear button * restore * button in interface * changelog * fixes * simplify * changes * components * changed dropdown behavior * fix label * add tests * update demos * changelog * changelog * restore * formatting * revert dropdown * frontend changes * other fixes * changelog * update guide * future * fix tests * fix tests * fix tests * changelog * update guide
29 lines
823 B
Python
29 lines
823 B
Python
import gradio as gr
|
|
import random
|
|
import time
|
|
|
|
with gr.Blocks() as demo:
|
|
chatbot = gr.Chatbot()
|
|
msg = gr.Textbox()
|
|
clear = gr.ClearButton([msg, chatbot])
|
|
|
|
def user(user_message, history):
|
|
return gr.update(value="", interactive=False), history + [[user_message, None]]
|
|
|
|
def bot(history):
|
|
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
|
history[-1][1] = ""
|
|
for character in bot_message:
|
|
history[-1][1] += character
|
|
time.sleep(0.05)
|
|
yield history
|
|
|
|
response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
|
bot, chatbot, chatbot
|
|
)
|
|
response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
|
|
|
|
demo.queue()
|
|
if __name__ == "__main__":
|
|
demo.launch()
|