Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -502,7 +502,44 @@ 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 |
# Get the summary based on model selection
|
| 508 |
if model_selection == "HuggingFace Inference":
|
|
@@ -1013,87 +1050,49 @@ with gr.Blocks(css="""
|
|
| 1013 |
<div style="text-align: center; margin: 10px;">
|
| 1014 |
<button
|
| 1015 |
onclick="
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1020 |
navigator.clipboard.writeText(promptArea.value)
|
| 1021 |
.then(() => {
|
| 1022 |
-
this.
|
| 1023 |
setTimeout(() => {
|
| 1024 |
-
|
| 1025 |
-
const link = document.createElement('a');
|
| 1026 |
-
link.href = chatGPTUrl;
|
| 1027 |
-
link.target = '_blank';
|
| 1028 |
-
link.rel = 'noopener noreferrer';
|
| 1029 |
-
link.click();
|
| 1030 |
-
|
| 1031 |
-
// Reset button text after a delay
|
| 1032 |
setTimeout(() => {
|
| 1033 |
-
this.
|
| 1034 |
}, 2000);
|
| 1035 |
}, 500);
|
| 1036 |
})
|
| 1037 |
.catch(err => {
|
| 1038 |
-
console.error('
|
| 1039 |
-
// Fallback
|
| 1040 |
promptArea.select();
|
| 1041 |
-
|
| 1042 |
-
|
| 1043 |
-
|
| 1044 |
-
|
| 1045 |
-
const chatGPTUrl = 'https://chat.openai.com/';
|
| 1046 |
-
const link = document.createElement('a');
|
| 1047 |
-
link.href = chatGPTUrl;
|
| 1048 |
-
link.target = '_blank';
|
| 1049 |
-
link.rel = 'noopener noreferrer';
|
| 1050 |
-
link.click();
|
| 1051 |
-
|
| 1052 |
-
// Reset button text after a delay
|
| 1053 |
-
setTimeout(() => {
|
| 1054 |
-
this.innerHTML = 'π Copy Prompt & Open ChatGPT';
|
| 1055 |
-
}, 2000);
|
| 1056 |
-
}, 500);
|
| 1057 |
-
} catch (err) {
|
| 1058 |
-
console.error('Fallback copy failed:', err);
|
| 1059 |
-
this.innerHTML = 'β Copy failed. Please try again.';
|
| 1060 |
setTimeout(() => {
|
| 1061 |
-
this.
|
| 1062 |
}, 2000);
|
| 1063 |
-
}
|
| 1064 |
});
|
| 1065 |
} else {
|
| 1066 |
-
|
| 1067 |
-
|
| 1068 |
-
|
| 1069 |
-
|
| 1070 |
-
this.innerHTML = 'β
Copied! Opening ChatGPT...';
|
| 1071 |
-
setTimeout(() => {
|
| 1072 |
-
const chatGPTUrl = 'https://chat.openai.com/';
|
| 1073 |
-
const link = document.createElement('a');
|
| 1074 |
-
link.href = chatGPTUrl;
|
| 1075 |
-
link.target = '_blank';
|
| 1076 |
-
link.rel = 'noopener noreferrer';
|
| 1077 |
-
link.click();
|
| 1078 |
-
|
| 1079 |
-
// Reset button text after a delay
|
| 1080 |
-
setTimeout(() => {
|
| 1081 |
-
this.innerHTML = 'π Copy Prompt & Open ChatGPT';
|
| 1082 |
-
}, 2000);
|
| 1083 |
-
}, 500);
|
| 1084 |
-
} catch (err) {
|
| 1085 |
-
console.error('Legacy copy failed:', err);
|
| 1086 |
-
this.innerHTML = 'β Copy failed. Please try again.';
|
| 1087 |
-
setTimeout(() => {
|
| 1088 |
-
this.innerHTML = 'π Copy Prompt & Open ChatGPT';
|
| 1089 |
-
}, 2000);
|
| 1090 |
-
}
|
| 1091 |
}
|
| 1092 |
-
}
|
| 1093 |
-
console.error('
|
| 1094 |
-
this.
|
| 1095 |
setTimeout(() => {
|
| 1096 |
-
this.
|
| 1097 |
}, 2000);
|
| 1098 |
}
|
| 1099 |
"
|
|
@@ -1115,7 +1114,8 @@ with gr.Blocks(css="""
|
|
| 1115 |
</div>
|
| 1116 |
"""
|
| 1117 |
)
|
| 1118 |
-
|
|
|
|
| 1119 |
with gr.Column(scale=1):
|
| 1120 |
summary_output = gr.Textbox(
|
| 1121 |
label="π Summary",
|
|
@@ -1127,6 +1127,9 @@ with gr.Blocks(css="""
|
|
| 1127 |
|
| 1128 |
with gr.Row():
|
| 1129 |
download_summary = gr.File(label="π₯ Download Summary")
|
|
|
|
|
|
|
|
|
|
| 1130 |
|
| 1131 |
# Hidden components for file handling
|
| 1132 |
download_files = gr.Files(label="π₯ Downloads", visible=False)
|
|
@@ -1412,26 +1415,29 @@ with gr.Blocks(css="""
|
|
| 1412 |
return []
|
| 1413 |
|
| 1414 |
# Model processing
|
| 1415 |
-
# Model processing button
|
| 1416 |
send_to_model_btn.click(
|
| 1417 |
fn=send_to_model,
|
| 1418 |
inputs=[
|
| 1419 |
-
generated_prompt,
|
| 1420 |
-
model_choice,
|
| 1421 |
-
hf_model,
|
| 1422 |
-
hf_custom_model,
|
| 1423 |
-
hf_api_key,
|
| 1424 |
-
groq_model,
|
| 1425 |
-
groq_api_key,
|
| 1426 |
-
openai_api_key,
|
| 1427 |
-
openai_model,
|
| 1428 |
-
cohere_api_key,
|
| 1429 |
-
cohere_model,
|
| 1430 |
-
glhf_api_key,
|
| 1431 |
-
glhf_model,
|
| 1432 |
-
glhf_custom_model
|
| 1433 |
],
|
| 1434 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1435 |
)
|
| 1436 |
|
| 1437 |
groq_refresh_btn.click(
|
|
|
|
| 502 |
|
| 503 |
try:
|
| 504 |
if model_selection == "Clipboard only":
|
| 505 |
+
|
| 506 |
+
# Return special message that will trigger clipboard copy in JavaScript
|
| 507 |
+
return gr.HTML(
|
| 508 |
+
f"""
|
| 509 |
+
<script>
|
| 510 |
+
try {{
|
| 511 |
+
navigator.clipboard.writeText(`{prompt.replace('`', '\\`')}`)
|
| 512 |
+
.then(() => {{
|
| 513 |
+
document.getElementById('clipboard_status').textContent = 'β
Copied to clipboard!';
|
| 514 |
+
setTimeout(() => {{
|
| 515 |
+
document.getElementById('clipboard_status').textContent = '';
|
| 516 |
+
}}, 2000);
|
| 517 |
+
}})
|
| 518 |
+
.catch(err => {{
|
| 519 |
+
console.error('Copy failed:', err);
|
| 520 |
+
// Fallback
|
| 521 |
+
const textarea = document.createElement('textarea');
|
| 522 |
+
textarea.value = `{prompt.replace('`', '\\`')}`;
|
| 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 |
+
}}, 2000);
|
| 531 |
+
}});
|
| 532 |
+
}} catch(err) {{
|
| 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 |
+
}}, 2000);
|
| 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":
|
|
|
|
| 1050 |
<div style="text-align: center; margin: 10px;">
|
| 1051 |
<button
|
| 1052 |
onclick="
|
| 1053 |
+
try {
|
| 1054 |
+
// Try all possible selectors for the prompt textarea
|
| 1055 |
+
const promptArea =
|
| 1056 |
+
document.querySelector('#generated_prompt textarea') ||
|
| 1057 |
+
document.querySelector('textarea#generated_prompt') ||
|
| 1058 |
+
document.querySelector('.generated_prompt textarea') ||
|
| 1059 |
+
Array.from(document.querySelectorAll('textarea')).find(el => el.value.includes('Summarize'));
|
| 1060 |
+
|
| 1061 |
+
if (promptArea && promptArea.value) {
|
| 1062 |
navigator.clipboard.writeText(promptArea.value)
|
| 1063 |
.then(() => {
|
| 1064 |
+
this.textContent = 'β
Copied! Opening ChatGPT...';
|
| 1065 |
setTimeout(() => {
|
| 1066 |
+
window.open('https://chat.openai.com/', '_blank');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1067 |
setTimeout(() => {
|
| 1068 |
+
this.textContent = 'π Copy Prompt & Open ChatGPT';
|
| 1069 |
}, 2000);
|
| 1070 |
}, 500);
|
| 1071 |
})
|
| 1072 |
.catch(err => {
|
| 1073 |
+
console.error('Modern copy failed:', err);
|
| 1074 |
+
// Fallback method
|
| 1075 |
promptArea.select();
|
| 1076 |
+
document.execCommand('copy');
|
| 1077 |
+
this.textContent = 'β
Copied! Opening ChatGPT...';
|
| 1078 |
+
setTimeout(() => {
|
| 1079 |
+
window.open('https://chat.openai.com/', '_blank');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1080 |
setTimeout(() => {
|
| 1081 |
+
this.textContent = 'π Copy Prompt & Open ChatGPT';
|
| 1082 |
}, 2000);
|
| 1083 |
+
}, 500);
|
| 1084 |
});
|
| 1085 |
} else {
|
| 1086 |
+
this.textContent = 'β No prompt found. Generate one first.';
|
| 1087 |
+
setTimeout(() => {
|
| 1088 |
+
this.textContent = 'π Copy Prompt & Open ChatGPT';
|
| 1089 |
+
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1090 |
}
|
| 1091 |
+
} catch (err) {
|
| 1092 |
+
console.error('Copy error:', err);
|
| 1093 |
+
this.textContent = 'β Copy failed. Try again.';
|
| 1094 |
setTimeout(() => {
|
| 1095 |
+
this.textContent = 'π Copy Prompt & Open ChatGPT';
|
| 1096 |
}, 2000);
|
| 1097 |
}
|
| 1098 |
"
|
|
|
|
| 1114 |
</div>
|
| 1115 |
"""
|
| 1116 |
)
|
| 1117 |
+
|
| 1118 |
+
|
| 1119 |
with gr.Column(scale=1):
|
| 1120 |
summary_output = gr.Textbox(
|
| 1121 |
label="π Summary",
|
|
|
|
| 1127 |
|
| 1128 |
with gr.Row():
|
| 1129 |
download_summary = gr.File(label="π₯ Download Summary")
|
| 1130 |
+
|
| 1131 |
+
with gr.Row():
|
| 1132 |
+
clipboard_status = gr.HTML(elem_id="clipboard_status")
|
| 1133 |
|
| 1134 |
# Hidden components for file handling
|
| 1135 |
download_files = gr.Files(label="π₯ Downloads", visible=False)
|
|
|
|
| 1415 |
return []
|
| 1416 |
|
| 1417 |
# Model processing
|
|
|
|
| 1418 |
send_to_model_btn.click(
|
| 1419 |
fn=send_to_model,
|
| 1420 |
inputs=[
|
| 1421 |
+
generated_prompt,
|
| 1422 |
+
model_choice,
|
| 1423 |
+
hf_model,
|
| 1424 |
+
hf_custom_model,
|
| 1425 |
+
hf_api_key,
|
| 1426 |
+
groq_model,
|
| 1427 |
+
groq_api_key,
|
| 1428 |
+
openai_api_key,
|
| 1429 |
+
openai_model,
|
| 1430 |
+
cohere_api_key,
|
| 1431 |
+
cohere_model,
|
| 1432 |
+
glhf_api_key,
|
| 1433 |
+
glhf_model,
|
| 1434 |
+
glhf_custom_model
|
| 1435 |
],
|
| 1436 |
+
outputs=[
|
| 1437 |
+
clipboard_status, # status display for clipboard operations
|
| 1438 |
+
summary_output,
|
| 1439 |
+
download_summary
|
| 1440 |
+
]
|
| 1441 |
)
|
| 1442 |
|
| 1443 |
groq_refresh_btn.click(
|