Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -26,22 +26,22 @@ def infer(img):
|
|
26 |
|
27 |
# get point prompt
|
28 |
img_arr = np.array(point_prompt)
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
38 |
point_coords=input_point,
|
39 |
point_labels=input_label,
|
40 |
)
|
41 |
-
|
42 |
-
|
43 |
-
result_label = [(masks[0, :, :], "mask")]
|
44 |
-
return image, result_label
|
45 |
|
46 |
|
47 |
with gr.Blocks() as demo:
|
@@ -53,8 +53,7 @@ with gr.Blocks() as demo:
|
|
53 |
im = gr.ImageEditor(
|
54 |
type="pil"
|
55 |
)
|
56 |
-
submit_btn = gr.Button()
|
57 |
output = gr.AnnotatedImage()
|
58 |
-
|
59 |
|
60 |
demo.launch(debug=True)
|
|
|
26 |
|
27 |
# get point prompt
|
28 |
img_arr = np.array(point_prompt)
|
29 |
+
if not np.any(img_arr):
|
30 |
+
gr.Error("Please select a point on top of the image.")
|
31 |
+
else:
|
32 |
+
nonzero_indices = np.nonzero(img_arr)
|
33 |
+
img_arr = np.array(point_prompt)
|
34 |
+
nonzero_indices = np.nonzero(img_arr)
|
35 |
+
center_x = int(np.mean(nonzero_indices[1]))
|
36 |
+
center_y = int(np.mean(nonzero_indices[0]))
|
37 |
+
input_point = np.array([[center_x, center_y]])
|
38 |
+
input_label = np.array([1])
|
39 |
+
masks, scores, logits = predictor.predict(
|
40 |
point_coords=input_point,
|
41 |
point_labels=input_label,
|
42 |
)
|
43 |
+
result_label = [(masks[0, :, :], "mask")]
|
44 |
+
return image, result_label
|
|
|
|
|
45 |
|
46 |
|
47 |
with gr.Blocks() as demo:
|
|
|
53 |
im = gr.ImageEditor(
|
54 |
type="pil"
|
55 |
)
|
|
|
56 |
output = gr.AnnotatedImage()
|
57 |
+
im.change(infer, inputs=im, outputs=output)
|
58 |
|
59 |
demo.launch(debug=True)
|