sujataprakashdatycs commited on
Commit
ab7a1c2
Β·
verified Β·
1 Parent(s): de338d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +321 -73
app.py CHANGED
@@ -8,15 +8,14 @@ from HCCDiagnosisListEngine import HCCDiagnosisListEngine
8
  from chartdiagnosischecker import ChartDiagnosisChecker
9
  from MeatValidatorAgent import MEATValidatorAgent
10
  from dotenv import load_dotenv
11
-
12
 
13
  APP_TITLE = "Risk Adjustment (HCC Chart Validation)"
14
  CSV_PATH = "hcc_mapping.csv"
15
- SAMPLE_PDF = "sample_patient_chart.pdf"
16
-
17
 
18
 
19
- # ---------- Helper: JSON β†’ Markdown (Unchanged) ----------
20
  def json_to_markdown(meat_results) -> str:
21
  if not meat_results:
22
  return "<div style='color:orange; font-weight:bold;'>⚠️ No results found.</div>"
@@ -42,23 +41,35 @@ def json_to_markdown(meat_results) -> str:
42
  return md
43
 
44
 
45
- # ---------- Pipeline (Unchanged Core Logic) ----------
46
  def process_pipeline(pdf_file, hcc_code, model_version, csv_path=CSV_PATH):
47
  try:
 
 
 
 
 
 
 
 
48
  pdf_path = pdf_file.name
49
  patient_name = os.path.splitext(os.path.basename(pdf_path))[0]
50
  print(f"\n[PROCESSING] {patient_name}")
51
 
52
- diag_engine = HCCDiagnosisListEngine(hcc_code, model_version, csv_path)
 
53
  diagnoses = diag_engine.run()
54
 
 
55
  checker = ChartDiagnosisChecker(pdf_path)
56
  checked = checker.run(diagnoses)
57
 
 
58
  has_positive = any(entry.get("answer", "").lower() == "yes" for entry in checked)
59
  if not has_positive:
60
- return f"<div style='border:2px solid #f59e0b; border-radius:12px; padding:15px; background-color:#fffbeb;'><h3 style='color:#d97706;'>⚠️ No Matching Diagnosis Found</h3><p>No diagnosis in the chart was found to be directly related to <b>HCC code {hcc_code}</b>.</p></div>"
61
 
 
62
  meat_validator = MEATValidatorAgent()
63
  meat_results = meat_validator.run(checked)
64
 
@@ -68,43 +79,8 @@ def process_pipeline(pdf_file, hcc_code, model_version, csv_path=CSV_PATH):
68
  print(f"[ERROR] {e}")
69
  return f"<div style='color:red; font-weight:bold;'>⚠️ Error during processing: {e}</div>"
70
 
