Spaces:
Runtime error
Runtime error
feat: app for official sam inference
Browse files
app.py
CHANGED
|
@@ -53,6 +53,14 @@ def inference(
|
|
| 53 |
return contour_image
|
| 54 |
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
def get_coords(evt: gr.SelectData):
|
| 57 |
"""Get coords from mouse click in gradio."""
|
| 58 |
return evt.index[0], evt.index[1]
|
|
@@ -88,21 +96,7 @@ with gr.Blocks() as demo:
|
|
| 88 |
with gr.Row():
|
| 89 |
coord_h = gr.Number(label="Mouse coords h")
|
| 90 |
coord_w = gr.Number(label="Mouse coords w")
|
| 91 |
-
|
| 92 |
input_image.select(get_coords, None, [coord_h, coord_w])
|
| 93 |
-
gr.Examples(
|
| 94 |
-
examples=[
|
| 95 |
-
[os.path.join(os.path.dirname(__file__), "samples/bears.jpg"), 1300, 950],
|
| 96 |
-
[
|
| 97 |
-
os.path.join(os.path.dirname(__file__), "samples/breast_cancer.png"),
|
| 98 |
-
125,
|
| 99 |
-
60,
|
| 100 |
-
],
|
| 101 |
-
],
|
| 102 |
-
inputs=[input_image, coord_h, coord_w],
|
| 103 |
-
outputs=output,
|
| 104 |
-
fn=inference,
|
| 105 |
-
run_on_click=True,
|
| 106 |
-
)
|
| 107 |
|
| 108 |
demo.queue().launch(debug=True, enable_queue=True)
|
|
|
|
| 53 |
return contour_image
|
| 54 |
|
| 55 |
|
| 56 |
+
def extract_object_by_event(
|
| 57 |
+
image: np.ndarray, evt: gr.SelectData
|
| 58 |
+
):
|
| 59 |
+
click_h, click_w = evt.index
|
| 60 |
+
|
| 61 |
+
return inference(SAM_PREDICTOR, image, click_h, click_w)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
def get_coords(evt: gr.SelectData):
|
| 65 |
"""Get coords from mouse click in gradio."""
|
| 66 |
return evt.index[0], evt.index[1]
|
|
|
|
| 96 |
with gr.Row():
|
| 97 |
coord_h = gr.Number(label="Mouse coords h")
|
| 98 |
coord_w = gr.Number(label="Mouse coords w")
|
| 99 |
+
input_image.select(extract_object_by_event, [input_image], output)
|
| 100 |
input_image.select(get_coords, None, [coord_h, coord_w])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
demo.queue().launch(debug=True, enable_queue=True)
|