cstr commited on
Commit
72b2920
Β·
verified Β·
1 Parent(s): a04534b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -84
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
- return "Text copied to clipboard. Use paste for processing.", None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- const promptArea = document.querySelector('textarea[data-testid=\'generated_prompt\']');
1017
- if (promptArea) {
1018
- // Try modern clipboard API first
1019
- if (navigator.clipboard && navigator.clipboard.writeText) {
 
 
 
 
 
1020
  navigator.clipboard.writeText(promptArea.value)
1021
  .then(() => {
1022
- this.innerHTML = 'βœ… Copied! Opening ChatGPT...';
1023
  setTimeout(() => {
1024
- const chatGPTUrl = 'https://chat.openai.com/';
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.innerHTML = 'πŸ“‹ Copy Prompt & Open ChatGPT';
1034
  }, 2000);
1035
  }, 500);
1036
  })
1037
  .catch(err => {
1038
- console.error('Copy failed:', err);
1039
- // Fallback to older method
1040
  promptArea.select();
1041
- try {
1042
- document.execCommand('copy');
1043
- this.innerHTML = 'βœ… Copied! Opening ChatGPT...';
1044
- setTimeout(() => {
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.innerHTML = 'πŸ“‹ Copy Prompt & Open ChatGPT';
1062
  }, 2000);
1063
- }
1064
  });
1065
  } else {
1066
- // Use older method directly if Clipboard API not available
1067
- promptArea.select();
1068
- try {
1069
- document.execCommand('copy');
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
- } else {
1093
- console.error('Prompt textarea not found');
1094
- this.innerHTML = '❌ Prompt not found. Generate a prompt first.';
1095
  setTimeout(() => {
1096
- this.innerHTML = 'πŸ“‹ Copy Prompt & Open ChatGPT';
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, # prompt
1420
- model_choice, # model_selection
1421
- hf_model, # hf_model_choice
1422
- hf_custom_model, # hf_custom_model
1423
- hf_api_key, # hf_api_key
1424
- groq_model, # groq_model_choice
1425
- groq_api_key, # groq_api_key
1426
- openai_api_key, # openai_api_key
1427
- openai_model, # openai_model_choice
1428
- cohere_api_key, # cohere_api_key
1429
- cohere_model, # cohere_model
1430
- glhf_api_key, # glhf_api_key
1431
- glhf_model, # glhf_model
1432
- glhf_custom_model # glhf_custom_model
1433
  ],
1434
- outputs=[summary_output, download_summary]
 
 
 
 
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(