Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -8,13 +8,12 @@ def analyze_image(image, min_size, circularity, do_necrosis=True):
|
|
| 8 |
return Image.fromarray(processed_img), picname, excelname
|
| 9 |
|
| 10 |
# Z-stack analysis function (adapt with your own logic)
|
| 11 |
-
def analyze_zstack(images, min_size, circularity, do_necrosis=True):
|
| 12 |
-
# images: list of PIL images
|
| 13 |
-
# Plug in your own z-stack segmentation logic here
|
| 14 |
-
# Example stub: pass images as a list to your analyzer
|
| 15 |
import Organoid_Analyzer_AI_zstack2_HF as analyzer
|
| 16 |
images = [Image.open(f.name) for f in images]
|
| 17 |
-
processed_img, picname, excelname = analyzer.main(
|
|
|
|
|
|
|
| 18 |
return Image.fromarray(processed_img), picname, excelname
|
| 19 |
|
| 20 |
with gr.Blocks() as demo:
|
|
@@ -26,6 +25,8 @@ with gr.Blocks() as demo:
|
|
| 26 |
image_input_multi = gr.File(file_count="multiple", type="filepath", label="Upload Z-Stack Images", visible=False)
|
| 27 |
min_size_input = gr.Number(label="Minimum Organoid Size (pixels)", value=1000)
|
| 28 |
circularity_input = gr.Number(label="Minimum Circularity", value=0.25)
|
|
|
|
|
|
|
| 29 |
output_image = gr.Image(type="pil", label="Analyzed Image")
|
| 30 |
output_file_img = gr.File(label="Download Image")
|
| 31 |
output_file_excel = gr.File(label="Download results (Excel)")
|
|
@@ -34,25 +35,38 @@ with gr.Blocks() as demo:
|
|
| 34 |
def toggle_inputs(z_stack_enabled):
|
| 35 |
return (
|
| 36 |
gr.update(visible=not z_stack_enabled), # single input
|
| 37 |
-
gr.update(visible=z_stack_enabled)
|
|
|
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
z_stack_checkbox.change(
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
def conditional_analyze(z_stack, single_image, multi_images, min_size, circularity, do_necrosis
|
| 47 |
if z_stack:
|
| 48 |
-
return analyze_zstack(multi_images, min_size, circularity,do_necrosis)
|
| 49 |
else:
|
| 50 |
-
return analyze_image(single_image, min_size, circularity,do_necrosis)
|
| 51 |
|
| 52 |
process_btn.click(
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
demo.launch()
|
|
|
|
| 8 |
return Image.fromarray(processed_img), picname, excelname
|
| 9 |
|
| 10 |
# Z-stack analysis function (adapt with your own logic)
|
| 11 |
+
def analyze_zstack(images, min_size, circularity, distance_cutoff=30, overlap_cutoff=0.4, do_necrosis=True):
|
|
|
|
|
|
|
|
|
|
| 12 |
import Organoid_Analyzer_AI_zstack2_HF as analyzer
|
| 13 |
images = [Image.open(f.name) for f in images]
|
| 14 |
+
processed_img, picname, excelname = analyzer.main(
|
| 15 |
+
[images, min_size, circularity, distance_cutoff, overlap_cutoff, do_necrosis]
|
| 16 |
+
)
|
| 17 |
return Image.fromarray(processed_img), picname, excelname
|
| 18 |
|
| 19 |
with gr.Blocks() as demo:
|
|
|
|
| 25 |
image_input_multi = gr.File(file_count="multiple", type="filepath", label="Upload Z-Stack Images", visible=False)
|
| 26 |
min_size_input = gr.Number(label="Minimum Organoid Size (pixels)", value=1000)
|
| 27 |
circularity_input = gr.Number(label="Minimum Circularity", value=0.25)
|
| 28 |
+
zstack_distance_cutoff_input = gr.Number(label="Z-Stack Centroid Distance Cutoff (pixels)", value=30, visible=False)
|
| 29 |
+
zstack_overlap_cutoff_input = gr.Number(label="Z-Stack Colony Overlap Cutoff", value=0.4, visible=False)
|
| 30 |
output_image = gr.Image(type="pil", label="Analyzed Image")
|
| 31 |
output_file_img = gr.File(label="Download Image")
|
| 32 |
output_file_excel = gr.File(label="Download results (Excel)")
|
|
|
|
| 35 |
def toggle_inputs(z_stack_enabled):
|
| 36 |
return (
|
| 37 |
gr.update(visible=not z_stack_enabled), # single input
|
| 38 |
+
gr.update(visible=z_stack_enabled), # multi input
|
| 39 |
+
gr.update(visible=z_stack_enabled), # zstack_distance_cutoff_input
|
| 40 |
+
gr.update(visible=z_stack_enabled) # zstack_overlap_cutoff_input
|
| 41 |
)
|
| 42 |
|
| 43 |
z_stack_checkbox.change(
|
| 44 |
+
toggle_inputs,
|
| 45 |
+
inputs=z_stack_checkbox,
|
| 46 |
+
outputs=[
|
| 47 |
+
image_input_single,
|
| 48 |
+
image_input_multi,
|
| 49 |
+
zstack_distance_cutoff_input,
|
| 50 |
+
zstack_overlap_cutoff_input])
|
| 51 |
|
| 52 |
+
def conditional_analyze(z_stack, single_image, multi_images, min_size, circularity, do_necrosis, distance_cutoff, overlap_cutoff):
|
| 53 |
if z_stack:
|
| 54 |
+
return analyze_zstack(multi_images, min_size, circularity, distance_cutoff, overlap_cutoff, do_necrosis)
|
| 55 |
else:
|
| 56 |
+
return analyze_image(single_image, min_size, circularity, do_necrosis)
|
| 57 |
|
| 58 |
process_btn.click(
|
| 59 |
+
conditional_analyze,
|
| 60 |
+
inputs=[
|
| 61 |
+
z_stack_checkbox,
|
| 62 |
+
image_input_single,
|
| 63 |
+
image_input_multi,
|
| 64 |
+
min_size_input,
|
| 65 |
+
circularity_input,
|
| 66 |
+
do_necrosis_checkbox,
|
| 67 |
+
zstack_distance_cutoff_input,
|
| 68 |
+
zstack_overlap_cutoff_input
|
| 69 |
+
],
|
| 70 |
+
outputs=[output_image, output_file_img, output_file_excel])
|
| 71 |
|
| 72 |
demo.launch()
|