71
- # ---------- NEW: Gradio UI Event Handler to run the pipeline and switch views ----------
72
- def run_and_display_pdf(pdf_file, hcc_code, model_version):
73
- # 1. Validate inputs first
74
- if pdf_file is None:
75
- return {
76
- output_md: "<div style='color:orange; font-weight:bold;'>⚠️ Please upload a patient chart PDF.</div>"
77
- }
78
- hcc_code_str = str(hcc_code or "").strip()
79
- if not hcc_code_str:
80
- return {
81
- output_md: "<div style='color:orange; font-weight:bold;'>⚠️ Please enter a valid HCC Code before running validation.</div>"
82
- }
83
-
84
- # 2. Run the main processing pipeline
85
- report_markdown = process_pipeline(pdf_file, hcc_code_str, model_version)
86
-
87
- # 3. Return a dictionary of updates for each component on the screen
88
- return {
89
- output_md: report_markdown,
90
- pdf_viewer: gr.update(value=pdf_file.name, visible=True),
91
- input_controls: gr.update(visible=False),
92
- reset_btn: gr.update(visible=True)
93
- }
94
-
95
- # ---------- NEW: Function to reset the UI to its initial state ----------
96
- def reset_ui():
97
- initial_md = "<div style='border:2px solid #1e40af; border-radius:12px; padding:15px; background-color:#f0f9ff;'>πŸ“„ Upload a PDF and click <b>Run Validation</b> to start.</div>"
98
- return {
99
- pdf_upload: gr.update(value=None),
100
- hcc_code: gr.update(value=""),
101
- output_md: initial_md,
102
- pdf_viewer: gr.update(visible=False, value=None),
103
- input_controls: gr.update(visible=True),
104
- reset_btn: gr.update(visible=False)
105
- }
106
-
107
- # ---------- Gradio Theme (Unchanged) ----------
108
  simple_theme = gr.themes.Soft(
109
  primary_hue=gr.themes.colors.blue,
110
  secondary_hue=gr.themes.colors.slate,
@@ -117,7 +93,19 @@ simple_theme = gr.themes.Soft(
117
  background_fill_secondary="#f8fafc",
118
  )
119
 
120
- # ---------- MODIFIED Gradio UI ----------
 
 
 
 
 
 
 
 
 
 
 
 
121
  with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
122
  gr.HTML(f"""
123
  <h1 style='text-align:center;color:#1e40af;'> 🏩 {APP_TITLE}</h1>
@@ -126,46 +114,306 @@ with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
126
  </p>
127
  """)
128
 
129
- with gr.Row(equal_height=False):
130
- # --- Left Column: Contains both the inputs and the PDF viewer ---
131
  with gr.Column(scale=1):
132
- # Group all input controls to easily hide/show them together
133
- with gr.Column(visible=True) as input_controls:
134
- pdf_upload = gr.File(label="Upload Patient Chart (PDF)", file_types=[".pdf"])
135
- hcc_code = gr.Textbox(label="HCC Code (e.g., 12)", placeholder="Enter HCC code")
136
- model_version = gr.Dropdown(choices=["V24", "V28"], label="Model Version", value="V24")
137
- run_btn = gr.Button("πŸš€ Run Validation", variant="primary")
138
- gr.Examples(
139
- examples=[[SAMPLE_PDF, "12", "V24"]],
140
- inputs=[pdf_upload, hcc_code, model_version],
141
- )
142
-
143
- # PDF viewer, initially hidden
144
- pdf_viewer = gr.File(label="Patient Chart Viewer", visible=False, height=800)
145
-
146
- # Reset button, also initially hidden
147
- reset_btn = gr.Button("πŸ”„ Analyze New Chart", visible=False)
148
-
149
- # --- Right Column: For the report output ---
150
  with gr.Column(scale=2):
151
  output_md = gr.Markdown(
152
  label="Validation Report",
153
  value="<div style='border:2px solid #1e40af; border-radius:12px; padding:15px; background-color:#f0f9ff;'>πŸ“„ Upload a PDF and click <b>Run Validation</b> to start.</div>",
154
  )
155
 
156
- # ---------- Connect the button clicks to the new handler functions ----------
157
  run_btn.click(
158
- fn=run_and_display_pdf,
159
  inputs=[pdf_upload, hcc_code, model_version],
160
- outputs=[output_md, pdf_viewer, input_controls, reset_btn],
161
  )
162
 
163
- reset_btn.click(
164
- fn=reset_ui,
165
- inputs=None,
166
- # The outputs list must include all components that the reset_ui function updates
167
- outputs=[pdf_upload, hcc_code, output_md, pdf_viewer, input_controls, reset_btn]
 
 
168
  )
169
 
 
170
  if __name__ == "__main__":
171
  interface.queue().launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  from chartdiagnosischecker import ChartDiagnosisChecker
9
  from MeatValidatorAgent import MEATValidatorAgent
10
  from dotenv import load_dotenv
11
+ load_dotenv()
12
 
13
  APP_TITLE = "Risk Adjustment (HCC Chart Validation)"
14
  CSV_PATH = "hcc_mapping.csv"
15
+ SAMPLE_PDF = "sample_patient_chart.pdf" # Place a sample PDF in the same folder
 
16
 
17
 
18
+ # ---------- Helper: JSON β†’ Markdown ----------
19
  def json_to_markdown(meat_results) -> str:
20
  if not meat_results:
21
  return "<div style='color:orange; font-weight:bold;'>⚠️ No results found.</div>"
 
41
  return md
42
 
43
 
44
+ # ---------- Pipeline ----------
45
  def process_pipeline(pdf_file, hcc_code, model_version, csv_path=CSV_PATH):
46
  try:
47
+ if pdf_file is None:
48
+ return "<div style='color:orange; font-weight:bold;'>⚠️ Please upload a patient chart PDF.</div>"
49
+
50
+ # Safely handle None hcc_code
51
+ hcc_code_str = str(hcc_code or "").strip()
52
+ if not hcc_code_str:
53
+ return "<div style='color:orange; font-weight:bold;'>⚠️ Please enter a valid HCC Code before running validation.</div>"
54
+
55
  pdf_path = pdf_file.name
56
  patient_name = os.path.splitext(os.path.basename(pdf_path))[0]
57
  print(f"\n[PROCESSING] {patient_name}")
58
 
59
+ # Step 1: HCC Diagnoses
60
+ diag_engine = HCCDiagnosisListEngine(hcc_code_str, model_version, csv_path)
61
  diagnoses = diag_engine.run()
62
 
63
+ # Step 2: Chart Checking
64
  checker = ChartDiagnosisChecker(pdf_path)
65
  checked = checker.run(diagnoses)
66
 
67
+ # βœ… Only proceed if at least one "yes"
68
  has_positive = any(entry.get("answer", "").lower() == "yes" for entry in checked)
69
  if not has_positive:
70
+ return f"<b>❌ Not found diagnosis in the chart related to HCC code {hcc_code_str}.</b>"
71
 
72
+ # Step 3: MEAT Validation
73
  meat_validator = MEATValidatorAgent()
74
  meat_results = meat_validator.run(checked)
75
 
 
79
  print(f"[ERROR] {e}")
80
  return f"<div style='color:red; font-weight:bold;'>⚠️ Error during processing: {e}</div>"
81
 
82
+
83
+ # ---------- Gradio Theme ----------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  simple_theme = gr.themes.Soft(
85
  primary_hue=gr.themes.colors.blue,
86
  secondary_hue=gr.themes.colors.slate,
 
93
  background_fill_secondary="#f8fafc",
94
  )
