Clocksp commited on
Commit
f89650e
·
verified ·
1 Parent(s): 9cfe489

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -89
app.py CHANGED
@@ -223,96 +223,29 @@ def inference_pipeline(img, thresh_b=0.5, thresh_v=0.5, seg_thresh=0.5):
223
  blended
224
  )
225
 
226
-
227
  title = "Chest X-ray: UNet segmentation + 2 binary classifiers"
228
- desc = (
229
- "Pipeline: UNet -> mask lungs -> two binary classifiers (Normal vs Bacterial, Normal vs Viral). "
230
- "If both classifiers fire, the stronger probability is chosen (fallback). Thresholds adjustable."
231
- )
232
-
233
- examples_df = pd.DataFrame({
234
- "Image": [
235
- "images/NORMAL.jpeg",
236
- "images/VIRAL.jpeg",
237
- "images/BACT.jpeg",
238
  ],
239
- "Label": ["NORMAL", "VIRAL", "BACTERIAL"]
240
- })
241
-
242
- with gr.Blocks(title=title) as demo:
243
-
244
- gr.Markdown(f"### {title}")
245
- gr.Markdown(desc)
246
-
247
- with gr.Row():
248
- with gr.Column(scale=1):
249
-
250
- image_input = gr.Image(
251
- type="numpy",
252
- label="Upload Chest X-ray"
253
- )
254
-
255
- thresh_b = gr.Slider(
256
- minimum=0.1, maximum=0.9, step=0.01, value=0.5,
257
- label="Bacterial Threshold"
258
- )
259
-
260
- thresh_v = gr.Slider(
261
- minimum=0.1, maximum=0.9, step=0.01, value=0.5,
262
- label="Viral Threshold"
263
- )
264
-
265
- seg_thresh = gr.Slider(
266
- minimum=0.1, maximum=0.9, step=0.01, value=0.5,
267
- label="Segmentation Mask Threshold"
268
- )
269
-
270
- with gr.Row():
271
- clear_btn = gr.Button("Clear", variant="secondary")
272
- submit_btn = gr.Button("Submit", variant="primary")
273
-
274
-
275
- with gr.Column(scale=1):
276
- pred_label = gr.Label(num_top_classes=1, label="Prediction")
277
- prob_b = gr.Number(label="Bacterial Probability")
278
- prob_v = gr.Number(label="Viral Probability")
279
- masked_img = gr.Image(type="pil", label="Masked Image")
280
- seg_overlay = gr.Image(type="pil", label="Segmentation Overlay")
281
-
282
- submit_btn.click(
283
- fn=inference_pipeline,
284
- inputs=[image_input, thresh_b, thresh_v, seg_thresh],
285
- outputs=[pred_label, prob_b, prob_v, masked_img, seg_overlay]
286
- )
287
-
288
- clear_btn.click(
289
- fn=lambda: (None, None, None, None, None),
290
- inputs=None,
291
- outputs=[pred_label, prob_b, prob_v, masked_img, seg_overlay]
292
- )
293
-
294
- with gr.Accordion("Try Examples", open=False):
295
-
296
- examples_table = gr.Dataframe(
297
- value=examples_df,
298
- headers=["Image", "Label"],
299
- datatype=["str", "str"],
300
- interactive=False,
301
- wrap=True
302
- )
303
-
304
- load_btn = gr.Button("Load Selected Example")
305
-
306
- def load_example(example_row):
307
- if example_row is None or len(example_row) == 0:
308
- return None
309
- img_path = example_row[0]["Image"]
310
- return img_path
311
 
312
- load_btn.click(
313
- fn=load_example,
314
- inputs=examples_table,
315
- outputs=image_input
316
- )
317
  if __name__ == "__main__":
318
- demo.launch(share=False)
 
223
  blended
224
  )
225
 
 
226
  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
+ iface = gr.Interface(
231
+ fn=inference_pipeline,
232
+ inputs=[
233
+ gr.Image(type="numpy", label="Upload chest X-ray (RGB or grayscale)"),
234
+ gr.Slider(minimum=0.1, maximum=0.9, step=0.01, value=0.5, label="Bacterial threshold (thresh_b)"),
235
+ gr.Slider(minimum=0.1, maximum=0.9, step=0.01, value=0.5, label="Viral threshold (thresh_v)"),
236
+ gr.Slider(minimum=0.1, maximum=0.9, step=0.01, value=0.5, label="Segmentation mask threshold (seg_thresh)")
237
  ],
238
+ outputs=[
239
+ gr.Label(num_top_classes=1, label="Prediction"),
240
+ gr.Number(label="Bacterial Probability"),
241
+ gr.Number(label="Viral Probability"),
242
+ gr.Image(type="pil", label="Masked Image (input × mask)"),
243
+ gr.Image(type="pil", label="Segmentation Overlay (red mask)")
244
+ ],
245
+ title=title,
246
+ description=desc,
247
+ allow_flagging="never"
248
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
 
 
 
 
 
 
250
  if __name__ == "__main__":
251
+ iface.launch(share=None)