Update app.py
Browse files
app.py
CHANGED
|
@@ -8,12 +8,38 @@ import matplotlib.pyplot as plt
|
|
| 8 |
import os, io, base64
|
| 9 |
from PIL import Image
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
try:
|
| 12 |
-
|
|
|
|
| 13 |
except Exception as e:
|
| 14 |
print(f"Error loading model: {e}")
|
| 15 |
exit(1)
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
def plot_flows(y):
|
| 18 |
Y = (np.clip(normalize99(y[0][0]),0,1) - 0.5) * 2
|
| 19 |
X = (np.clip(normalize99(y[1][0]),0,1) - 0.5) * 2
|
|
@@ -101,7 +127,7 @@ def image_resize(img, resize=400):
|
|
| 101 |
|
| 102 |
@spaces.GPU(duration=10)
|
| 103 |
def run_model_gpu(img):
|
| 104 |
-
masks, flows, _ = model.eval(img
|
| 105 |
return masks, flows
|
| 106 |
|
| 107 |
#@spaces.GPU(duration=10)
|
|
|
|
| 8 |
import os, io, base64
|
| 9 |
from PIL import Image
|
| 10 |
|
| 11 |
+
|
| 12 |
+
# @title Data retrieval
|
| 13 |
+
def download_weights():
|
| 14 |
+
import os, requests
|
| 15 |
+
|
| 16 |
+
fname = 'cpsam'
|
| 17 |
+
|
| 18 |
+
url = ["https://osf.io/d7c8e/download"]
|
| 19 |
+
|
| 20 |
+
for j in range(len(url)):
|
| 21 |
+
if not os.path.isfile(fname[j]):
|
| 22 |
+
try:
|
| 23 |
+
r = requests.get(url[j])
|
| 24 |
+
except requests.ConnectionError:
|
| 25 |
+
print("!!! Failed to download data !!!")
|
| 26 |
+
else:
|
| 27 |
+
if r.status_code != requests.codes.ok:
|
| 28 |
+
print("!!! Failed to download data !!!")
|
| 29 |
+
else:
|
| 30 |
+
with open(fname[j], "wb") as fid:
|
| 31 |
+
fid.write(r.content)
|
| 32 |
+
|
| 33 |
try:
|
| 34 |
+
download_weights()
|
| 35 |
+
model = models.CellposeModel(gpu=True, pretrained_model="cpsam")
|
| 36 |
except Exception as e:
|
| 37 |
print(f"Error loading model: {e}")
|
| 38 |
exit(1)
|
| 39 |
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
def plot_flows(y):
|
| 44 |
Y = (np.clip(normalize99(y[0][0]),0,1) - 0.5) * 2
|
| 45 |
X = (np.clip(normalize99(y[1][0]),0,1) - 0.5) * 2
|
|
|
|
| 127 |
|
| 128 |
@spaces.GPU(duration=10)
|
| 129 |
def run_model_gpu(img):
|
| 130 |
+
masks, flows, _ = model.eval(img)
|
| 131 |
return masks, flows
|
| 132 |
|
| 133 |
#@spaces.GPU(duration=10)
|