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