cstr commited on
Commit
9f34c41
Β·
verified Β·
1 Parent(s): 7dadb62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -28
app.py CHANGED
@@ -487,39 +487,31 @@ def send_to_model_impl(prompt, model_selection, hf_model_choice, hf_custom_model
487
  # Create HTML with JavaScript using string formatting
488
  html_template = '''
489
  <script>
490
- try {
491
- const textToCopy = "%s";
492
- navigator.clipboard.writeText(textToCopy)
493
- .then(() => {
494
- document.getElementById('clipboard_status').textContent = 'βœ… Copied to clipboard!';
495
- setTimeout(() => {
496
- document.getElementById('clipboard_status').textContent = '';
497
- }, 2000);
498
- })
499
- .catch(err => {
500
- console.error('Copy failed:', err);
501
- // Fallback
502
- const textarea = document.createElement('textarea');
503
- textarea.value = textToCopy;
504
- document.body.appendChild(textarea);
505
- textarea.select();
506
- document.execCommand('copy');
507
- document.body.removeChild(textarea);
508
- document.getElementById('clipboard_status').textContent = 'βœ… Copied to clipboard!';
509
- setTimeout(() => {
510
- document.getElementById('clipboard_status').textContent = '';
511
- }, 2000);
512
- });
513
- } catch(err) {
514
- console.error('Copy error:', err);
515
- document.getElementById('clipboard_status').textContent = '❌ Copy failed. Try again.';
516
  setTimeout(() => {
517
  document.getElementById('clipboard_status').textContent = '';
518
  }, 2000);
519
  }
 
520
  </script>
521
  <div id="clipboard_status" style="color: green; font-weight: bold;"></div>
522
- '''
523
 
524
  # Return all three expected outputs:
525
  # 1. HTML component for status
@@ -576,7 +568,7 @@ def send_to_model_impl(prompt, model_selection, hf_model_choice, hf_custom_model
576
  if not summary.startswith("Error"):
577
  with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.txt') as f:
578
  f.write(summary)
579
- return summary, f.name
580
 
581
  return gr.HTML(""), summary, download_file
582
 
 
487
  # Create HTML with JavaScript using string formatting
488
  html_template = '''
489
  <script>
490
+ async function copyToClipboard(text) {
491
+ try {
492
+ // Modern API
493
+ await navigator.clipboard.writeText(text);
494
+ document.getElementById('clipboard_status').textContent = 'βœ… Copied to clipboard!';
495
+ } catch (err) {
496
+ console.error('Modern API failed, fallback to textarea method', err);
497
+ // Fallback method
498
+ const textarea = document.createElement('textarea');
499
+ textarea.value = text;
500
+ document.body.appendChild(textarea);
501
+ textarea.select();
502
+ document.execCommand('copy');
503
+ document.body.removeChild(textarea);
504
+ document.getElementById('clipboard_status').textContent = 'βœ… Copied to clipboard!';
505
+ }
506
+ // Clear message after 2 seconds
 
 
 
 
 
 
 
 
 
507
  setTimeout(() => {
508
  document.getElementById('clipboard_status').textContent = '';
509
  }, 2000);
510
  }
511
+ copyToClipboard("%s");
512
  </script>
513
  <div id="clipboard_status" style="color: green; font-weight: bold;"></div>
514
+ '''
515
 
516
  # Return all three expected outputs:
517
  # 1. HTML component for status
 
568
  if not summary.startswith("Error"):
569
  with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.txt') as f:
570
  f.write(summary)
571
+ return gr.HTML(""), summary, f.name
572
 
573
  return gr.HTML(""), summary, download_file
574