mouseland commited on
Commit
7a96d4b
·
verified ·
1 Parent(s): 47ad03f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -152,23 +152,23 @@ def image_resize(img, resize=400):
152
 
153
 
154
  @spaces.GPU(duration=10)
155
- def run_model_gpu(img, max_iter):
156
- masks, flows, _ = model.eval(img, niter = max_iter)#, channels = [0,0])
157
  return masks, flows
158
 
159
  @spaces.GPU(duration=60)
160
- def run_model_gpu60(img, max_iter):
161
- masks, flows, _ = model.eval(img, niter = max_iter)#, channels = [0,0])
162
  return masks, flows
163
 
164
  @spaces.GPU(duration=240)
165
- def run_model_gpu240(img, max_iter):
166
- masks, flows, _ = model.eval(img, niter = max_iter)#, channels = [0,0])
167
  return masks, flows
168
 
169
  import datetime
170
  from zipfile import ZipFile
171
- def cellpose_segment(filepath, resize = 1000,max_iter = 250):
172
 
173
  zip_path = os.path.splitext(filepath[-1])[0]+"_masks.zip"
174
  #zip_path = 'masks.zip'
@@ -183,11 +183,11 @@ def cellpose_segment(filepath, resize = 1000,max_iter = 250):
183
 
184
  maxsize = np.max(img.shape)
185
  if maxsize<=1000:
186
- masks, flows = run_model_gpu(img, max_iter)
187
  elif maxsize < 5000:
188
- masks, flows = run_model_gpu60(img, max_iter)
189
  elif maxsize < 20000:
190
- masks, flows = run_model_gpu240(img, max_iter)
191
  else:
192
  raise ValueError("Image size must be less than 20,000")
193
 
@@ -310,6 +310,8 @@ with gr.Blocks(title = "Hello",
310
  with gr.Row():
311
  resize = gr.Number(label = 'max resize', value = 1000)
312
  max_iter = gr.Number(label = 'max iterations', value = 250)
 
 
313
 
314
  up_btn = gr.UploadButton("Multi-file upload (png, jpg, tif etc)", visible=True, file_count = "multiple")
315
 
@@ -336,7 +338,7 @@ with gr.Blocks(title = "Hello",
336
  input_image.upload(update_button, input_image, [input_image, up_btn, outlines, flows])
337
  up_btn.upload(update_image, up_btn, [input_image, up_btn, outlines, flows])
338
 
339
- send_btn.click(cellpose_segment, [up_btn, resize, max_iter], [outlines, flows, down_btn, down_btn2])
340
 
341
  #down_btn.click(download_function, None, [down_btn, down_btn2])
342
 
 
152
 
153
 
154
  @spaces.GPU(duration=10)
155
+ def run_model_gpu(img, max_iter, flow_threshold, cellprob_threshold):
156
+ masks, flows, _ = model.eval(img, niter = max_iter, flow_threshold = flow_threshold, cellprob_threshold = cellprob_threshold)
157
  return masks, flows
158
 
159
  @spaces.GPU(duration=60)
160
+ def run_model_gpu60(img, max_iter, flow_threshold, cellprob_threshold):
161
+ masks, flows, _ = model.eval(img, niter = max_iter, flow_threshold = flow_threshold, cellprob_threshold = cellprob_threshold)
162
  return masks, flows
163
 
164
  @spaces.GPU(duration=240)
165
+ def run_model_gpu240(img, max_iter, flow_threshold, cellprob_threshold):
166
+ masks, flows, _ = model.eval(img, niter = max_iter, flow_threshold = flow_threshold, cellprob_threshold = cellprob_threshold)
167
  return masks, flows
168
 
169
  import datetime
170
  from zipfile import ZipFile
171
+ def cellpose_segment(filepath, resize = 1000,max_iter = 250, flow_threshold= 0.4, cellprob_threshold = 0):
172
 
173
  zip_path = os.path.splitext(filepath[-1])[0]+"_masks.zip"
174
  #zip_path = 'masks.zip'
 
183
 
184
  maxsize = np.max(img.shape)
185
  if maxsize<=1000:
186
+ masks, flows = run_model_gpu(img, max_iter, flow_threshold, cellprob_threshold)
187
  elif maxsize < 5000:
188
+ masks, flows = run_model_gpu60(img, max_iter, flow_threshold, cellprob_threshold)
189
  elif maxsize < 20000:
190
+ masks, flows = run_model_gpu240(img, max_iter, flow_threshold, cellprob_threshold)
191
  else:
192
  raise ValueError("Image size must be less than 20,000")
193
 
 
310
  with gr.Row():
311
  resize = gr.Number(label = 'max resize', value = 1000)
312
  max_iter = gr.Number(label = 'max iterations', value = 250)
313
+ flow_threshold = gr.Number(label = 'flow threshold', value = 0.4)
314
+ cellprob_threshold = gr.Number(label = 'cellprob threshold', value = 0)
315
 
316
  up_btn = gr.UploadButton("Multi-file upload (png, jpg, tif etc)", visible=True, file_count = "multiple")
317
 
 
338
  input_image.upload(update_button, input_image, [input_image, up_btn, outlines, flows])
339
  up_btn.upload(update_image, up_btn, [input_image, up_btn, outlines, flows])
340
 
341
+ send_btn.click(cellpose_segment, [up_btn, resize, max_iter, flow_threshold, cellprob_threshold], [outlines, flows, down_btn, down_btn2])
342
 
343
  #down_btn.click(download_function, None, [down_btn, down_btn2])
344