Download core/frontend_copy.py from deeme/long: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/deeme/long/resolve/main/core/frontend_copy.py
- Command line
-
hf download hf://spaces/deeme/long/core/frontend_copy.py
-
curl -L -o frontend_copy.py https://huggingface.co/spaces/deeme/long/resolve/main/core/frontend_copy.py
1.1 kB
| import gradio as gr | |
| enable_copy_js = """ | |
| <script> | |
| document.addEventListener('copy', function(e) { | |
| // 获取选中的文本 | |
| var selectedText = window.getSelection().toString(); | |
| if(selectedText) { | |
| // 直接触发 gradio 组件的更新 | |
| const textbox = document.getElementById('copy_textbox'); | |
| if(textbox) { | |
| textbox.querySelector('textarea').value = selectedText; | |
| // 触发 change 事件以更新 Gradio 状态 | |
| textbox.querySelector('textarea').dispatchEvent(new Event('input', { bubbles: true })); | |
| } | |
| } | |
| }); | |
| </script> | |
| """ | |
| def on_copy(fn, inputs, outputs): | |
| copy_textbox = gr.Textbox(elem_id="copy_textbox", visible=False) | |
| return copy_textbox.change(fn, [copy_textbox] + inputs, outputs) | |
| # with gr.Blocks(head=enable_copy_js) as demo: | |
| # gr.Markdown("Hello\nTest Copy") | |
| # copy_textbox = gr.Textbox(elem_id="copy_textbox", visible=False) | |
| # def copy_handle(text): | |
| # gr.Info(text) | |
| # copy_textbox.change(copy_handle, copy_textbox) | |
| # demo.launch() |