Update app.py
Browse files
app.py
CHANGED
|
@@ -230,28 +230,54 @@ desc = (
|
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
| 248 |
|
| 249 |
-
|
|
|
|
| 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
|
| 254 |
-
seg_overlay = gr.Image(type="pil", label="Segmentation Overlay
|
| 255 |
|
| 256 |
submit_btn.click(
|
| 257 |
fn=inference_pipeline,
|
|
@@ -259,16 +285,35 @@ with gr.Blocks(title=title) as demo:
|
|
| 259 |
outputs=[pred_label, prob_b, prob_v, masked_img, seg_overlay]
|
| 260 |
)
|
| 261 |
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 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 |
-
|
|
|
|
| 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,
|
|
|
|
| 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 |
+
height=300
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
+
load_btn = gr.Button("Load Selected Example")
|
| 306 |
+
|
| 307 |
+
def load_example(example_row):
|
| 308 |
+
if example_row is None or len(example_row) == 0:
|
| 309 |
+
return None
|
| 310 |
+
img_path = example_row[0]["Image"]
|
| 311 |
+
return img_path
|
| 312 |
+
|
| 313 |
+
load_btn.click(
|
| 314 |
+
fn=load_example,
|
| 315 |
+
inputs=examples_table,
|
| 316 |
+
outputs=image_input
|
| 317 |
+
)
|
| 318 |
if __name__ == "__main__":
|
| 319 |
demo.launch(share=False)
|
|
|