Update app.py
Browse files
app.py
CHANGED
|
@@ -230,49 +230,45 @@ desc = (
|
|
| 230 |
"If both classifiers fire, the stronger probability is chosen (fallback). Thresholds adjustable."
|
| 231 |
)
|
| 232 |
|
| 233 |
-
|
| 234 |
-
example_samples = [
|
| 235 |
-
["images/NORMAL.jpeg", "NORMAL"],
|
| 236 |
-
["images/VIRAL.jpeg", "VIRAL"],
|
| 237 |
-
["images/BACT.jpeg", "BACTERIAL"],
|
| 238 |
-
]
|
| 239 |
-
|
| 240 |
-
|
| 241 |
with gr.Blocks(title=title) as demo:
|
| 242 |
gr.Markdown(f"### {title}")
|
| 243 |
gr.Markdown(desc)
|
| 244 |
|
| 245 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
fn=inference_pipeline,
|
| 247 |
-
inputs=[
|
| 248 |
-
|
| 249 |
-
gr.Slider(minimum=0.1, maximum=0.9, step=0.01, value=0.5,
|
| 250 |
-
label="Bacterial threshold (thresh_b)"),
|
| 251 |
-
gr.Slider(minimum=0.1, maximum=0.9, step=0.01, value=0.5,
|
| 252 |
-
label="Viral threshold (thresh_v)"),
|
| 253 |
-
gr.Slider(minimum=0.1, maximum=0.9, step=0.01, value=0.5,
|
| 254 |
-
label="Segmentation mask threshold (seg_thresh)")
|
| 255 |
-
],
|
| 256 |
-
outputs=[
|
| 257 |
-
gr.Label(num_top_classes=1, label="Prediction"),
|
| 258 |
-
gr.Number(label="Bacterial Probability"),
|
| 259 |
-
gr.Number(label="Viral Probability"),
|
| 260 |
-
gr.Image(type="pil", label="Masked Image (input × mask)"),
|
| 261 |
-
gr.Image(type="pil", label="Segmentation Overlay (red mask)")
|
| 262 |
-
],
|
| 263 |
-
allow_flagging="never"
|
| 264 |
)
|
| 265 |
|
| 266 |
-
gr.
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
col_count=(2, "fixed")
|
| 275 |
)
|
| 276 |
|
| 277 |
if __name__ == "__main__":
|
| 278 |
demo.launch(share=False)
|
|
|
|
|
|
| 230 |
"If both classifiers fire, the stronger probability is chosen (fallback). Thresholds adjustable."
|
| 231 |
)
|
| 232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
with gr.Blocks(title=title) as demo:
|
| 234 |
gr.Markdown(f"### {title}")
|
| 235 |
gr.Markdown(desc)
|
| 236 |
|
| 237 |
+
with gr.Row():
|
| 238 |
+
with gr.Column():
|
| 239 |
+
image_input = gr.Image(
|
| 240 |
+
type="numpy",
|
| 241 |
+
label="Upload chest X-ray (RGB or grayscale)"
|
| 242 |
+
)
|
| 243 |
+
thresh_b = gr.Slider(0.1, 0.9, value=0.5, step=0.01, label="Bacterial threshold (thresh_b)")
|
| 244 |
+
thresh_v = gr.Slider(0.1, 0.9, value=0.5, step=0.01, label="Viral threshold (thresh_v)")
|
| 245 |
+
seg_thresh = gr.Slider(0.1, 0.9, value=0.5, step=0.01, label="Segmentation mask threshold (seg_thresh)")
|
| 246 |
+
|
| 247 |
+
submit_btn = gr.Button("Run Inference")
|
| 248 |
+
|
| 249 |
+
with gr.Column():
|
| 250 |
+
pred_label = gr.Label(num_top_classes=1, label="Prediction")
|
| 251 |
+
prob_b = gr.Number(label="Bacterial Probability")
|
| 252 |
+
prob_v = gr.Number(label="Viral Probability")
|
| 253 |
+
masked_img = gr.Image(type="pil", label="Masked Image (input × mask)")
|
| 254 |
+
seg_overlay = gr.Image(type="pil", label="Segmentation Overlay (red mask)")
|
| 255 |
+
|
| 256 |
+
submit_btn.click(
|
| 257 |
fn=inference_pipeline,
|
| 258 |
+
inputs=[image_input, thresh_b, thresh_v, seg_thresh],
|
| 259 |
+
outputs=[pred_label, prob_b, prob_v, masked_img, seg_overlay]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
)
|
| 261 |
|
| 262 |
+
gr.Examples(
|
| 263 |
+
examples=[
|
| 264 |
+
["images/NORMAL.jpeg"],
|
| 265 |
+
["images/VIRAL.jpeg"],
|
| 266 |
+
["images/BACT.jpeg"],
|
| 267 |
+
],
|
| 268 |
+
inputs=image_input,
|
| 269 |
+
label="Try Examples"
|
|
|
|
| 270 |
)
|
| 271 |
|
| 272 |
if __name__ == "__main__":
|
| 273 |
demo.launch(share=False)
|
| 274 |
+
|