Clocksp commited on
Commit
2175e55
·
verified ·
1 Parent(s): 8871faa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -225,20 +225,19 @@ def inference_pipeline(img, thresh_b=0.5, thresh_v=0.5, seg_thresh=0.5):
225
 
226
 
227
  title = "Chest X-ray: UNet segmentation + 2 binary classifiers"
228
- desc = "Pipeline: UNet -> mask lungs -> two binary classifiers (Normal vs Bacterial, Normal vs Viral). " \
229
- "If both classifiers fire, the stronger probability is chosen (fallback). Thresholds adjustable."
 
 
230
 
231
 
232
- def encode_image(img_path):
233
- with open(img_path, "rb") as img:
234
- return "data:image/png;base64," + base64.b64encode(img.read()).decode()
235
-
236
  example_samples = [
237
- [f"<img src='{encode_image('images/NORMAL.jpeg')}' width='120'>", "NORMAL"],
238
- [f"<img src='{encode_image('images/VIRAL.jpeg')}' width='120'>", "VIRAL"],
239
- [f"<img src='{encode_image('images/BACT.jpeg')}' width='120'>", "BACTERIAL"],
240
  ]
241
 
 
242
  with gr.Blocks(title=title) as demo:
243
  gr.Markdown(f"### {title}")
244
  gr.Markdown(desc)
@@ -247,9 +246,12 @@ with gr.Blocks(title=title) as demo:
247
  fn=inference_pipeline,
248
  inputs=[
249
  gr.Image(type="numpy", label="Upload chest X-ray (RGB or grayscale)"),
250
- gr.Slider(minimum=0.1, maximum=0.9, step=0.01, value=0.5, label="Bacterial threshold (thresh_b)"),
251
- gr.Slider(minimum=0.1, maximum=0.9, step=0.01, value=0.5, label="Viral threshold (thresh_v)"),
252
- gr.Slider(minimum=0.1, maximum=0.9, step=0.01, value=0.5, label="Segmentation mask threshold (seg_thresh)")
 
 
 
253
  ],
254
  outputs=[
255
  gr.Label(num_top_classes=1, label="Prediction"),
@@ -266,8 +268,8 @@ with gr.Blocks(title=title) as demo:
266
  gr.Dataframe(
267
  headers=["Image", "Label"],
268
  value=example_samples,
 
269
  interactive=False,
270
- wrap=True,
271
  row_count=(len(example_samples), "fixed"),
272
  col_count=(2, "fixed")
273
  )
 
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
 
 
 
 
 
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)
 
246
  fn=inference_pipeline,
247
  inputs=[
248
  gr.Image(type="numpy", label="Upload chest X-ray (RGB or grayscale)"),
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"),
 
268
  gr.Dataframe(
269
  headers=["Image", "Label"],
270
  value=example_samples,
271
+ datatype=["image", "str"],
272
  interactive=False,
 
273
  row_count=(len(example_samples), "fixed"),
274
  col_count=(2, "fixed")
275
  )