Update app.py
Browse files
app.py
CHANGED
|
@@ -227,49 +227,6 @@ title = "Chest X-ray: UNet segmentation + 2 binary classifiers"
|
|
| 227 |
desc = "Pipeline: UNet -> mask lungs -> two binary classifiers (Normal vs Bacterial, Normal vs Viral). " \
|
| 228 |
"If both classifiers fire, the stronger probability is chosen (fallback). Thresholds adjustable."
|
| 229 |
|
| 230 |
-
with gr.Blocks() as demo:
|
| 231 |
-
|
| 232 |
-
gr.Markdown("### Example Table (Image + True Label)")
|
| 233 |
-
|
| 234 |
-
example_samples = [
|
| 235 |
-
["images/NORMAL.jpg", "NORMAL"],
|
| 236 |
-
["images/VIRAL.jpg", "VIRAL"],
|
| 237 |
-
["images/BACT.jpg", "BACTERIAL"],
|
| 238 |
-
]
|
| 239 |
-
|
| 240 |
-
gr.Dataset(
|
| 241 |
-
samples=example_samples,
|
| 242 |
-
components=[
|
| 243 |
-
gr.Image(type="filepath", label="Image"),
|
| 244 |
-
gr.Textbox(label="True Label")
|
| 245 |
-
],
|
| 246 |
-
headers=["Image", "Label"],
|
| 247 |
-
label="Examples",
|
| 248 |
-
layout="table"
|
| 249 |
-
)
|
| 250 |
-
|
| 251 |
-
iface = gr.Interface(
|
| 252 |
-
fn=inference_pipeline,
|
| 253 |
-
inputs=[
|
| 254 |
-
gr.Image(type="numpy", label="Upload chest X-ray (RGB or grayscale)"),
|
| 255 |
-
gr.Slider(minimum=0.1, maximum=0.9, step=0.01, value=0.5, label="Bacterial threshold (thresh_b)"),
|
| 256 |
-
gr.Slider(minimum=0.1, maximum=0.9, step=0.01, value=0.5, label="Viral threshold (thresh_v)"),
|
| 257 |
-
gr.Slider(minimum=0.1, maximum=0.9, step=0.01, value=0.5, label="Segmentation mask threshold (seg_thresh)")
|
| 258 |
-
],
|
| 259 |
-
outputs=[
|
| 260 |
-
gr.Label(num_top_classes=1, label="Prediction"),
|
| 261 |
-
gr.Number(label="Bacterial Probability"),
|
| 262 |
-
gr.Number(label="Viral Probability"),
|
| 263 |
-
gr.Image(type="pil", label="Masked Image (input × mask)"),
|
| 264 |
-
gr.Image(type="pil", label="Segmentation Overlay (red mask)")
|
| 265 |
-
],
|
| 266 |
-
title=title,
|
| 267 |
-
description=desc,
|
| 268 |
-
allow_flagging="never"
|
| 269 |
-
)
|
| 270 |
-
|
| 271 |
-
demo.launch(share=False)
|
| 272 |
-
|
| 273 |
|
| 274 |
iface = gr.Interface(
|
| 275 |
fn=inference_pipeline,
|
|
@@ -291,6 +248,24 @@ iface = gr.Interface(
|
|
| 291 |
description=desc,
|
| 292 |
allow_flagging="never"
|
| 293 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
|
| 295 |
if __name__ == "__main__":
|
| 296 |
iface.launch(share=False)
|
|
|
|
| 227 |
desc = "Pipeline: UNet -> mask lungs -> two binary classifiers (Normal vs Bacterial, Normal vs Viral). " \
|
| 228 |
"If both classifiers fire, the stronger probability is chosen (fallback). Thresholds adjustable."
|
| 229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
|
| 231 |
iface = gr.Interface(
|
| 232 |
fn=inference_pipeline,
|
|
|
|
| 248 |
description=desc,
|
| 249 |
allow_flagging="never"
|
| 250 |
)
|
| 251 |
+
gr.Markdown("### Example Images with True Labels")
|
| 252 |
+
|
| 253 |
+
example_samples = [
|
| 254 |
+
["images/NORMAL.jpg", "NORMAL"],
|
| 255 |
+
["images/VIRAL.jpg", "VIRAL"],
|
| 256 |
+
["images/BACT.jpg", "BACTERIAL"],
|
| 257 |
+
]
|
| 258 |
+
|
| 259 |
+
gr.Dataset(
|
| 260 |
+
samples=example_samples,
|
| 261 |
+
components=[
|
| 262 |
+
gr.Image(type="filepath", label="Image"),
|
| 263 |
+
gr.Textbox(label="True Label")
|
| 264 |
+
],
|
| 265 |
+
headers=["Image", "Label"],
|
| 266 |
+
label="Test Samples",
|
| 267 |
+
layout="table"
|
| 268 |
+
)
|
| 269 |
|
| 270 |
if __name__ == "__main__":
|
| 271 |
iface.launch(share=False)
|