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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -23
app.py CHANGED
@@ -486,31 +486,65 @@ def send_to_model_impl(prompt, model_selection, hf_model_choice, hf_custom_model
486
 
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:
 
486
 
487
  # Create HTML with JavaScript using string formatting
488
  html_template = '''
489
+ <div style="text-align: center; margin: 10px;">
490
+ <button
491
+ onclick="
492
+ try {
493
+ // Try all possible selectors for the prompt textarea
494
+ const promptArea =
495
+ document.querySelector('#generated_prompt textarea') ||
496
+ document.querySelector('textarea#generated_prompt') ||
497
+ document.querySelector('.generated_prompt textarea') ||
498
+ Array.from(document.querySelectorAll('textarea')).find(el => el.value.includes('Summarize'));
499
+
500
+ if (promptArea && promptArea.value) {
501
+ navigator.clipboard.writeText(promptArea.value)
502
+ .then(() => {
503
+ this.textContent = 'βœ… Copied to clipboard!';
504
+ setTimeout(() => {
505
+ this.textContent = 'πŸ“‹ Copy Text to Clipboard';
506
+ }, 2000);
507
+ })
508
+ .catch(err => {
509
+ console.error('Modern copy failed:', err);
510
  // Fallback method
511
+ promptArea.select();
 
 
 
512
  document.execCommand('copy');
513
+ this.textContent = 'βœ… Copied to clipboard!';
514
+ setTimeout(() => {
515
+ this.textContent = 'πŸ“‹ Copy Text to Clipboard';
516
+ }, 2000);
517
+ });
518
+ } else {
519
+ this.textContent = '❌ No text found. Generate one first.';
520
+ setTimeout(() => {
521
+ this.textContent = 'πŸ“‹ Copy Text to Clipboard';
522
+ }, 2000);
523
+ }
524
+ } catch (err) {
525
+ console.error('Copy error:', err);
526
+ this.textContent = '❌ Copy failed. Try again.';
527
+ setTimeout(() => {
528
+ this.textContent = 'πŸ“‹ Copy Text to Clipboard';
529
+ }, 2000);
530
+ }
531
+ "
532
+ style="
533
+ padding: 10px 20px;
534
+ background-color: #2C3E50;
535
+ color: white;
536
+ border: none;
537
+ border-radius: 5px;
538
+ font-weight: bold;
539
+ cursor: pointer;
540
+ transition: background-color 0.3s ease;
541
+ "
542
+ onmouseover="this.style.backgroundColor='#34495E'"
543
+ onmouseout="this.style.backgroundColor='#2C3E50'"
544
+ >
545
+ πŸ“‹ Copy Text to Clipboard
546
+ </button>
547
+ </div>
548
  '''
549
 
550
  # Return all three expected outputs: