Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,10 @@ sam = sam_model_registry[model_type](checkpoint="./tinysam/tinysam.pth")
|
|
14 |
predictor = SamPredictor(sam)
|
15 |
|
16 |
def infer(img):
|
|
|
|
|
|
|
|
|
17 |
# background (original image) layers[0] ( point prompt) composite (total image)
|
18 |
image = img["background"].convert("RGB")
|
19 |
point_prompt = img["layers"][0]
|
@@ -23,6 +27,8 @@ def infer(img):
|
|
23 |
# get point prompt
|
24 |
img_arr = np.array(point_prompt)
|
25 |
nonzero_indices = np.nonzero(img_arr)
|
|
|
|
|
26 |
center_x = int(np.mean(nonzero_indices[1]))
|
27 |
center_y = int(np.mean(nonzero_indices[0]))
|
28 |
input_point = np.array([[center_x, center_y]])
|
|
|
14 |
predictor = SamPredictor(sam)
|
15 |
|
16 |
def infer(img):
|
17 |
+
if img is None:
|
18 |
+
gr.Error("Please upload an image and select a point.")
|
19 |
+
if img["background"] is None:
|
20 |
+
gr.Error("Please upload an image and select a point.")
|
21 |
# background (original image) layers[0] ( point prompt) composite (total image)
|
22 |
image = img["background"].convert("RGB")
|
23 |
point_prompt = img["layers"][0]
|
|
|
27 |
# get point prompt
|
28 |
img_arr = np.array(point_prompt)
|
29 |
nonzero_indices = np.nonzero(img_arr)
|
30 |
+
if nonzero_indices is None:
|
31 |
+
gr.Error("Please select a point.")
|
32 |
center_x = int(np.mean(nonzero_indices[1]))
|
33 |
center_y = int(np.mean(nonzero_indices[0]))
|
34 |
input_point = np.array([[center_x, center_y]])
|