Update app.py
Browse files
app.py
CHANGED
|
@@ -98,10 +98,6 @@ def image_resize(img, resize=400):
|
|
| 98 |
img = img.astype(np.uint8)
|
| 99 |
return img
|
| 100 |
|
| 101 |
-
|
| 102 |
-
def plot_masks(masks):
|
| 103 |
-
|
| 104 |
-
return RGB
|
| 105 |
|
| 106 |
#@spaces.GPU(duration=10)
|
| 107 |
#def run_model_gpu(model, img):
|
|
@@ -132,10 +128,16 @@ def cellpose_segment(img_input):
|
|
| 132 |
#flows = Image.fromarray(flows)
|
| 133 |
#masks = Image.fromarray(255. * crand[masks])
|
| 134 |
|
| 135 |
-
pil_masks = Image.fromarray(
|
| 136 |
-
pil_masks.save("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
-
return outpix, overlay, flows,
|
| 139 |
|
| 140 |
# Gradio Interface
|
| 141 |
#iface = gr.Interface(
|
|
@@ -146,9 +148,7 @@ def cellpose_segment(img_input):
|
|
| 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 |
-
|
| 150 |
-
return gr.DownloadButton("Download segmentations", visible=False)
|
| 151 |
-
|
| 152 |
with gr.Blocks(title = "Hello",
|
| 153 |
css=".gradio-container {background:purple;}") as demo:
|
| 154 |
|
|
@@ -156,7 +156,8 @@ with gr.Blocks(title = "Hello",
|
|
| 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
|
|
|
|
| 160 |
|
| 161 |
with gr.Column(scale=1):
|
| 162 |
img_outlines = gr.Image(label = "Output image", type = "pil")
|
|
@@ -165,9 +166,9 @@ with gr.Blocks(title = "Hello",
|
|
| 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, down_btn])
|
| 169 |
|
| 170 |
-
down_btn.click(
|
| 171 |
|
| 172 |
|
| 173 |
|
|
|
|
| 98 |
img = img.astype(np.uint8)
|
| 99 |
return img
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
#@spaces.GPU(duration=10)
|
| 103 |
#def run_model_gpu(model, img):
|
|
|
|
| 128 |
#flows = Image.fromarray(flows)
|
| 129 |
#masks = Image.fromarray(255. * crand[masks])
|
| 130 |
|
| 131 |
+
pil_masks = Image.fromarray(masks.astype('int32'))
|
| 132 |
+
pil_masks.save("masks.tiff")
|
| 133 |
+
|
| 134 |
+
pil_outpix = Image.fromarray(outpix)
|
| 135 |
+
pil_outpix.save("outlines.png")
|
| 136 |
+
|
| 137 |
+
b1 = gr.DownloadButton(visible=True, value = "masks.tiff")
|
| 138 |
+
b2 = gr.DownloadButton(visible=True, value = "outlines.png")
|
| 139 |
|
| 140 |
+
return outpix, overlay, flows, b1, b2
|
| 141 |
|
| 142 |
# Gradio Interface
|
| 143 |
#iface = gr.Interface(
|
|
|
|
| 148 |
# description="upload an image, then cellpose will segment it at a max size of 400x400 (for full functionality, 'pip install cellpose' locally)"
|
| 149 |
#)
|
| 150 |
|
| 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 masks as TIFF", visible=False)
|
| 160 |
+
down_btn2 = gr.DownloadButton("Download outline image as PNG", visible=False)
|
| 161 |
|
| 162 |
with gr.Column(scale=1):
|
| 163 |
img_outlines = gr.Image(label = "Output image", type = "pil")
|
|
|
|
| 166 |
#masks = gr.Image(label = "Output image", type = "numpy")
|
| 167 |
|
| 168 |
|
| 169 |
+
send_btn.click(fn=cellpose_segment, inputs=[input_image], outputs=[img_outlines, img_overlay, flows, down_btn, down_btn2])
|
| 170 |
|
| 171 |
+
down_btn.click(None, None, None)
|
| 172 |
|
| 173 |
|
| 174 |
|