mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-24 10:54:04 +08:00
2a30deed84
* fix a copy button duplication bug in chatbot * fix copy button invalid issue * Update CHANGELOG.md: Fixed Copy Button * fix changelog typo * switch to static HTML + event delegation for copy button * fix * format + notebooks * format + notebooks --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: pngwn <hello@pngwn.io>
30 lines
631 B
Python
30 lines
631 B
Python
import gradio as gr
|
|
import random
|
|
import time
|
|
|
|
md = """This is some code:
|
|
|
|
<h1>hello</h1>
|
|
|
|
```py
|
|
def fn(x, y, z):
|
|
print(x, y, z)
|
|
"""
|
|
|
|
with gr.Blocks() as demo:
|
|
chatbot = gr.Chatbot()
|
|
msg = gr.Textbox()
|
|
clear = gr.Button("Clear")
|
|
|
|
def respond(message, chat_history):
|
|
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
|
chat_history.append((message, md))
|
|
time.sleep(1)
|
|
return "", chat_history
|
|
|
|
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
|
clear.click(lambda: None, None, chatbot, queue=False)
|
|
|
|
if __name__ == "__main__":
|
|
demo.launch()
|