Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -479,79 +479,66 @@ def send_to_model_impl(prompt, model_selection, hf_model_choice, hf_custom_model
|
|
479 |
# Escape the prompt for JavaScript
|
480 |
escaped_prompt = prompt.replace('"', '\\"').replace("'", "\\'").replace('\n', '\\n')
|
481 |
|
482 |
-
# Create temporary file for download
|
483 |
with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.txt') as f:
|
484 |
f.write(prompt)
|
485 |
download_file = f.name
|
486 |
-
|
487 |
-
#
|
488 |
-
html_template = '''
|
489 |
<div style="text-align: center; margin: 10px;">
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
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
|
551 |
-
|
552 |
-
# 2. Text message for summary output
|
553 |
-
# 3. Download file
|
554 |
-
return gr.HTML(html_template % escaped_prompt), "Text copied to clipboard. Use paste for processing.", download_file
|
555 |
|
556 |
# Get the summary based on model selection
|
557 |
if model_selection == "HuggingFace Inference":
|
|
|
479 |
# Escape the prompt for JavaScript
|
480 |
escaped_prompt = prompt.replace('"', '\\"').replace("'", "\\'").replace('\n', '\\n')
|
481 |
|
482 |
+
# Create a temporary file for download
|
483 |
with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.txt') as f:
|
484 |
f.write(prompt)
|
485 |
download_file = f.name
|
486 |
+
|
487 |
+
# Use f-string for HTML
|
488 |
+
html_template = f'''
|
489 |
<div style="text-align: center; margin: 10px;">
|
490 |
+
<button
|
491 |
+
onclick="
|
492 |
+
try {{
|
493 |
+
const textToCopy = `{escaped_prompt}`;
|
494 |
+
navigator.clipboard.writeText(textToCopy)
|
495 |
+
.then(() => {{
|
496 |
+
this.textContent = 'β
Copied to clipboard!';
|
497 |
+
setTimeout(() => {{
|
498 |
+
this.textContent = 'π Copy Text to Clipboard';
|
499 |
+
}}, 2000);
|
500 |
+
}})
|
501 |
+
.catch(err => {{
|
502 |
+
console.error('Copy failed:', err);
|
503 |
+
const textarea = document.createElement('textarea');
|
504 |
+
textarea.value = textToCopy;
|
505 |
+
document.body.appendChild(textarea);
|
506 |
+
textarea.select();
|
507 |
+
document.execCommand('copy');
|
508 |
+
document.body.removeChild(textarea);
|
509 |
+
this.textContent = 'β
Copied to clipboard!';
|
510 |
+
setTimeout(() => {{
|
511 |
+
this.textContent = 'π Copy Text to Clipboard';
|
512 |
+
}}, 2000);
|
513 |
+
}});
|
514 |
+
}} catch(err) {{
|
515 |
+
console.error('Copy error:', err);
|
516 |
+
this.textContent = 'β Copy failed. Try again.';
|
517 |
+
setTimeout(() => {{
|
518 |
+
this.textContent = 'π Copy Text to Clipboard';
|
519 |
+
}}, 2000);
|
520 |
+
}}
|
521 |
+
"
|
522 |
+
style="
|
523 |
+
padding: 10px 20px;
|
524 |
+
background-color: #2C3E50;
|
525 |
+
color: white;
|
526 |
+
border: none;
|
527 |
+
border-radius: 5px;
|
528 |
+
font-weight: bold;
|
529 |
+
cursor: pointer;
|
530 |
+
transition: background-color 0.3s ease;
|
531 |
+
"
|
532 |
+
onmouseover="this.style.backgroundColor='#34495E'"
|
533 |
+
onmouseout="this.style.backgroundColor='#2C3E50'"
|
534 |
+
>
|
535 |
+
π Copy Text to Clipboard
|
536 |
+
</button>
|
537 |
+
</div>
|
538 |
+
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
539 |
|
540 |
+
# Return all three values
|
541 |
+
return gr.HTML(html_template), "Text copied to clipboard.", download_file
|
|
|
|
|
|
|
542 |
|
543 |
# Get the summary based on model selection
|
544 |
if model_selection == "HuggingFace Inference":
|