Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -35,6 +35,10 @@ def point_selection(mask_sim, topk=1):
|
|
35 |
|
36 |
return topk_xy, topk_label, last_xy, last_label
|
37 |
|
|
|
|
|
|
|
|
|
38 |
def inference_scribble(image):
|
39 |
# in context image and mask
|
40 |
ic_image = image["image"]
|
@@ -135,6 +139,7 @@ def inference_scribble(image):
|
|
135 |
return [Image.fromarray((mask_colors * 0.6 + test_image * 0.4).astype('uint8'), 'RGB'),
|
136 |
Image.fromarray((mask_colors ).astype('uint8'), 'RGB')]
|
137 |
|
|
|
138 |
demo = gr.Interface(fn=inference_scribble,
|
139 |
inputs=gr.Image(label="[Stroke] Draw on Image", tool='sketch',type='pil'),
|
140 |
outputs=[
|
@@ -149,4 +154,26 @@ demo = gr.Interface(fn=inference_scribble,
|
|
149 |
"./cardamage_example/0206.JPEG"
|
150 |
]
|
151 |
)
|
152 |
-
demo.launch(enable_queue=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
return topk_xy, topk_label, last_xy, last_label
|
37 |
|
38 |
+
def reset_data():
|
39 |
+
global cache_data
|
40 |
+
cache_data = None
|
41 |
+
|
42 |
def inference_scribble(image):
|
43 |
# in context image and mask
|
44 |
ic_image = image["image"]
|
|
|
139 |
return [Image.fromarray((mask_colors * 0.6 + test_image * 0.4).astype('uint8'), 'RGB'),
|
140 |
Image.fromarray((mask_colors ).astype('uint8'), 'RGB')]
|
141 |
|
142 |
+
'''
|
143 |
demo = gr.Interface(fn=inference_scribble,
|
144 |
inputs=gr.Image(label="[Stroke] Draw on Image", tool='sketch',type='pil'),
|
145 |
outputs=[
|
|
|
154 |
"./cardamage_example/0206.JPEG"
|
155 |
]
|
156 |
)
|
157 |
+
demo.launch(enable_queue=False)
|
158 |
+
'''
|
159 |
+
|
160 |
+
with gr.Blocks() as demo:
|
161 |
+
gr.Markdown("# How to use")
|
162 |
+
gr.Markdown("To start, input an image, then use the brush to create dots on the object which you want to segment, don't worry if your dots aren't perfect as the code will find the middle of each drawn item. Then press the segment button to create masks for the object that the dots are on.")
|
163 |
+
gr.Markdown("# Demo to run Segment Anything base model")
|
164 |
+
gr.Markdown("""This app uses the [Segment Anything](https://huggingface.co/facebook/sam-vit-base) model from Meta to get a mask from a points in an image.
|
165 |
+
""")
|
166 |
+
with gr.Tab("Flip Image"):
|
167 |
+
with gr.Row():
|
168 |
+
image_input = gr.Image(label="[Stroke] Draw on Image", tool='sketch',type='pil')
|
169 |
+
image_output = [
|
170 |
+
gr.Image(type="pil", label="Mask with Image"),
|
171 |
+
gr.Image(type="pil", label="Mask")
|
172 |
+
],
|
173 |
+
|
174 |
+
image_button = gr.Button("Genarate-Segment-Mask")
|
175 |
+
|
176 |
+
image_button.click(inference_scribble, inputs=image_input, outputs=image_output)
|
177 |
+
image_input.upload(reset_data)
|
178 |
+
|
179 |
+
demo.launch()
|