Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
.
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
.
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 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 |
|