disable loadinug when there is a mask
Browse files
app.py
CHANGED
|
@@ -387,14 +387,19 @@ def update_dataset_from_head(head: str) -> Dict[str, Any]:
|
|
| 387 |
return gr.update()
|
| 388 |
|
| 389 |
|
| 390 |
-
def update_upload_component_state(head: str) -> Dict[str, Any]:
|
| 391 |
"""Disable upload component for heads that require masks."""
|
| 392 |
if head in HEADS_REQUIRING_MASK:
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
)
|
| 397 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
|
| 399 |
|
| 400 |
def load_dataset_metadata(subset: str) -> Tuple[Dict[str, Any], str]:
|
|
@@ -557,10 +562,11 @@ def build_demo() -> gr.Blocks:
|
|
| 557 |
"""
|
| 558 |
)
|
| 559 |
|
|
|
|
| 560 |
head_dropdown = gr.Dropdown(
|
| 561 |
label="Model head",
|
| 562 |
choices=[(label, key) for key, label in HEAD_OPTIONS],
|
| 563 |
-
value=
|
| 564 |
)
|
| 565 |
|
| 566 |
gr.Markdown("---")
|
|
@@ -571,7 +577,7 @@ def build_demo() -> gr.Blocks:
|
|
| 571 |
dataset_dropdown = gr.Dropdown(
|
| 572 |
label="CuriaBench subset",
|
| 573 |
choices=[(meta["label"], key) for key, meta in DATASET_OPTIONS.items()],
|
| 574 |
-
value="
|
| 575 |
)
|
| 576 |
dataset_status = gr.Markdown("Select a dataset to load class metadata.")
|
| 577 |
class_dropdown = gr.Dropdown(label="Target class filter", choices=["Random"], value="Random")
|
|
@@ -579,7 +585,22 @@ def build_demo() -> gr.Blocks:
|
|
| 579 |
|
| 580 |
with gr.Column():
|
| 581 |
gr.Markdown("### Upload custom image")
|
| 582 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 583 |
|
| 584 |
gr.Markdown("---")
|
| 585 |
|
|
@@ -605,7 +626,7 @@ def build_demo() -> gr.Blocks:
|
|
| 605 |
).then(
|
| 606 |
fn=update_upload_component_state,
|
| 607 |
inputs=[head_dropdown],
|
| 608 |
-
outputs=[upload_component],
|
| 609 |
)
|
| 610 |
|
| 611 |
dataset_dropdown.change(
|
|
@@ -628,7 +649,7 @@ def build_demo() -> gr.Blocks:
|
|
| 628 |
|
| 629 |
upload_component.upload(
|
| 630 |
fn=handle_upload_preview,
|
| 631 |
-
inputs=[upload_component],
|
| 632 |
outputs=[
|
| 633 |
image_display,
|
| 634 |
status_text,
|
|
|
|
| 387 |
return gr.update()
|
| 388 |
|
| 389 |
|
| 390 |
+
def update_upload_component_state(head: str) -> Tuple[Dict[str, Any], Dict[str, Any]]:
|
| 391 |
"""Disable upload component for heads that require masks."""
|
| 392 |
if head in HEADS_REQUIRING_MASK:
|
| 393 |
+
info_update = gr.update(
|
| 394 |
+
value="⚠️ Custom image upload is disabled for this task because it requires a mask from the dataset.",
|
| 395 |
+
visible=True,
|
| 396 |
)
|
| 397 |
+
upload_update = gr.update(interactive=False)
|
| 398 |
+
return info_update, upload_update
|
| 399 |
+
|
| 400 |
+
info_update = gr.update(visible=False)
|
| 401 |
+
upload_update = gr.update(interactive=True)
|
| 402 |
+
return info_update, upload_update
|
| 403 |
|
| 404 |
|
| 405 |
def load_dataset_metadata(subset: str) -> Tuple[Dict[str, Any], str]:
|
|
|
|
| 562 |
"""
|
| 563 |
)
|
| 564 |
|
| 565 |
+
default_head = "kits"
|
| 566 |
head_dropdown = gr.Dropdown(
|
| 567 |
label="Model head",
|
| 568 |
choices=[(label, key) for key, label in HEAD_OPTIONS],
|
| 569 |
+
value=default_head,
|
| 570 |
)
|
| 571 |
|
| 572 |
gr.Markdown("---")
|
|
|
|
| 577 |
dataset_dropdown = gr.Dropdown(
|
| 578 |
label="CuriaBench subset",
|
| 579 |
choices=[(meta["label"], key) for key, meta in DATASET_OPTIONS.items()],
|
| 580 |
+
value="kits",
|
| 581 |
)
|
| 582 |
dataset_status = gr.Markdown("Select a dataset to load class metadata.")
|
| 583 |
class_dropdown = gr.Dropdown(label="Target class filter", choices=["Random"], value="Random")
|
|
|
|
| 585 |
|
| 586 |
with gr.Column():
|
| 587 |
gr.Markdown("### Upload custom image")
|
| 588 |
+
# Set initial state based on default head
|
| 589 |
+
initial_requires_mask = default_head in HEADS_REQUIRING_MASK
|
| 590 |
+
upload_info_text = gr.Markdown(
|
| 591 |
+
value=(
|
| 592 |
+
"⚠️ Custom image upload is disabled for this task because it requires a mask from the dataset."
|
| 593 |
+
if initial_requires_mask
|
| 594 |
+
else ""
|
| 595 |
+
),
|
| 596 |
+
visible=initial_requires_mask,
|
| 597 |
+
)
|
| 598 |
+
upload_component = gr.Image(
|
| 599 |
+
label="Upload image",
|
| 600 |
+
image_mode="L",
|
| 601 |
+
type="numpy",
|
| 602 |
+
interactive=not initial_requires_mask,
|
| 603 |
+
)
|
| 604 |
|
| 605 |
gr.Markdown("---")
|
| 606 |
|
|
|
|
| 626 |
).then(
|
| 627 |
fn=update_upload_component_state,
|
| 628 |
inputs=[head_dropdown],
|
| 629 |
+
outputs=[upload_info_text, upload_component],
|
| 630 |
)
|
| 631 |
|
| 632 |
dataset_dropdown.change(
|
|
|
|
| 649 |
|
| 650 |
upload_component.upload(
|
| 651 |
fn=handle_upload_preview,
|
| 652 |
+
inputs=[upload_component, dataset_dropdown],
|
| 653 |
outputs=[
|
| 654 |
image_display,
|
| 655 |
status_text,
|