Tonic commited on
Commit
a82b00b
·
unverified ·
1 Parent(s): 04d38bc

attempt to generate discharge paper with auth

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -29,7 +29,7 @@ import csv # For CSV
29
  import io # For IO operations
30
  from PIL import Image # For image handling
31
  from utils.callbackmanager import extract_auth_code_from_url, extract_code_from_url
32
- from utils.generators import generate_pdf_from_meldrx, generate_ai_discharge_content, generate_pdf_from_meldrx_with_ai_content, extract_section, generate_pdf_from_form, generate_discharge_summary, generate_ai_discharge_content, analyze_dicom_file_with_ai, analyze_hl7_file_with_ai, analyze_cda_xml_file_with_ai, analyze_pdf_file_with_ai, analyze_csv_file_with_ai, generate_pdf_from_form , generate_ai_discharge_content , extract_section , generate_pdf_from_meldrx_with_ai_content
33
 
34
 
35
  # Initialize Inference Client - Ensure YOUR_HF_TOKEN is set in environment variables or replace with your actual token
@@ -340,16 +340,27 @@ with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
340
  first_name_input = gr.Textbox(label="First Name (Optional)", placeholder="Enter First Name")
341
  last_name_input = gr.Textbox(label="Last Name (Optional)", placeholder="Enter Last Name")
342
  one_click_ai_button = gr.Button("Generate Discharge Summary with AI (One-Click)", elem_classes="cyberpunk-button")
343
- one_click_ai_output = gr.File(label="Download AI-Generated Discharge PDF") # Changed to File output for PDF
344
- one_click_ai_status = gr.Textbox(label="Generation Status", lines=2, placeholder="Status will appear here...")
345
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  # Use the global CALLBACK_MANAGER instead of creating a new MeldRxAPI instance
347
  def one_click_handler(patient_id, first_name, last_name):
348
  try:
349
  # Check if CALLBACK_MANAGER is authenticated
350
  if not CALLBACK_MANAGER.access_token:
351
  return None, "Error: Not authenticated. Please authenticate in the 'Authenticate with MeldRx' tab first."
352
-
353
  # Call the one-click function with the existing authenticated CALLBACK_MANAGER.api
354
  pdf_path, status = generate_discharge_paper_one_click(
355
  CALLBACK_MANAGER.api, patient_id, first_name, last_name
@@ -359,11 +370,11 @@ with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
359
  logger.error(f"One-click handler error: {str(e)}")
360
  return None, f"Error: {str(e)}"
361
 
362
- one_click_ai_button.click(
363
- fn=one_click_handler,
364
- inputs=[patient_id_input, first_name_input, last_name_input],
365
- outputs=[one_click_ai_output, one_click_ai_status],
366
- )
367
 
368
 
369
  # Connect the patient data buttons
 
29
  import io # For IO operations
30
  from PIL import Image # For image handling
31
  from utils.callbackmanager import extract_auth_code_from_url, extract_code_from_url
32
+ from utils.generators import generate_pdf_from_meldrx, generate_ai_discharge_content, generate_pdf_from_meldrx_with_ai_content, extract_section, generate_pdf_from_form, generate_discharge_summary, generate_ai_discharge_content, analyze_dicom_file_with_ai, analyze_hl7_file_with_ai, analyze_cda_xml_file_with_ai, analyze_pdf_file_with_ai, analyze_csv_file_with_ai, generate_pdf_from_form , generate_ai_discharge_content , extract_section , generate_pdf_from_meldrx_with_ai_content
33
 
34
 
35
  # Initialize Inference Client - Ensure YOUR_HF_TOKEN is set in environment variables or replace with your actual token
 
340
  first_name_input = gr.Textbox(label="First Name (Optional)", placeholder="Enter First Name")
341
  last_name_input = gr.Textbox(label="Last Name (Optional)", placeholder="Enter Last Name")
342
  one_click_ai_button = gr.Button("Generate Discharge Summary with AI (One-Click)", elem_classes="cyberpunk-button")
343
+ one_click_ai_output = gr.Textbox(label="AI-Generated Discharge Summary", lines=20, placeholder="Discharge summary will appear here...")
 
344
 
345
+ # Initialize MeldRxAPI (ensure client_id, client_secret, workspace_id are set in environment variables)
346
+ client_id = os.getenv("APPID")
347
+ client_secret = os.getenv("CLIENT_SECRET")
348
+ workspace_id = os.getenv("WORKSPACE_URL")
349
+ redirect_uri = "https://multitransformer-discharge-guard.hf.space/callback"
350
+ meldrx_api = MeldRxAPI(client_id, client_secret, workspace_id, redirect_uri)
351
+
352
+ one_click_ai_button.click(
353
+ fn=lambda pid, fname, lname: generate_discharge_paper_one_click(meldrx_api, pid, fname, lname),
354
+ inputs=[patient_id_input, first_name_input, last_name_input],
355
+ outputs=one_click_ai_output,
356
+ )
357
  # Use the global CALLBACK_MANAGER instead of creating a new MeldRxAPI instance
358
  def one_click_handler(patient_id, first_name, last_name):
359
  try:
360
  # Check if CALLBACK_MANAGER is authenticated
361
  if not CALLBACK_MANAGER.access_token:
362
  return None, "Error: Not authenticated. Please authenticate in the 'Authenticate with MeldRx' tab first."
363
+
364
  # Call the one-click function with the existing authenticated CALLBACK_MANAGER.api
365
  pdf_path, status = generate_discharge_paper_one_click(
366
  CALLBACK_MANAGER.api, patient_id, first_name, last_name
 
370
  logger.error(f"One-click handler error: {str(e)}")
371
  return None, f"Error: {str(e)}"
372
 
373
+ # one_click_ai_button.click(
374
+ # fn=lambda pid, fname, lname: generate_discharge_paper_one_click(meldrx_api, pid, fname, lname),
375
+ # inputs=[patient_id_input, first_name_input, last_name_input],
376
+ # outputs=one_click_ai_output,
377
+ # )
378
 
379
 
380
  # Connect the patient data buttons