95
 
96
+
97
+ # ---------- Helper for Sample PDF ----------
98
+ def load_sample_pdf():
99
+ if not os.path.exists(SAMPLE_PDF):
100
+ raise FileNotFoundError(f"Sample PDF not found at {SAMPLE_PDF}")
101
+ # Create a simple wrapper so it has a `.name` attribute
102
+ class PDFWrapper:
103
+ def __init__(self, path):
104
+ self.name = path
105
+ return PDFWrapper(SAMPLE_PDF)
106
+
107
+
108
+ # ---------- Gradio UI ----------
109
  with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
110
  gr.HTML(f"""
111
  <h1 style='text-align:center;color:#1e40af;'> 🏩 {APP_TITLE}</h1>
 
114
  </p>
115
  """)
116
 
117
+ with gr.Row():
 
118
  with gr.Column(scale=1):
119
+ pdf_upload = gr.File(label="Upload Patient Chart (PDF)", file_types=[".pdf"])
120
+ hcc_code = gr.Textbox(label="HCC Code (e.g., 12)", placeholder="Enter HCC code")
121
+ model_version = gr.Dropdown(choices=["V24", "V28"], label="Model Version", value="V24")
122
+ run_btn = gr.Button("πŸš€ Run Validation", variant="primary")
123
+
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  with gr.Column(scale=2):
125
  output_md = gr.Markdown(
126
  label="Validation Report",
127
  value="<div style='border:2px solid #1e40af; border-radius:12px; padding:15px; background-color:#f0f9ff;'>πŸ“„ Upload a PDF and click <b>Run Validation</b> to start.</div>",
128
  )
129
 
130
+ # ---------- Run validation ----------
131
  run_btn.click(
132
+ fn=process_pipeline,
133
  inputs=[pdf_upload, hcc_code, model_version],
134
+ outputs=[output_md],
135
  )
136
 
137
+ # ---------- Sample PDF using Gradio Examples ----------
138
+ gr.Examples(
139
+ examples=[[SAMPLE_PDF]],
140
+ inputs=[pdf_upload],
141
+ outputs=[output_md],
142
+ fn=lambda x: process_pipeline(load_sample_pdf(), hcc_code="12", model_version="V24"),
143
+ cache_examples=False
144
  )
145
 
146
+
147
  if __name__ == "__main__":
148
  interface.queue().launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))
