alxd commited on
Commit
bb9ca74
Β·
1 Parent(s): 0e17596

add text box with the response of HTML converted to TEXT

Browse files
Files changed (1) hide show
  1. scoutLLM.py +35 -32
scoutLLM.py CHANGED
@@ -320,19 +320,27 @@ def run_query(max_value):
320
 
321
  # Function to call both refresh_job_list and check_job_status using the last job ID
322
  def periodic_update(is_checked):
323
- interval = 2 if is_checked else None
324
  debug_print(f"Auto-refresh checkbox is {'checked' if is_checked else 'unchecked'}, every={interval}")
325
  if is_checked:
326
  global last_job_id
327
  job_list_md = refresh_job_list()
328
  job_status = check_job_status(last_job_id) if last_job_id else ("No job ID available", "", "", "", "")
329
 
330
- # Return all expected outputs
331
- return job_list_md, job_status[0], job_status[1], job_status[2], job_status[3], job_status[4]
 
 
 
 
 
 
 
 
332
  else:
333
  # Return empty values to stop updates - make sure to match the number of expected outputs
334
- return "", "", "", "", "", ""
335
-
336
  # OAuth 2.0 Scopes
337
  SCOPES = ["https://www.googleapis.com/auth/gmail.send"]
338
 
@@ -515,10 +523,17 @@ with gr.Blocks() as app:
515
  )
516
  submit_button = gr.Button("Submit Query ")
517
  # Use a Checkbox to control the periodic updates
518
-
 
 
 
519
  response_output = gr.Textbox(label="Response", interactive=False)
520
  token_info = gr.Textbox(label="Token Info", interactive=False)
521
-
 
 
 
 
522
  # Add buttons for copying and sending email
523
  # with gr.Row():
524
  # copy_plain_button = gr.Button("πŸ“‹ Copy Plain Text")
@@ -533,6 +548,7 @@ with gr.Blocks() as app:
533
  with gr.Column(scale=1):
534
  # Change Job Status output to an HTML component for proper formatting
535
  status_output = gr.HTML(label="Job Status", interactive=False)
 
536
  job_id_display = gr.Textbox(label="Job ID", interactive=False)
537
  input_tokens_display = gr.Textbox(label="Input Tokens", interactive=False)
538
  output_tokens_display = gr.Textbox(label="Output Tokens", interactive=False)
@@ -596,10 +612,20 @@ with gr.Blocks() as app:
596
  auto_refresh_checkbox.change(
597
  fn=periodic_update,
598
  inputs=[auto_refresh_checkbox],
599
- outputs=[job_list_display, status_output, job_id_display, input_tokens_display, output_tokens_display, job_query_display],
600
- every=2
601
  )
602
 
 
 
 
 
 
 
 
 
 
 
603
  # Copy and email buttons
604
  # copy_plain_button.click(fn=copy_plain_text, inputs=[status_output], outputs=[email_status])
605
  # copy_formatted_button.click(fn=copy_to_clipboard, inputs=[status_output], outputs=[email_status])
@@ -609,26 +635,3 @@ with gr.Blocks() as app:
609
  if __name__ == "__main__":
610
  debug_print("Launching Gradio UI...")
611
  app.queue().launch(share=False)
612
-
613
-
614
- @app.route("/oauth2callback")
615
- def oauth2callback(request):
616
- global oauth_flow
617
-
618
- # Get the authorization code from the request
619
- code = request.query_params.get("code")
620
- if not code:
621
- return "Authorization code missing"
622
-
623
- try:
624
- # Exchange the authorization code for credentials
625
- oauth_flow.fetch_token(code=code)
626
- creds = oauth_flow.credentials
627
-
628
- # Save the credentials
629
- with open(token_path, "w") as token_file:
630
- token_file.write(creds.to_json())
631
-
632
- return "Authentication successful! You can close this window and return to the application."
633
- except Exception as e:
634
- return f"Error during authentication: {str(e)}"
 
320
 
321
  # Function to call both refresh_job_list and check_job_status using the last job ID
322
  def periodic_update(is_checked):
323
+ interval = 3 if is_checked else None
324
  debug_print(f"Auto-refresh checkbox is {'checked' if is_checked else 'unchecked'}, every={interval}")
325
  if is_checked:
326
  global last_job_id
327
  job_list_md = refresh_job_list()
328
  job_status = check_job_status(last_job_id) if last_job_id else ("No job ID available", "", "", "", "")
329
 
330
+ # Extract plain text from HTML for status_text
331
+ from bs4 import BeautifulSoup
332
+ html_content = job_status[0]
333
+ plain_text = ""
334
+ if html_content:
335
+ soup = BeautifulSoup(html_content, "html.parser")
336
+ plain_text = soup.get_text()
337
+
338
+ # Return all expected outputs, including status_text
339
+ return job_list_md, job_status[0], plain_text, job_status[1], job_status[2], job_status[3], job_status[4]
340
  else:
341
  # Return empty values to stop updates - make sure to match the number of expected outputs
342
+ return "", "", "", "", "", "", ""
343
+
344
  # OAuth 2.0 Scopes
345
  SCOPES = ["https://www.googleapis.com/auth/gmail.send"]
346
 
 
523
  )
524
  submit_button = gr.Button("Submit Query ")
525
  # Use a Checkbox to control the periodic updates
526
+
527
+ # Add a textarea to store the plain text version for copying
528
+ status_text = gr.Textbox(label="Response Text ", visible=True)
529
+
530
  response_output = gr.Textbox(label="Response", interactive=False)
531
  token_info = gr.Textbox(label="Token Info", interactive=False)
532
+ # Add buttons for copying and sending email
533
+ # with gr.Row():
534
+ # copy_btn = gr.Button("πŸ“‹ Copy Text")
535
+
536
+
537
  # Add buttons for copying and sending email
538
  # with gr.Row():
539
  # copy_plain_button = gr.Button("πŸ“‹ Copy Plain Text")
 
548
  with gr.Column(scale=1):
549
  # Change Job Status output to an HTML component for proper formatting
550
  status_output = gr.HTML(label="Job Status", interactive=False)
551
+
552
  job_id_display = gr.Textbox(label="Job ID", interactive=False)
553
  input_tokens_display = gr.Textbox(label="Input Tokens", interactive=False)
554
  output_tokens_display = gr.Textbox(label="Output Tokens", interactive=False)
 
612
  auto_refresh_checkbox.change(
613
  fn=periodic_update,
614
  inputs=[auto_refresh_checkbox],
615
+ outputs=[job_list_display, status_output, status_text, job_id_display, input_tokens_display, output_tokens_display, job_query_display],
616
+ every=3
617
  )
618
 
619
+
620
+ # Connect the copy button to show the text in the textbox and make it visible temporarily
621
+ def show_copy_text(text):
622
+ # Simply return the text value and make the component visible
623
+ return gr.update(value=text, visible=True)
624
+
625
+ # Set up the event handlers
626
+ # copy_btn.click(fn=show_copy_text, inputs=status_text, outputs=status_text)
627
+
628
+
629
  # Copy and email buttons
630
  # copy_plain_button.click(fn=copy_plain_text, inputs=[status_output], outputs=[email_status])
631
  # copy_formatted_button.click(fn=copy_to_clipboard, inputs=[status_output], outputs=[email_status])
 
635
  if __name__ == "__main__":
636
  debug_print("Launching Gradio UI...")
637
  app.queue().launch(share=False)