Spaces:
Paused
Paused
Commit ·
48c1344
1
Parent(s): 5094450
Rename app_old.py to app.py
Browse files- app_old.py → app.py +39 -0
app_old.py → app.py
RENAMED
|
@@ -13,6 +13,33 @@ sam = sam_model_registry[model_type](checkpoint="./tinysam/tinysam.pth")
|
|
| 13 |
|
| 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.")
|
|
@@ -54,6 +81,18 @@ with gr.Blocks() as demo:
|
|
| 54 |
type="pil"
|
| 55 |
)
|
| 56 |
output = gr.AnnotatedImage()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
im.change(infer, inputs=im, outputs=output)
|
| 58 |
|
| 59 |
demo.launch(debug=True)
|
|
|
|
| 13 |
|
| 14 |
predictor = SamPredictor(sam)
|
| 15 |
|
| 16 |
+
examples = [
|
| 17 |
+
["assets/1.jpg"],
|
| 18 |
+
["assets/2.jpg"],
|
| 19 |
+
["assets/3.jpg"],
|
| 20 |
+
["assets/4.jpeg"],
|
| 21 |
+
["assets/5.jpg"],
|
| 22 |
+
["assets/6.jpeg"]
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
default_example = examples[0]
|
| 26 |
+
# Description
|
| 27 |
+
title = "<center><strong><font size='8'>TinySAM<font></strong> <a href='https://github.com/xinghaochen/TinySAM'><font size='6'>[GitHub]</font></a> </center>"
|
| 28 |
+
description_p = """# Interactive Instance Segmentation
|
| 29 |
+
- Point-prompt instruction
|
| 30 |
+
<ol>
|
| 31 |
+
<li> Click on the left image (point input), visualizing the point on the right image </li>
|
| 32 |
+
<li> Click the button of Segment with Point Prompt </li>
|
| 33 |
+
</ol>
|
| 34 |
+
- Box-prompt instruction
|
| 35 |
+
<ol>
|
| 36 |
+
<li> Click on the left image (one point input), visualizing the point on the right image </li>
|
| 37 |
+
<li> Click on the left image (another point input), visualizing the point and the box on the right image</li>
|
| 38 |
+
<li> Click the button of Segment with Box Prompt </li>
|
| 39 |
+
</ol>
|
| 40 |
+
- Github [link](https://github.com/xinghaochen/TinySAM)
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
def infer(img):
|
| 44 |
if img is None:
|
| 45 |
gr.Error("Please upload an image and select a point.")
|
|
|
|
| 81 |
type="pil"
|
| 82 |
)
|
| 83 |
output = gr.AnnotatedImage()
|
| 84 |
+
with gr.Row():
|
| 85 |
+
with gr.Column():
|
| 86 |
+
gr.Markdown("Try some of the examples below ⬇️")
|
| 87 |
+
gr.Examples(
|
| 88 |
+
examples=examples,
|
| 89 |
+
inputs=[im],
|
| 90 |
+
examples_per_page=4,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
with gr.Column():
|
| 94 |
+
# Description
|
| 95 |
+
gr.Markdown(description_p)
|
| 96 |
im.change(infer, inputs=im, outputs=output)
|
| 97 |
|
| 98 |
demo.launch(debug=True)
|