Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -218,15 +218,15 @@ def load_sample_pdf():
|
|
| 218 |
return PDFWrapper(SAMPLE_PDF)
|
| 219 |
|
| 220 |
|
| 221 |
-
# ---------- PDF Embed Helper (
|
| 222 |
def embed_pdf(file):
|
| 223 |
if file is None:
|
| 224 |
return "<div style='color:gray;'>No PDF uploaded.</div>"
|
| 225 |
-
|
| 226 |
-
pdf_path = file.name
|
| 227 |
return f"""
|
| 228 |
<iframe
|
| 229 |
-
src="
|
| 230 |
width="100%" height="600px" style="border:1px solid #ccc;border-radius:8px;">
|
| 231 |
</iframe>
|
| 232 |
"""
|
|
@@ -241,14 +241,12 @@ with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
|
|
| 241 |
</p>
|
| 242 |
""")
|
| 243 |
|
| 244 |
-
# Top row
|
| 245 |
with gr.Row():
|
| 246 |
pdf_upload = gr.File(label="Upload Patient Chart (PDF)", file_types=[".pdf"], scale=2)
|
| 247 |
hcc_code = gr.Textbox(label="HCC Code (e.g., 12)", placeholder="Enter HCC code", scale=1)
|
| 248 |
model_version = gr.Dropdown(choices=["V24", "V28"], label="Model Version", value="V24", scale=1)
|
| 249 |
run_btn = gr.Button("π Run Validation", variant="primary", scale=1)
|
| 250 |
|
| 251 |
-
# Main content row
|
| 252 |
with gr.Row():
|
| 253 |
with gr.Column(scale=1):
|
| 254 |
pdf_preview = gr.HTML(label="π PDF Preview")
|
|
@@ -258,17 +256,14 @@ with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
|
|
| 258 |
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>",
|
| 259 |
)
|
| 260 |
|
| 261 |
-
# Connect PDF upload β preview
|
| 262 |
pdf_upload.change(fn=embed_pdf, inputs=pdf_upload, outputs=pdf_preview)
|
| 263 |
|
| 264 |
-
# Run validation
|
| 265 |
run_btn.click(
|
| 266 |
fn=process_pipeline,
|
| 267 |
inputs=[pdf_upload, hcc_code, model_version],
|
| 268 |
outputs=[output_md],
|
| 269 |
)
|
| 270 |
|
| 271 |
-
# Example
|
| 272 |
gr.Examples(
|
| 273 |
examples=[[SAMPLE_PDF]],
|
| 274 |
inputs=[pdf_upload],
|
|
@@ -281,6 +276,5 @@ with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
|
|
| 281 |
if __name__ == "__main__":
|
| 282 |
interface.queue().launch(
|
| 283 |
server_name="0.0.0.0",
|
| 284 |
-
server_port=int(os.environ.get("PORT", 7860))
|
| 285 |
-
static_dirs={"pdfjs": "pdfjs"} # <-- serve PDF.js files
|
| 286 |
)
|
|
|
|
| 218 |
return PDFWrapper(SAMPLE_PDF)
|
| 219 |
|
| 220 |
|
| 221 |
+
# ---------- PDF Embed Helper (PDF.js) ----------
|
| 222 |
def embed_pdf(file):
|
| 223 |
if file is None:
|
| 224 |
return "<div style='color:gray;'>No PDF uploaded.</div>"
|
| 225 |
+
|
| 226 |
+
pdf_path = file.name
|
| 227 |
return f"""
|
| 228 |
<iframe
|
| 229 |
+
src="pdfjs/web/viewer.html?file=/file={pdf_path}"
|
| 230 |
width="100%" height="600px" style="border:1px solid #ccc;border-radius:8px;">
|
| 231 |
</iframe>
|
| 232 |
"""
|
|
|
|
| 241 |
</p>
|
| 242 |
""")
|
| 243 |
|
|
|
|
| 244 |
with gr.Row():
|
| 245 |
pdf_upload = gr.File(label="Upload Patient Chart (PDF)", file_types=[".pdf"], scale=2)
|
| 246 |
hcc_code = gr.Textbox(label="HCC Code (e.g., 12)", placeholder="Enter HCC code", scale=1)
|
| 247 |
model_version = gr.Dropdown(choices=["V24", "V28"], label="Model Version", value="V24", scale=1)
|
| 248 |
run_btn = gr.Button("π Run Validation", variant="primary", scale=1)
|
| 249 |
|
|
|
|
| 250 |
with gr.Row():
|
| 251 |
with gr.Column(scale=1):
|
| 252 |
pdf_preview = gr.HTML(label="π PDF Preview")
|
|
|
|
| 256 |
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>",
|
| 257 |
)
|
| 258 |
|
|
|
|
| 259 |
pdf_upload.change(fn=embed_pdf, inputs=pdf_upload, outputs=pdf_preview)
|
| 260 |
|
|
|
|
| 261 |
run_btn.click(
|
| 262 |
fn=process_pipeline,
|
| 263 |
inputs=[pdf_upload, hcc_code, model_version],
|
| 264 |
outputs=[output_md],
|
| 265 |
)
|
| 266 |
|
|
|
|
| 267 |
gr.Examples(
|
| 268 |
examples=[[SAMPLE_PDF]],
|
| 269 |
inputs=[pdf_upload],
|
|
|
|
| 276 |
if __name__ == "__main__":
|
| 277 |
interface.queue().launch(
|
| 278 |
server_name="0.0.0.0",
|
| 279 |
+
server_port=int(os.environ.get("PORT", 7860))
|
|
|
|
| 280 |
)
|