Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -502,44 +502,46 @@ def send_to_model_impl(prompt, model_selection, hf_model_choice, hf_custom_model
|
|
502 |
|
503 |
try:
|
504 |
if model_selection == "Clipboard only":
|
|
|
|
|
505 |
|
506 |
-
#
|
507 |
-
|
508 |
-
f"""
|
509 |
<script>
|
510 |
-
try {
|
511 |
-
|
512 |
-
|
|
|
513 |
document.getElementById('clipboard_status').textContent = 'β
Copied to clipboard!';
|
514 |
-
setTimeout(() => {
|
515 |
document.getElementById('clipboard_status').textContent = '';
|
516 |
-
}
|
517 |
-
}
|
518 |
-
.catch(err => {
|
519 |
console.error('Copy failed:', err);
|
520 |
// Fallback
|
521 |
const textarea = document.createElement('textarea');
|
522 |
-
textarea.value =
|
523 |
document.body.appendChild(textarea);
|
524 |
textarea.select();
|
525 |
document.execCommand('copy');
|
526 |
document.body.removeChild(textarea);
|
527 |
document.getElementById('clipboard_status').textContent = 'β
Copied to clipboard!';
|
528 |
-
setTimeout(() => {
|
529 |
document.getElementById('clipboard_status').textContent = '';
|
530 |
-
}
|
531 |
-
}
|
532 |
-
}
|
533 |
console.error('Copy error:', err);
|
534 |
document.getElementById('clipboard_status').textContent = 'β Copy failed. Try again.';
|
535 |
-
setTimeout(() => {
|
536 |
document.getElementById('clipboard_status').textContent = '';
|
537 |
-
}
|
538 |
-
}
|
539 |
</script>
|
540 |
<div id="clipboard_status" style="color: green; font-weight: bold;"></div>
|
541 |
-
|
542 |
-
), None
|
543 |
|
544 |
# Get the summary based on model selection
|
545 |
if model_selection == "HuggingFace Inference":
|
|
|
502 |
|
503 |
try:
|
504 |
if model_selection == "Clipboard only":
|
505 |
+
# Escape the prompt for JavaScript
|
506 |
+
escaped_prompt = prompt.replace('"', '\\"').replace("'", "\\'").replace('\n', '\\n')
|
507 |
|
508 |
+
# Create HTML with JavaScript using string formatting
|
509 |
+
html_template = '''
|
|
|
510 |
<script>
|
511 |
+
try {
|
512 |
+
const textToCopy = "%s";
|
513 |
+
navigator.clipboard.writeText(textToCopy)
|
514 |
+
.then(() => {
|
515 |
document.getElementById('clipboard_status').textContent = 'β
Copied to clipboard!';
|
516 |
+
setTimeout(() => {
|
517 |
document.getElementById('clipboard_status').textContent = '';
|
518 |
+
}, 2000);
|
519 |
+
})
|
520 |
+
.catch(err => {
|
521 |
console.error('Copy failed:', err);
|
522 |
// Fallback
|
523 |
const textarea = document.createElement('textarea');
|
524 |
+
textarea.value = textToCopy;
|
525 |
document.body.appendChild(textarea);
|
526 |
textarea.select();
|
527 |
document.execCommand('copy');
|
528 |
document.body.removeChild(textarea);
|
529 |
document.getElementById('clipboard_status').textContent = 'β
Copied to clipboard!';
|
530 |
+
setTimeout(() => {
|
531 |
document.getElementById('clipboard_status').textContent = '';
|
532 |
+
}, 2000);
|
533 |
+
});
|
534 |
+
} catch(err) {
|
535 |
console.error('Copy error:', err);
|
536 |
document.getElementById('clipboard_status').textContent = 'β Copy failed. Try again.';
|
537 |
+
setTimeout(() => {
|
538 |
document.getElementById('clipboard_status').textContent = '';
|
539 |
+
}, 2000);
|
540 |
+
}
|
541 |
</script>
|
542 |
<div id="clipboard_status" style="color: green; font-weight: bold;"></div>
|
543 |
+
'''
|
544 |
+
return gr.HTML(html_template % escaped_prompt), None
|
545 |
|
546 |
# Get the summary based on model selection
|
547 |
if model_selection == "HuggingFace Inference":
|