Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from PIL import Image
|
|
| 6 |
import torch
|
| 7 |
import torchxrayvision as xrv
|
| 8 |
from torchvision import transforms
|
|
|
|
| 9 |
|
| 10 |
# -----------------------------
|
| 11 |
# Imaging Agent (Chest X-ray, proxy for lung cancer risk)
|
|
@@ -55,7 +56,6 @@ CANCER_MARKERS = {
|
|
| 55 |
"afp": {"unit": "ng/mL", "high": 10},
|
| 56 |
}
|
| 57 |
|
| 58 |
-
import re
|
| 59 |
def lab_agent(text: str):
|
| 60 |
if not text.strip():
|
| 61 |
return "No lab text provided."
|
|
@@ -88,34 +88,15 @@ def coordinator(imaging_txt, lab_txt):
|
|
| 88 |
# -----------------------------
|
| 89 |
# Gradio UI
|
| 90 |
# -----------------------------
|
| 91 |
-
with gr.Blocks(theme="soft") as demo:
|
| 92 |
-
gr.Markdown("# 🏥 AI Diagnostics Agent: Early Cancer Discovery (Demo)")
|
| 93 |
-
gr.Markdown("Upload a chest X-ray or paste tumor marker labs.\n\n⚠️ Research demo only. Not for clinical use.")
|
| 94 |
-
|
| 95 |
-
with gr.Row():
|
| 96 |
-
with gr.Column():
|
| 97 |
-
img_in = gr.Image(type="filepath", label="Chest X-ray (PNG/JPG)")
|
| 98 |
-
imaging_out = gr.Textbox(label="Imaging Agent Output")
|
| 99 |
-
imaging_raw = gr.Code(label="Probabilities JSON", language="json")
|
| 100 |
-
with gr.Column():
|
| 101 |
-
lab_in = gr.Textbox(lines=6, label="Lab Results (e.g., 'PSA: 8 ng/mL')")
|
| 102 |
-
lab_out = gr.Textbox(label="Lab Agent Output")
|
| 103 |
-
|
| 104 |
-
run_btn = gr.Button("Run Agents")
|
| 105 |
-
coord_out = gr.Textbox(label="Coordinator Summary", lines=10)
|
| 106 |
-
|
| 107 |
-
def run_all(image, labs):
|
| 108 |
-
txt, raw = imaging_agent(image) if image else ("No image.", None)
|
| 109 |
-
lab = lab_agent(labs)
|
| 110 |
-
coord = coordinator(txt, lab)
|
| 111 |
-
return txt, raw, lab, coord
|
| 112 |
-
|
| 113 |
-
run_btn.click(run_all, inputs=[img_in, lab_in], outputs=[imaging_out, imaging_raw, lab_out, coord_out])
|
| 114 |
-
|
| 115 |
-
# Preload with demo samples
|
| 116 |
SAMPLE_XRAY = "samples/sample_xray.jpg"
|
| 117 |
SAMPLE_LABS = "PSA: 8 ng/mL\nCA125: 20 U/mL\nAFP: 15 ng/mL"
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
with gr.Blocks(theme="soft") as demo:
|
| 120 |
gr.Markdown("# 🏥 AI Diagnostics Agent: Early Cancer Discovery (Demo)")
|
| 121 |
gr.Markdown("Upload a chest X-ray or paste tumor marker labs.\n\n⚠️ Research demo only. Not for clinical use.")
|
|
@@ -132,8 +113,10 @@ with gr.Blocks(theme="soft") as demo:
|
|
| 132 |
run_btn = gr.Button("Run Agents")
|
| 133 |
coord_out = gr.Textbox(label="Coordinator Summary", lines=10)
|
| 134 |
|
|
|
|
| 135 |
|
| 136 |
demo.launch()
|
| 137 |
|
| 138 |
|
| 139 |
|
|
|
|
|
|
| 6 |
import torch
|
| 7 |
import torchxrayvision as xrv
|
| 8 |
from torchvision import transforms
|
| 9 |
+
import re
|
| 10 |
|
| 11 |
# -----------------------------
|
| 12 |
# Imaging Agent (Chest X-ray, proxy for lung cancer risk)
|
|
|
|
| 56 |
"afp": {"unit": "ng/mL", "high": 10},
|
| 57 |
}
|
| 58 |
|
|
|
|
| 59 |
def lab_agent(text: str):
|
| 60 |
if not text.strip():
|
| 61 |
return "No lab text provided."
|
|
|
|
| 88 |
# -----------------------------
|
| 89 |
# Gradio UI
|
| 90 |
# -----------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
SAMPLE_XRAY = "samples/sample_xray.jpg"
|
| 92 |
SAMPLE_LABS = "PSA: 8 ng/mL\nCA125: 20 U/mL\nAFP: 15 ng/mL"
|
| 93 |
|
| 94 |
+
def run_all(image, labs):
|
| 95 |
+
txt, raw = imaging_agent(image) if image else ("No image.", None)
|
| 96 |
+
lab = lab_agent(labs)
|
| 97 |
+
coord = coordinator(txt, lab)
|
| 98 |
+
return txt, raw, lab, coord
|
| 99 |
+
|
| 100 |
with gr.Blocks(theme="soft") as demo:
|
| 101 |
gr.Markdown("# 🏥 AI Diagnostics Agent: Early Cancer Discovery (Demo)")
|
| 102 |
gr.Markdown("Upload a chest X-ray or paste tumor marker labs.\n\n⚠️ Research demo only. Not for clinical use.")
|
|
|
|
| 113 |
run_btn = gr.Button("Run Agents")
|
| 114 |
coord_out = gr.Textbox(label="Coordinator Summary", lines=10)
|
| 115 |
|
| 116 |
+
run_btn.click(run_all, inputs=[img_in, lab_in], outputs=[imaging_out, imaging_raw, lab_out, coord_out])
|
| 117 |
|
| 118 |
demo.launch()
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
+
|