149
+
150
+
151
+
152
+
153
+
154
+ # import os
155
+ # import gradio as gr
156
+ # import json
157
+
158
+ # from HCCDiagnosisListEngine import HCCDiagnosisListEngine
159
+ # from chartdiagnosischecker import ChartDiagnosisChecker
160
+ # from MeatValidatorAgent import MEATValidatorAgent
161
+
162
+ # APP_TITLE = "Risk Adjustment (HCC Chart Validation)"
163
+ # CSV_PATH = "hcc_mapping.csv"
164
+ # SAMPLE_PDF = "sample_patient_chart.pdf" # Place a sample PDF in the same folder
165
+
166
+
167
+ # # ---------- Helper: JSON β†’ Markdown ----------
168
+ # def json_to_markdown(meat_results: list[dict]) -> str:
169
+ # if not meat_results:
170
+ # return "<div style='color:orange; font-weight:bold;'>⚠️ No results found.</div>"
171
+
172
+ # md = "<div style='border:2px solid #1e40af; border-radius:12px; padding:15px; background-color:#f0f9ff;'>"
173
+ # md += "<h2 style='color:#1e40af;'>🩺 HCC Chart Validation Report</h2>"
174
+
175
+ # for entry in meat_results:
176
+ # md += f"<h3 style='color:#1d4ed8;'>πŸ“Œ {entry['diagnosis']} ({entry['icd10']})</h3>"
177
+ # md += f"<p><b>Reference:</b> {entry.get('reference', 'N/A')}<br>"
178
+ # md += f"<b>Answer:</b> {entry.get('answer', 'unknown').upper()}<br>"
179
+ # md += f"<b>Rationale:</b> {entry.get('rationale', '')}<br>"
180
+ # md += f"<b>Clinical Status:</b> {entry.get('clinical_status', 'N/A')}</p>"
181
+ # md += "<b>MEAT Criteria:</b><ul>"
182
+ # meat = entry.get("meat", {})
183
+ # md += f"<li>Monitor: {'βœ…' if meat.get('monitor') else '❌'}</li>"
184
+ # md += f"<li>Evaluate: {'βœ…' if meat.get('evaluate') else '❌'}</li>"
185
+ # md += f"<li>Assess: {'βœ…' if meat.get('assess') else '❌'}</li>"
186
+ # md += f"<li>Treat: {'βœ…' if meat.get('treat') else '❌'}</li>"
187
+ # md += "</ul>"
188
+ # md += f"<b>MEAT Rationale:</b> {entry.get('meat_rationale', '')}<br><br>"
189
+ # md += "</div>"
190
+ # return md
191
+
192
+
193
+ # # ---------- Pipeline ----------
194
+ # def process_pipeline(pdf_file, hcc_code, model_version, csv_path=CSV_PATH):
195
+ # try:
196
+ # if pdf_file is None:
197
+ # return "<div style='color:orange; font-weight:bold;'>⚠️ Please upload a patient chart PDF.</div>"
198
+
199
+ # if not hcc_code or str(hcc_code).strip() == "":
200
+ # return "<div style='color:orange; font-weight:bold;'>⚠️ Please enter a valid HCC Code before running validation.</div>"
201
+
202
+ # pdf_path = pdf_file.name
203
+ # patient_name = os.path.splitext(os.path.basename(pdf_path))[0]
204
+ # print(f"\n[PROCESSING] {patient_name}")
205
+
206
+ # # Step 1: HCC Diagnoses
207
+ # diag_engine = HCCDiagnosisListEngine(hcc_code, model_version, csv_path)
208
+ # diagnoses = diag_engine.run()
209
+
210
+ # # Step 2: Chart Checking
211
+ # checker = ChartDiagnosisChecker(pdf_path)
212
+ # checked = checker.run(diagnoses)
213
+
214
+ # # βœ… Only proceed if at least one "yes"
215
+ # has_positive = any(entry.get("answer", "").lower() == "yes" for entry in checked)
216
+ # if not has_positive:
217
+ # return f"<b>❌ Not found diagnosis in the chart related to HCC code {hcc_code}.</b>"
218
+
219
+ # # Step 3: MEAT Validation
220
+ # meat_validator = MEATValidatorAgent()
221
+ # meat_results = meat_validator.run(checked)
222
+
223
+ # return json_to_markdown(meat_results)
224
+
225
+ # except Exception as e:
226
+ # print(f"[ERROR] {e}")
227
+ # return f"<div style='color:red; font-weight:bold;'>⚠️ Error during processing: {e}</div>"
228
+
229
+
230
+ # # ---------- Gradio Theme ----------
231
+ # simple_theme = gr.themes.Soft(
232
+ # primary_hue=gr.themes.colors.blue,
233
+ # secondary_hue=gr.themes.colors.slate,
234
+ # neutral_hue=gr.themes.colors.slate,
235
+ # ).set(
236
+ # button_primary_background_fill="#1e40af",
237
+ # button_primary_background_fill_hover="#1d4ed8",
238
+ # button_primary_text_color="white",
239
+ # background_fill_primary="white",
240
+ # background_fill_secondary="#f8fafc",
241
+ # )
242
+
243
+
244
+ # # ---------- Gradio UI ----------
245
+ # with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
246
+ # gr.HTML(f"""
247
+ # <h1 style='text-align:center;color:#1e40af;'> 🏩 {APP_TITLE}</h1>
248
+ # <p style='text-align:center;color:#64748b;'>
249
+ # Upload a chart, set HCC + model version, and validate MEAT criteria.
250
+ # </p>
251
+ # """)
252
+
253
+ # with gr.Row():
254
+ # with gr.Column(scale=1):
255
+ # pdf_upload = gr.File(label="Upload Patient Chart (PDF)", file_types=[".pdf"])
256
+ # hcc_code = gr.Textbox(label="HCC Code (e.g., 12)", placeholder="Enter HCC code")
257
+ # model_version = gr.Dropdown(choices=["V24", "V28"], label="Model Version", value="V24")
258
+ # run_btn = gr.Button("πŸš€ Run Validation", variant="primary")
259
+ # sample_btn = gr.Button("πŸ“„ Use Sample PDF", variant="secondary")
260
+
261
+ # with gr.Column(scale=2):
262
+ # output_md = gr.Markdown(
263
+ # label="Validation Report",
264
+ # value="<div style='border:2px solid #1e40af; border-radius:12px; padding:15px; background-color:#f0f9ff;'>πŸ“„ Upload a PDF and click <b>Run Validation</b> to start.</div>",
265
+ # )
266
+
267
+ # # ---------- Button Events ----------
268
+ # sample_btn.click(
269
+ # fn=lambda: gr.File.update(value=SAMPLE_PDF),
270
+ # inputs=[],
271
+ # outputs=[pdf_upload],
272
+ # )
273
+
274
+ # run_btn.click(
275
+ # fn=process_pipeline,
276
+ # inputs=[pdf_upload, hcc_code, model_version],
277
+ # outputs=[output_md],
278
+ # )
279
+
280
+
281
+ # if __name__ == "__main__":
282
+ # interface.queue().launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+ #### old
302
+ # import os
303
+ # import gradio as gr
304
+ # import json
305
+
306
+ # from HCCDiagnosisListEngine import HCCDiagnosisListEngine
307
+ # from chartdiagnosischecker import ChartDiagnosisChecker
308
+ # from MeatValidatorAgent import MEATValidatorAgent
309
+
310
+ # APP_TITLE = "Risk Adjustment (HCC Chart Validation)"
311
+ # CSV_PATH = "hcc_mapping.csv"
312
+
313
+ # # ---------- Helper: JSON β†’ Markdown ----------
314
+ # def json_to_markdown(meat_results: list[dict]) -> str:
315
+ # if not meat_results:
316
+ # return "⚠️ **No results found.**"
317
+
318
+ # md = "## πŸ₯ HCC Chart Validation Report\n\n"
319
+
320
+ # for entry in meat_results:
321
+ # md += f"### πŸ“Œ {entry['diagnosis']} ({entry['icd10']})\n"
322
+ # md += f"- **Reference:** {entry.get('reference', 'N/A')}\n"
323
+ # md += f"- **Answer:** {entry.get('answer', 'unknown').upper()}\n"
324
+ # md += f"- **Rationale:** {entry.get('rationale', '')}\n"
325
+ # md += f"- **Clinical Status:** {entry.get('clinical_status', 'N/A')}\n"
326
+ # md += f"- **MEAT Criteria:**\n"
327
+ # meat = entry.get("meat", {})
328
+ # if meat:
329
+ # md += " - Monitor: βœ…\n" if meat.get("monitor") else " - Monitor: ❌\n"
330
+ # md += " - Evaluate: βœ…\n" if meat.get("evaluate") else " - Evaluate: ❌\n"
331
+ # md += " - Assess: βœ…\n" if meat.get("assess") else " - Assess: ❌\n"
332
+ # md += " - Treat: βœ…\n" if meat.get("treat") else " - Treat: ❌\n"
333
+ # md += f"- **MEAT Rationale:** {entry.get('meat_rationale', '')}\n\n"
334
+ # return md.strip()
335
+
336
+
337
+
338
+ # # ---------- Pipeline ----------
339
+ # def process_pipeline(pdf_file, hcc_code, model_version, csv_path=CSV_PATH):
340
+ # try:
341
+ # if pdf_file is None:
342
+ # return "⚠️ Please upload a patient chart PDF."
343
+
344
+ # if not hcc_code or str(hcc_code).strip() == "":
345
+ # return "⚠️ Please enter a valid HCC Code before running validation."
346
+
347
+ # pdf_path = pdf_file.name
348
+ # patient_name = os.path.splitext(os.path.basename(pdf_path))[0]
349
+ # print(f"\n[PROCESSING] {patient_name}")
350
+
351
+
352
+
353
+ # # Step 1: HCC Diagnoses
354
+ # diag_engine = HCCDiagnosisListEngine(hcc_code, model_version, csv_path)
355
+ # diagnoses = diag_engine.run()
356
+
357
+ # # Step 2: Chart Checking
358
+ # checker = ChartDiagnosisChecker(pdf_path)
359
+ # checked = checker.run(diagnoses)
360
+
361
+ # # βœ… New condition: only proceed if at least one "yes"
362
+ # has_positive = any(entry.get("answer", "").lower() == "yes" for entry in checked)
363
+ # if not has_positive:
364
+ # return f"**❌ Not found diagnosis in the chart related to HCC code {hcc_code}.**"
365
+
366
+ # # Step 3: MEAT Validation
367
+ # meat_validator = MEATValidatorAgent()
368
+ # meat_results = meat_validator.run(checked)
369
+
370
+ # return json_to_markdown(meat_results)
371
+
372
+ # except Exception as e:
373
+ # print(f"[ERROR] {e}")
374
+ # return f"⚠️ Error during processing: {e}"
375
+
376
+
377
+
378
+
379
+ # # ---------- Gradio Theme ----------
380
+ # simple_theme = gr.themes.Soft(
381
+ # primary_hue=gr.themes.colors.blue,
382
+ # secondary_hue=gr.themes.colors.slate,
383
+ # neutral_hue=gr.themes.colors.slate,
384
+ # ).set(
385
+ # button_primary_background_fill="#1e40af",
386
+ # button_primary_background_fill_hover="#1d4ed8",
387
+ # button_primary_text_color="white",
388
+ # background_fill_primary="white",
389
+ # background_fill_secondary="#f8fafc",
390
+ # )
391
+
392
+
393
+ # # ---------- Gradio UI ----------
394
+ # with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
395
+ # gr.HTML(f"<h1 style='text-align:center;color:#1e40af;'>πŸ₯ {APP_TITLE}</h1>")
396
+ # gr.HTML("<p style='text-align:center;color:#64748b;'>Upload a chart, set HCC + model version, and validate MEAT criteria.</p>")
397
+
398
+ # with gr.Row():
399
+ # with gr.Column(scale=1):
400
+ # pdf_upload = gr.File(label="Upload Patient Chart (PDF)", file_types=[".pdf"])
401
+ # hcc_code = gr.Textbox(label="HCC Code (e.g., 12)", placeholder="Enter HCC code")
402
+ # model_version = gr.Dropdown(choices=["V24", "V28"], label="Model Version", value="V24")
403
+ # run_btn = gr.Button("πŸš€ Run Validation", variant="primary")
404
+
405
+ # with gr.Column(scale=2):
406
+ # output_md = gr.Markdown(
407
+ # label="Validation Report",
408
+ # value="πŸ“„ Upload a PDF and click **Run Validation** to start.",
409
+ # )
410
+
411
+ # run_btn.click(
412
+ # fn=process_pipeline,
413
+ # inputs=[pdf_upload, hcc_code, model_version],
414
+ # outputs=[output_md],
415
+ # )
416
+
417
+
418
+ # if __name__ == "__main__":
419
+ # interface.queue().launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))