Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
import tempfile
|
| 3 |
import hashlib
|
|
@@ -362,7 +363,20 @@ def modify_criteria(suggestions):
|
|
| 362 |
gr.update(visible=False)
|
| 363 |
)
|
| 364 |
|
| 365 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
"""Cancel the current analysis."""
|
| 367 |
global _CURRENT_ENGINE, _CURRENT_CRITERIA, _ANALYSIS_STATE
|
| 368 |
|
|
@@ -408,7 +422,24 @@ with gr.Blocks(theme=simple_theme, title="ChartWise AI") as interface:
|
|
| 408 |
height=400
|
| 409 |
)
|
| 410 |
|
| 411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
with gr.Column():
|
| 413 |
gr.HTML("<h3 style='color:#1e40af;'>🎯 Interactive HEDIS Analysis</h3>")
|
| 414 |
hedis_measure = gr.Textbox(
|
|
@@ -451,12 +482,27 @@ with gr.Blocks(theme=simple_theme, title="ChartWise AI") as interface:
|
|
| 451 |
outputs=[summary_output]
|
| 452 |
)
|
| 453 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
start_hedis_btn.click(
|
| 455 |
fn=start_hedis_analysis,
|
| 456 |
inputs=[pdf_upload, hedis_measure, measurement_year],
|
| 457 |
outputs=[hedis_output, suggestions_input, approve_btn, modify_btn, cancel_btn]
|
| 458 |
)
|
| 459 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
approve_btn.click(
|
| 461 |
fn=approve_criteria,
|
| 462 |
inputs=[],
|
|
|
|
| 1 |
+
# app.py - Interactive Version with HEDIS Feedback
|
| 2 |
import os
|
| 3 |
import tempfile
|
| 4 |
import hashlib
|
|
|
|
| 363 |
gr.update(visible=False)
|
| 364 |
)
|
| 365 |
|
| 366 |
+
def toggle_analysis_mode(mode):
|
| 367 |
+
"""Toggle between interactive and standard analysis modes."""
|
| 368 |
+
if mode == "Interactive (with criteria review)":
|
| 369 |
+
return (
|
| 370 |
+
gr.update(visible=True), # start_hedis_btn
|
| 371 |
+
gr.update(visible=False), # run_standard_btn
|
| 372 |
+
"Select analysis mode and enter measure details, then click 'Start Interactive Analysis' to begin criteria review."
|
| 373 |
+
)
|
| 374 |
+
else:
|
| 375 |
+
return (
|
| 376 |
+
gr.update(visible=False), # start_hedis_btn
|
| 377 |
+
gr.update(visible=True), # run_standard_btn
|
| 378 |
+
"Select analysis mode and enter measure details, then click 'Run Standard Analysis' for direct analysis."
|
| 379 |
+
)
|
| 380 |
"""Cancel the current analysis."""
|
| 381 |
global _CURRENT_ENGINE, _CURRENT_CRITERIA, _ANALYSIS_STATE
|
| 382 |
|
|
|
|
| 422 |
height=400
|
| 423 |
)
|
| 424 |
|
| 425 |
+
def generate_hedis_analysis_original(pdf_file, measure_name, measurement_year):
|
| 426 |
+
"""Original HEDIS analysis without interactive feedback."""
|
| 427 |
+
try:
|
| 428 |
+
if pdf_file is None:
|
| 429 |
+
return "⚠️ Please upload a PDF file first."
|
| 430 |
+
if not measure_name:
|
| 431 |
+
return "⚠️ Please enter a HEDIS measure code (e.g., COL, BCS, CCS)."
|
| 432 |
+
if not measurement_year:
|
| 433 |
+
return "⚠️ Please enter a measurement year."
|
| 434 |
+
|
| 435 |
+
# Reuse embeddings if already built for this file
|
| 436 |
+
vectordb = _get_vectordb_from_bytes(pdf_file)
|
| 437 |
+
|
| 438 |
+
hedis = HedisComplianceEngine(vectordb, measure_name, int(measurement_year))
|
| 439 |
+
result = hedis.run() # Use original non-interactive run method
|
| 440 |
+
return result
|
| 441 |
+
except Exception as e:
|
| 442 |
+
return f"❌ Error processing HEDIS analysis: {e}"
|
| 443 |
with gr.Column():
|
| 444 |
gr.HTML("<h3 style='color:#1e40af;'>🎯 Interactive HEDIS Analysis</h3>")
|
| 445 |
hedis_measure = gr.Textbox(
|
|
|
|
| 482 |
outputs=[summary_output]
|
| 483 |
)
|
| 484 |
|
| 485 |
+
# Mode toggle
|
| 486 |
+
analysis_mode.change(
|
| 487 |
+
fn=toggle_analysis_mode,
|
| 488 |
+
inputs=[analysis_mode],
|
| 489 |
+
outputs=[start_hedis_btn, run_standard_btn, hedis_output]
|
| 490 |
+
)
|
| 491 |
+
|
| 492 |
+
# Interactive analysis
|
| 493 |
start_hedis_btn.click(
|
| 494 |
fn=start_hedis_analysis,
|
| 495 |
inputs=[pdf_upload, hedis_measure, measurement_year],
|
| 496 |
outputs=[hedis_output, suggestions_input, approve_btn, modify_btn, cancel_btn]
|
| 497 |
)
|
| 498 |
|
| 499 |
+
# Standard analysis
|
| 500 |
+
run_standard_btn.click(
|
| 501 |
+
fn=generate_hedis_analysis_original,
|
| 502 |
+
inputs=[pdf_upload, hedis_measure, measurement_year],
|
| 503 |
+
outputs=[hedis_output]
|
| 504 |
+
)
|
| 505 |
+
|
| 506 |
approve_btn.click(
|
| 507 |
fn=approve_criteria,
|
| 508 |
inputs=[],
|