TouseefAhmad commited on
Commit
8b9e08d
·
verified ·
1 Parent(s): 5559754

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -8,15 +8,25 @@ from skimage.measure import regionprops
8
  from skimage.segmentation import clear_border
9
  from cellpose import models
10
 
11
- # Load Cellpose model
12
- model = models.Cellpose(gpu=False, model_type="cyto")
 
 
 
 
 
13
 
14
  def process_image(image):
15
  # Convert to numpy array and make grayscale
16
  image_np = np.array(image.convert("L"))
17
 
18
- # Run Cellpose prediction
19
- masks, flows, styles = model.eval(image_np, diameter=None, channels=[0,0])
 
 
 
 
 
20
 
21
  # Clean up borders and small artifacts
22
  masks_cleaned = clear_border(masks)
 
8
  from skimage.segmentation import clear_border
9
  from cellpose import models
10
 
11
+ # Load Cellpose model - updated for v4.0.6
12
+ try:
13
+ # Try the new API first
14
+ model = models.CellposeModel(gpu=False, model_type="cyto")
15
+ except AttributeError:
16
+ # Fall back to older API if needed
17
+ model = models.Cellpose(gpu=False, model_type="cyto")
18
 
19
  def process_image(image):
20
  # Convert to numpy array and make grayscale
21
  image_np = np.array(image.convert("L"))
22
 
23
+ try:
24
+ # Try new API call format
25
+ masks, flows, styles = model.eval(image_np, diameter=None, channels=[0,0])
26
+ except TypeError:
27
+ # Fall back to older API format
28
+ masks, flows, styles, diams = model.eval([image_np], diameter=None, channels=[0,0])
29
+ masks = masks[0]
30
 
31
  # Clean up borders and small artifacts
32
  masks_cleaned = clear_border(masks)