mouseland commited on
Commit
f62e231
·
verified ·
1 Parent(s): f672193

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -26
app.py CHANGED
@@ -11,7 +11,7 @@ from cellpose.io import imread, imsave
11
 
12
  from huggingface_hub import hf_hub_download
13
 
14
- img = np.zeros((384, 512))
15
  fp0 = "0.png"
16
  imsave(fp0, img)
17
 
@@ -167,6 +167,7 @@ def run_model_gpu1000(img):
167
  masks, flows, _ = model.eval(img)#, channels = [0,0])
168
  return masks, flows
169
 
 
170
  from zipfile import ZipFile
171
  def cellpose_segment(filepath, resize = 1000):
172
 
@@ -249,31 +250,22 @@ def download_function():
249
  b2 = gr.DownloadButton("Download outline image as PNG", visible=False)
250
  return b1, b2
251
 
 
 
 
 
 
 
 
 
252
  def update_image(filepath):
253
- #img = imread(filepath)
254
- #img = normalize99(img)
255
- #img = np.clip(img, 0, 1)
256
-
257
- #filegui = os.path.splitext(filepath)[0]+"_gui.png"
258
- #imsave(filegui, img)
259
-
260
- #b1 = gr.DownloadButton("Download masks as TIFF", visible=False)
261
- #b2 = gr.DownloadButton("Download outline image as PNG", visible=False)
262
- for f in filepath:
263
- print(f)
264
-
265
- return filepath[-1], fp0, fp0
266
-
267
-
268
- def update_button(filepath):
269
- #img = imread(filepath)
270
- #img = normalize99(img)
271
- #img = np.clip(img, 0, 1)
272
-
273
- #b1 = gr.DownloadButton("Download masks as TIFF", visible=False)
274
- #b2 = gr.DownloadButton("Download outline image as PNG", visible=False)
275
 
276
- return [filepath], fp0, fp0
 
 
277
 
278
  with gr.Blocks(title = "Hello",
279
  css=".gradio-container {background:purple;}") as demo:
@@ -312,8 +304,8 @@ with gr.Blocks(title = "Hello",
312
  sample_list.append("samples/img%0.2d.png"%j)
313
  gr.Examples(sample_list, fn = update_button, inputs=input_image, outputs = [up_btn, outlines, flows], examples_per_page=25, label = "Click on an example to try it")
314
 
315
- input_image.upload(update_button, input_image, [up_btn, outlines, flows])
316
- up_btn.upload(update_image, up_btn, [input_image, outlines, flows])
317
  send_btn.click(cellpose_segment, [up_btn, resize], [outlines, flows, down_btn, down_btn2])
318
 
319
  #down_btn.click(download_function, None, [down_btn, down_btn2])
 
11
 
12
  from huggingface_hub import hf_hub_download
13
 
14
+ img = np.zeros((96, 128))
15
  fp0 = "0.png"
16
  imsave(fp0, img)
17
 
 
167
  masks, flows, _ = model.eval(img)#, channels = [0,0])
168
  return masks, flows
169
 
170
+
171
  from zipfile import ZipFile
172
  def cellpose_segment(filepath, resize = 1000):
173
 
 
250
  b2 = gr.DownloadButton("Download outline image as PNG", visible=False)
251
  return b1, b2
252
 
253
+ def tif_view(filepath):
254
+ fpath, fext = os.path.splitext(filepath)
255
+ if fext in ['tiff', 'tif']:
256
+ img = imread(filepath[-1])
257
+ filepath = fpath+'.png'
258
+ imsave(filepath, img)
259
+ return filepath
260
+
261
  def update_image(filepath):
262
+ for f in filepath:
263
+ f = tif_view(f)
264
+ return filepath, filepath[-1], fp0, fp0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
 
266
+ def update_button(filepath):
267
+ filepath = tif_view(filepath)
268
+ return filepath, [filepath], fp0, fp0
269
 
270
  with gr.Blocks(title = "Hello",
271
  css=".gradio-container {background:purple;}") as demo:
 
304
  sample_list.append("samples/img%0.2d.png"%j)
305
  gr.Examples(sample_list, fn = update_button, inputs=input_image, outputs = [up_btn, outlines, flows], examples_per_page=25, label = "Click on an example to try it")
306
 
307
+ input_image.upload(update_button, input_image, [up_btn, input_image, outlines, flows])
308
+ up_btn.upload(update_image, up_btn, [up_btn, input_image, outlines, flows])
309
  send_btn.click(cellpose_segment, [up_btn, resize], [outlines, flows, down_btn, down_btn2])
310
 
311
  #down_btn.click(download_function, None, [down_btn, down_btn2])