Spaces:
Sleeping
Sleeping
Commit ·
be57e23
1
Parent(s): d4a259c
Pseudo-color-4
Browse files
app.py
CHANGED
|
@@ -286,6 +286,14 @@ def update_gallery_color(raw_list_state, color_name):
|
|
| 286 |
bar_img = generate_colorbar_preview(color_name)
|
| 287 |
return new_gallery, bar_img
|
| 288 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
# --- Generation Functions ---
|
| 290 |
@spaces.GPU(duration=120)
|
| 291 |
def generate_t2i(prompt, num_inference_steps, current_color):
|
|
@@ -514,7 +522,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 514 |
inputs=[t2i_raw_state, t2i_color],
|
| 515 |
outputs=[t2i_out, t2i_colorbar]
|
| 516 |
)
|
| 517 |
-
|
|
|
|
| 518 |
|
| 519 |
# --- TAB 2: Super-Resolution ---
|
| 520 |
with gr.Tab("Super-Resolution", id="super_res"):
|
|
@@ -544,7 +553,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 544 |
sr_model.change(update_sr_prompt, sr_model, sr_prompt)
|
| 545 |
sr_btn.click(run_super_resolution, [sr_file, sr_model, sr_prompt, sr_steps, sr_seed, sr_color], [sr_in_disp, sr_out_disp, sr_dl, sr_raw_state, sr_colorbar])
|
| 546 |
sr_color.change(update_single_image_color, [sr_raw_state, sr_color], [sr_out_disp, sr_colorbar])
|
| 547 |
-
|
|
|
|
| 548 |
|
| 549 |
# --- TAB 3: Denoising ---
|
| 550 |
with gr.Tab("Denoising", id="denoising"):
|
|
@@ -572,7 +582,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 572 |
|
| 573 |
dn_btn.click(run_denoising, [dn_img, dn_type, dn_steps, dn_seed, dn_color], [dn_orig, dn_out, dn_dl, dn_raw_state, dn_colorbar])
|
| 574 |
dn_color.change(update_single_image_color, [dn_raw_state, dn_color], [dn_out, dn_colorbar])
|
| 575 |
-
|
|
|
|
| 576 |
|
| 577 |
# --- TAB 4: Mask-to-Image ---
|
| 578 |
with gr.Tab("Mask-to-Image", id="mask2img"):
|
|
@@ -600,7 +611,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 600 |
|
| 601 |
m2i_btn.click(run_mask_to_image_generation, [m2i_file, m2i_type, m2i_num, m2i_steps, m2i_seed, m2i_color], [m2i_in_disp, m2i_gal_out, m2i_dl, m2i_raw_state, m2i_colorbar])
|
| 602 |
m2i_color.change(update_gallery_color, [m2i_raw_state, m2i_color], [m2i_gal_out, m2i_colorbar])
|
| 603 |
-
|
|
|
|
| 604 |
|
| 605 |
# --- TAB 5: Cell Segmentation ---
|
| 606 |
with gr.Tab("Cell Segmentation", id="segmentation"):
|
|
@@ -618,7 +630,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 618 |
seg_out = gr.Image(label="Overlay", type="pil", interactive=False, show_download_button=False)
|
| 619 |
seg_gal = gr.Gallery(value=seg_examples, label="Examples", columns=6, height="auto")
|
| 620 |
seg_btn.click(run_segmentation, [seg_img, seg_model, seg_diam, seg_flow, seg_prob], [seg_orig, seg_out])
|
| 621 |
-
|
|
|
|
| 622 |
|
| 623 |
# --- TAB 6: Classification ---
|
| 624 |
with gr.Tab("Classification", id="classification"):
|
|
@@ -632,7 +645,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 632 |
cls_res = gr.Label(label="Results", num_top_classes=10)
|
| 633 |
cls_gal = gr.Gallery(value=cls_examples, label="Examples", columns=6, height="auto")
|
| 634 |
cls_btn.click(run_classification, [cls_img, cls_model], [cls_orig, cls_res])
|
| 635 |
-
|
|
|
|
| 636 |
|
| 637 |
if __name__ == "__main__":
|
| 638 |
demo.launch()
|
|
|
|
| 286 |
bar_img = generate_colorbar_preview(color_name)
|
| 287 |
return new_gallery, bar_img
|
| 288 |
|
| 289 |
+
# --- Event Handler Helper (Fix for Lambda Issue) ---
|
| 290 |
+
def get_gallery_selection(evt: gr.SelectData):
|
| 291 |
+
"""
|
| 292 |
+
Standard event handler for gallery selection.
|
| 293 |
+
Returns the caption (which stores the filepath/prompt) from the selected item.
|
| 294 |
+
"""
|
| 295 |
+
return evt.value['caption']
|
| 296 |
+
|
| 297 |
# --- Generation Functions ---
|
| 298 |
@spaces.GPU(duration=120)
|
| 299 |
def generate_t2i(prompt, num_inference_steps, current_color):
|
|
|
|
| 522 |
inputs=[t2i_raw_state, t2i_color],
|
| 523 |
outputs=[t2i_out, t2i_colorbar]
|
| 524 |
)
|
| 525 |
+
# FIXED: Use defined function instead of lambda
|
| 526 |
+
t2i_gal.select(fn=get_gallery_selection, inputs=None, outputs=t2i_prompt)
|
| 527 |
|
| 528 |
# --- TAB 2: Super-Resolution ---
|
| 529 |
with gr.Tab("Super-Resolution", id="super_res"):
|
|
|
|
| 553 |
sr_model.change(update_sr_prompt, sr_model, sr_prompt)
|
| 554 |
sr_btn.click(run_super_resolution, [sr_file, sr_model, sr_prompt, sr_steps, sr_seed, sr_color], [sr_in_disp, sr_out_disp, sr_dl, sr_raw_state, sr_colorbar])
|
| 555 |
sr_color.change(update_single_image_color, [sr_raw_state, sr_color], [sr_out_disp, sr_colorbar])
|
| 556 |
+
# FIXED: Use defined function instead of lambda
|
| 557 |
+
sr_gal.select(fn=get_gallery_selection, inputs=None, outputs=sr_file)
|
| 558 |
|
| 559 |
# --- TAB 3: Denoising ---
|
| 560 |
with gr.Tab("Denoising", id="denoising"):
|
|
|
|
| 582 |
|
| 583 |
dn_btn.click(run_denoising, [dn_img, dn_type, dn_steps, dn_seed, dn_color], [dn_orig, dn_out, dn_dl, dn_raw_state, dn_colorbar])
|
| 584 |
dn_color.change(update_single_image_color, [dn_raw_state, dn_color], [dn_out, dn_colorbar])
|
| 585 |
+
# FIXED: Use defined function instead of lambda
|
| 586 |
+
dn_gal.select(fn=get_gallery_selection, inputs=None, outputs=dn_img)
|
| 587 |
|
| 588 |
# --- TAB 4: Mask-to-Image ---
|
| 589 |
with gr.Tab("Mask-to-Image", id="mask2img"):
|
|
|
|
| 611 |
|
| 612 |
m2i_btn.click(run_mask_to_image_generation, [m2i_file, m2i_type, m2i_num, m2i_steps, m2i_seed, m2i_color], [m2i_in_disp, m2i_gal_out, m2i_dl, m2i_raw_state, m2i_colorbar])
|
| 613 |
m2i_color.change(update_gallery_color, [m2i_raw_state, m2i_color], [m2i_gal_out, m2i_colorbar])
|
| 614 |
+
# FIXED: Use defined function instead of lambda
|
| 615 |
+
m2i_gal.select(fn=get_gallery_selection, inputs=None, outputs=m2i_file)
|
| 616 |
|
| 617 |
# --- TAB 5: Cell Segmentation ---
|
| 618 |
with gr.Tab("Cell Segmentation", id="segmentation"):
|
|
|
|
| 630 |
seg_out = gr.Image(label="Overlay", type="pil", interactive=False, show_download_button=False)
|
| 631 |
seg_gal = gr.Gallery(value=seg_examples, label="Examples", columns=6, height="auto")
|
| 632 |
seg_btn.click(run_segmentation, [seg_img, seg_model, seg_diam, seg_flow, seg_prob], [seg_orig, seg_out])
|
| 633 |
+
# FIXED: Use defined function instead of lambda
|
| 634 |
+
seg_gal.select(fn=get_gallery_selection, inputs=None, outputs=seg_img)
|
| 635 |
|
| 636 |
# --- TAB 6: Classification ---
|
| 637 |
with gr.Tab("Classification", id="classification"):
|
|
|
|
| 645 |
cls_res = gr.Label(label="Results", num_top_classes=10)
|
| 646 |
cls_gal = gr.Gallery(value=cls_examples, label="Examples", columns=6, height="auto")
|
| 647 |
cls_btn.click(run_classification, [cls_img, cls_model], [cls_orig, cls_res])
|
| 648 |
+
# FIXED: Use defined function instead of lambda
|
| 649 |
+
cls_gal.select(fn=get_gallery_selection, inputs=None, outputs=cls_img)
|
| 650 |
|
| 651 |
if __name__ == "__main__":
|
| 652 |
demo.launch()
|