qqwjq1981 commited on
Commit
27acc6d
·
verified ·
1 Parent(s): be02f5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -325,15 +325,23 @@ with gr.Blocks() as demo:
325
  with gr.Column():
326
  reflection_btn = gr.Button("Generate reflection")
327
  reflection_output = gr.Textbox(label="Reflections", lines=5)
328
- copy_btn = gr.Button("Copy to clipboard")
329
-
330
- # Connect the button to the JS function for copying
331
- copy_btn.click(
332
- None,
333
- inputs=[reflection_output],
334
- outputs=[],
335
- _js=f"copyToClipboard"
336
- )
 
 
 
 
 
 
 
 
337
 
338
  fetch_btn.click(
339
  process_webpage,
@@ -353,8 +361,7 @@ with gr.Blocks() as demo:
353
  outputs=reflection_output,
354
  )
355
 
356
- demo.launch(share=True, custom_js=copy_to_clipboard_js)
357
-
358
 
359
- # In[ ]:
360
 
 
 
325
  with gr.Column():
326
  reflection_btn = gr.Button("Generate reflection")
327
  reflection_output = gr.Textbox(label="Reflections", lines=5)
328
+ # Custom HTML and JS for copy-to-clipboard
329
+ custom_js = """
330
+ <script>
331
+ function copyToClipboard() {
332
+ const textbox = document.querySelector("textarea[aria-label='Reflections']");
333
+ if (textbox) {
334
+ navigator.clipboard.writeText(textbox.value).then(() => {
335
+ alert("Text copied to clipboard!");
336
+ }).catch(err => {
337
+ alert("Failed to copy text: " + err);
338
+ });
339
+ }
340
+ }
341
+ </script>
342
+ <button onclick="copyToClipboard()">Copy to clipboard</button>
343
+ """
344
+ gr.HTML(custom_js)
345
 
346
  fetch_btn.click(
347
  process_webpage,
 
361
  outputs=reflection_output,
362
  )
363
 
364
+ demo.launch(share=True)
 
365
 
 
366
 
367
+ # In[ ]: