gradio/demo/copy_events/run.py
Abubakar Abid e7629f7eac
Adds copy event to gr.Markdown, gr.Chatbot, and gr.Textbox (#9979)
* add copy event

* add changeset

* test

* demo

* changes

* add changeset

* add list format

* typing

* notebook

* copy events'

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
2024-11-19 19:58:19 +00:00

23 lines
685 B
Python

import gradio as gr
md = "This is **bold** text."
def copy_callback(copy_data: gr.CopyData):
return copy_data.value
with gr.Blocks() as demo:
textbox = gr.Textbox(label="Copied text")
with gr.Row():
markdown = gr.Markdown(value=md, header_links=True, height=400, show_copy_button=True)
chatbot = gr.Chatbot([("Hello", "World"), ("Goodbye", "World")], show_copy_button=True)
textbox2 = gr.Textbox("Write something here", interactive=True, show_copy_button=True)
gr.on(
[markdown.copy, chatbot.copy, textbox2.copy],
copy_callback,
outputs=textbox
)
if __name__ == "__main__":
demo.launch()