Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,10 +17,8 @@ CSV_PATH = "hcc_mapping.csv"
|
|
| 17 |
SAMPLE_PDF = "sample_patient_chart.pdf" # Place a sample PDF in the same folder
|
| 18 |
|
| 19 |
|
|
|
|
| 20 |
def json_to_markdown(data) -> str:
|
| 21 |
-
"""
|
| 22 |
-
Convert JSON (dict or list) into a clean, styled Markdown/HTML string.
|
| 23 |
-
"""
|
| 24 |
try:
|
| 25 |
if isinstance(data, dict) and "final_analysis" in data:
|
| 26 |
patient_id = data.get("patient_id", "Unknown Patient")
|
|
@@ -217,6 +215,15 @@ def load_sample_pdf():
|
|
| 217 |
return PDFWrapper(SAMPLE_PDF)
|
| 218 |
|
| 219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
# ---------- Gradio UI ----------
|
| 221 |
with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
|
| 222 |
gr.HTML(f"""
|
|
@@ -234,17 +241,17 @@ with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
|
|
| 234 |
|
| 235 |
with gr.Row():
|
| 236 |
with gr.Column(scale=1):
|
| 237 |
-
|
| 238 |
-
pdf_preview = gr.PDF(label="📑 PDF Preview", height=600)
|
| 239 |
with gr.Column(scale=2):
|
| 240 |
output_md = gr.Markdown(
|
| 241 |
label="Validation Report",
|
| 242 |
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>",
|
| 243 |
)
|
| 244 |
|
| 245 |
-
#
|
| 246 |
-
pdf_upload.change(fn=
|
| 247 |
|
|
|
|
| 248 |
run_btn.click(
|
| 249 |
fn=process_pipeline,
|
| 250 |
inputs=[pdf_upload, hcc_code, model_version],
|
|
@@ -264,4 +271,4 @@ if __name__ == "__main__":
|
|
| 264 |
interface.queue().launch(
|
| 265 |
server_name="0.0.0.0",
|
| 266 |
server_port=int(os.environ.get("PORT", 7860))
|
| 267 |
-
)
|
|
|
|
| 17 |
SAMPLE_PDF = "sample_patient_chart.pdf" # Place a sample PDF in the same folder
|
| 18 |
|
| 19 |
|
| 20 |
+
# ---------- JSON to Markdown ----------
|
| 21 |
def json_to_markdown(data) -> str:
|
|
|
|
|
|
|
|
|
|
| 22 |
try:
|
| 23 |
if isinstance(data, dict) and "final_analysis" in data:
|
| 24 |
patient_id = data.get("patient_id", "Unknown Patient")
|
|
|
|
| 215 |
return PDFWrapper(SAMPLE_PDF)
|
| 216 |
|
| 217 |
|
| 218 |
+
# ---------- Helper for PDF Preview ----------
|
| 219 |
+
def pdf_to_iframe(file):
|
| 220 |
+
if file is None:
|
| 221 |
+
return "<p style='color:orange;'>No PDF uploaded.</p>"
|
| 222 |
+
return f"""
|
| 223 |
+
<iframe src="{file.name}" width="100%" height="600px" style="border:1px solid #ccc;"></iframe>
|
| 224 |
+
"""
|
| 225 |
+
|
| 226 |
+
|
| 227 |
# ---------- Gradio UI ----------
|
| 228 |
with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
|
| 229 |
gr.HTML(f"""
|
|
|
|
| 241 |
|
| 242 |
with gr.Row():
|
| 243 |
with gr.Column(scale=1):
|
| 244 |
+
pdf_preview = gr.HTML(label="📑 PDF Preview", value="<p>Upload a PDF to preview</p>")
|
|
|
|
| 245 |
with gr.Column(scale=2):
|
| 246 |
output_md = gr.Markdown(
|
| 247 |
label="Validation Report",
|
| 248 |
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>",
|
| 249 |
)
|
| 250 |
|
| 251 |
+
# Connect PDF upload to preview
|
| 252 |
+
pdf_upload.change(fn=pdf_to_iframe, inputs=pdf_upload, outputs=pdf_preview)
|
| 253 |
|
| 254 |
+
# Connect run button
|
| 255 |
run_btn.click(
|
| 256 |
fn=process_pipeline,
|
| 257 |
inputs=[pdf_upload, hcc_code, model_version],
|
|
|
|
| 271 |
interface.queue().launch(
|
| 272 |
server_name="0.0.0.0",
|
| 273 |
server_port=int(os.environ.get("PORT", 7860))
|
| 274 |
+
)
|