Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -513,6 +513,29 @@ def _handle_drop(files_list, current_state):
|
|
| 513 |
def clear_files():
|
| 514 |
return [], "0 file(s) selected", []
|
| 515 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
# ==============================
|
| 517 |
# UI wiring
|
| 518 |
# ==============================
|
|
@@ -612,6 +635,13 @@ def build_app():
|
|
| 612 |
value=True,
|
| 613 |
label="Compact results (show only top label + confidence)"
|
| 614 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 615 |
with gr.Column():
|
| 616 |
# Multi-upload UX: button + drag-and-drop zone (both append)
|
| 617 |
files_state = gr.State([])
|
|
@@ -682,6 +712,12 @@ def build_app():
|
|
| 682 |
outputs=[files_state, files_label, gallery, files_dnd]
|
| 683 |
)
|
| 684 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 685 |
clear_btn.click(
|
| 686 |
fn=clear_files,
|
| 687 |
inputs=None,
|
|
|
|
| 513 |
def clear_files():
|
| 514 |
return [], "0 file(s) selected", []
|
| 515 |
|
| 516 |
+
import random
|
| 517 |
+
|
| 518 |
+
def load_sample_images():
|
| 519 |
+
sample_dir = Path("sample_images")
|
| 520 |
+
|
| 521 |
+
images = [
|
| 522 |
+
str(p)
|
| 523 |
+
for p in sample_dir.glob("*")
|
| 524 |
+
if p.suffix.lower() in [".png", ".jpg", ".jpeg"]
|
| 525 |
+
]
|
| 526 |
+
|
| 527 |
+
if not images:
|
| 528 |
+
raise gr.Error("No sample MRI images found in the sample_images folder.")
|
| 529 |
+
|
| 530 |
+
# Randomly choose up to 4 images
|
| 531 |
+
selected = random.sample(images, min(4, len(images)))
|
| 532 |
+
|
| 533 |
+
return (
|
| 534 |
+
selected,
|
| 535 |
+
f"{len(selected)} sample MRI(s) loaded",
|
| 536 |
+
_gallery_from_paths(selected),
|
| 537 |
+
)
|
| 538 |
+
|
| 539 |
# ==============================
|
| 540 |
# UI wiring
|
| 541 |
# ==============================
|
|
|
|
| 635 |
value=True,
|
| 636 |
label="Compact results (show only top label + confidence)"
|
| 637 |
)
|
| 638 |
+
|
| 639 |
+
sample_btn = gr.Button(
|
| 640 |
+
"🧪 Load Sample MRIs",
|
| 641 |
+
variant="secondary",
|
| 642 |
+
size="lg"
|
| 643 |
+
)
|
| 644 |
+
|
| 645 |
with gr.Column():
|
| 646 |
# Multi-upload UX: button + drag-and-drop zone (both append)
|
| 647 |
files_state = gr.State([])
|
|
|
|
| 712 |
outputs=[files_state, files_label, gallery, files_dnd]
|
| 713 |
)
|
| 714 |
|
| 715 |
+
sample_btn.click(
|
| 716 |
+
fn=load_sample_images,
|
| 717 |
+
inputs=None,
|
| 718 |
+
outputs=[files_state, files_label, gallery]
|
| 719 |
+
)
|
| 720 |
+
|
| 721 |
clear_btn.click(
|
| 722 |
fn=clear_files,
|
| 723 |
inputs=None,
|