Update app.py
Browse files
app.py
CHANGED
|
@@ -128,12 +128,14 @@ def cellpose_segment(img_input):
|
|
| 128 |
crand = .2 + .8 * np.random.rand(np.max(masks.flatten()).astype('int')+1,).astype('float32')
|
| 129 |
crand[0] = 0
|
| 130 |
|
| 131 |
-
overlay = Image.fromarray(overlay)
|
| 132 |
-
flows = Image.fromarray(flows)
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
| 135 |
|
| 136 |
-
return outpix, overlay, flows, masks
|
| 137 |
|
| 138 |
# Gradio Interface
|
| 139 |
#iface = gr.Interface(
|
|
@@ -144,6 +146,9 @@ def cellpose_segment(img_input):
|
|
| 144 |
# description="upload an image, then cellpose will segment it at a max size of 400x400 (for full functionality, 'pip install cellpose' locally)"
|
| 145 |
#)
|
| 146 |
|
|
|
|
|
|
|
|
|
|
| 147 |
with gr.Blocks(title = "Hello",
|
| 148 |
css=".gradio-container {background:purple;}") as demo:
|
| 149 |
|
|
@@ -151,16 +156,18 @@ with gr.Blocks(title = "Hello",
|
|
| 151 |
with gr.Column(scale=1):
|
| 152 |
input_image = gr.Image(label = "Input image", type = "numpy")
|
| 153 |
send_btn = gr.Button("Run Cellpose-SAM")
|
|
|
|
| 154 |
|
| 155 |
with gr.Column(scale=1):
|
| 156 |
img_outlines = gr.Image(label = "Output image", type = "pil")
|
| 157 |
-
img_overlay = gr.Image(label = "Output image", type = "
|
| 158 |
-
flows = gr.Image(label = "Output image", type = "
|
| 159 |
-
masks = gr.Image(label = "Output image", type = "
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
send_btn.click(fn=cellpose_segment, inputs=[input_image], outputs=[img_outlines, img_overlay, flows, masks])
|
| 163 |
|
|
|
|
| 164 |
|
| 165 |
|
| 166 |
|
|
|
|
| 128 |
crand = .2 + .8 * np.random.rand(np.max(masks.flatten()).astype('int')+1,).astype('float32')
|
| 129 |
crand[0] = 0
|
| 130 |
|
| 131 |
+
#overlay = Image.fromarray(overlay)
|
| 132 |
+
#flows = Image.fromarray(flows)
|
| 133 |
+
#masks = Image.fromarray(255. * crand[masks])
|
| 134 |
+
|
| 135 |
+
pil_masks = Image.fromarray(masks.astype('int32'))
|
| 136 |
+
pil_masks.save("test.png")
|
| 137 |
|
| 138 |
+
return outpix, overlay, flows, masks, gr.DownloadButton(visible=True, value = "test.png")
|
| 139 |
|
| 140 |
# Gradio Interface
|
| 141 |
#iface = gr.Interface(
|
|
|
|
| 146 |
# description="upload an image, then cellpose will segment it at a max size of 400x400 (for full functionality, 'pip install cellpose' locally)"
|
| 147 |
#)
|
| 148 |
|
| 149 |
+
def download_file():
|
| 150 |
+
return gr.DownloadButton(v"Download segmentations", visible=False)
|
| 151 |
+
|
| 152 |
with gr.Blocks(title = "Hello",
|
| 153 |
css=".gradio-container {background:purple;}") as demo:
|
| 154 |
|
|
|
|
| 156 |
with gr.Column(scale=1):
|
| 157 |
input_image = gr.Image(label = "Input image", type = "numpy")
|
| 158 |
send_btn = gr.Button("Run Cellpose-SAM")
|
| 159 |
+
down_btn = gr.DownloadButton("Download segmentations", visible=False)
|
| 160 |
|
| 161 |
with gr.Column(scale=1):
|
| 162 |
img_outlines = gr.Image(label = "Output image", type = "pil")
|
| 163 |
+
img_overlay = gr.Image(label = "Output image", type = "numpy")
|
| 164 |
+
flows = gr.Image(label = "Output image", type = "numpy")
|
| 165 |
+
masks = gr.Image(label = "Output image", type = "numpy")
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
send_btn.click(fn=cellpose_segment, inputs=[input_image], outputs=[img_outlines, img_overlay, flows, masks, down_btn])
|
| 169 |
|
| 170 |
+
down_btn.click(download_file, None, down_btn)
|
| 171 |
|
| 172 |
|
| 173 |
|