attempt to generate discharge paper with auth
Browse files
app.py
CHANGED
@@ -333,37 +333,37 @@ with gr.Blocks(theme=cyberpunk_theme) as demo: # Apply the theme here
|
|
333 |
analyze_csv_file_with_ai, inputs=csv_file, outputs=csv_ai_output
|
334 |
)
|
335 |
|
336 |
-
with gr.Tab("One-Click Discharge Paper (AI)", elem_classes="cyberpunk-tab"):
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
|
368 |
|
369 |
# Connect the patient data buttons
|
|
|
333 |
analyze_csv_file_with_ai, inputs=csv_file, outputs=csv_ai_output
|
334 |
)
|
335 |
|
336 |
+
with gr.Tab("One-Click Discharge Paper (AI)", elem_classes="cyberpunk-tab"):
|
337 |
+
gr.Markdown("<h2 style='color:#00FFFF; text-shadow: 0 0 3px #00FFFF;'>One-Click Medical Discharge Summary with AI Content</h2>")
|
338 |
+
with gr.Row():
|
339 |
+
patient_id_input = gr.Textbox(label="Patient ID (Optional)", placeholder="Enter Patient ID")
|
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
|
356 |
+
)
|
357 |
+
return pdf_path, status
|
358 |
+
except Exception as e:
|
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
|