Spaces:
Runtime error
Runtime error
test modified interface
Browse files
app.py
CHANGED
|
@@ -71,7 +71,7 @@ def overlay_masks_boxes_on_image(image, masks, boxes, labels, show_masks, show_b
|
|
| 71 |
return output_image
|
| 72 |
|
| 73 |
|
| 74 |
-
def detect_objects(image, prompt, show_masks, show_boxes, crop_options):
|
| 75 |
image_source, image = load_image(image)
|
| 76 |
predictor.set_image(image_source)
|
| 77 |
|
|
@@ -142,77 +142,30 @@ def detect_objects(image, prompt, show_masks, show_boxes, crop_options):
|
|
| 142 |
|
| 143 |
return output_image_path
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
gr.
|
| 149 |
-
|
| 150 |
-
body {
|
| 151 |
-
background-color: #f5f5f5;
|
| 152 |
-
font-family: 'Roboto', sans-serif;
|
| 153 |
-
padding: 30px;
|
| 154 |
-
}
|
| 155 |
-
</style>
|
| 156 |
-
""")
|
| 157 |
-
|
| 158 |
-
gr.HTML("<h1 style='text-align: center;'>Segment Any Image</h1>")
|
| 159 |
-
gr.HTML("<h3 style='text-align: center;'>Zero-Shot Object Detection, Segmentation and Cropping</h3>")
|
| 160 |
-
with gr.Row():
|
| 161 |
-
with gr.Column(width="auto"):
|
| 162 |
-
input_image = gr.Image(type='filepath', label="Upload Image")
|
| 163 |
-
with gr.Column(width="auto"):
|
| 164 |
-
output_image = gr.Image(type='filepath', label="Result")
|
| 165 |
-
with gr.Row():
|
| 166 |
-
with gr.Column(width="auto"):
|
| 167 |
-
object_search = gr.Textbox(
|
| 168 |
label="Object to Detect",
|
| 169 |
placeholder="Enter any text, comma separated if multiple objects needed",
|
| 170 |
show_label=True,
|
| 171 |
lines=1,
|
| 172 |
-
)
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
)
|
| 191 |
-
gr.HTML("""
|
| 192 |
-
<div style="text-align:center">
|
| 193 |
-
<p>Developed by <a href='https://www.linkedin.com/in/dekay/'>Github and Huggingface: Volkopat</a></p>
|
| 194 |
-
<p>Powered by <a href='https://segment-anything.com'>Segment Anything</a> and <a href='https://arxiv.org/abs/2303.05499'>Grounding DINO</a></p>
|
| 195 |
-
<p>Just upload an image and enter the objects to detect, segment, crop, etc. That's all folks!</p>
|
| 196 |
-
<p>What's Zero-Shot? It means you can detect objects without any training samples!</p>
|
| 197 |
-
<p>This project is for demonstration purposes. Credits for State of the Art models go to Meta AI and IDEA Research.</p>
|
| 198 |
-
</div>
|
| 199 |
-
<style>
|
| 200 |
-
p {
|
| 201 |
-
margin-bottom: 10px;
|
| 202 |
-
font-size: 16px;
|
| 203 |
-
}
|
| 204 |
-
a {
|
| 205 |
-
color: #3867d6;
|
| 206 |
-
text-decoration: none;
|
| 207 |
-
}
|
| 208 |
-
a:hover {
|
| 209 |
-
text-decoration: underline;
|
| 210 |
-
}
|
| 211 |
-
</style>
|
| 212 |
-
""")
|
| 213 |
-
|
| 214 |
-
submit.click(fn=detect_objects,
|
| 215 |
-
inputs=[input_image, object_search, show_masks, show_boxes, crop_options],
|
| 216 |
-
outputs=[output_image])
|
| 217 |
-
|
| 218 |
-
block.launch(width=800)
|
|
|
|
| 71 |
return output_image
|
| 72 |
|
| 73 |
|
| 74 |
+
def detect_objects(image, prompt, show_masks=True, show_boxes=True, crop_options="No crop"):
|
| 75 |
image_source, image = load_image(image)
|
| 76 |
predictor.set_image(image_source)
|
| 77 |
|
|
|
|
| 142 |
|
| 143 |
return output_image_path
|
| 144 |
|
| 145 |
+
|
| 146 |
+
app = gr.Interface(
|
| 147 |
+
detect_objects,
|
| 148 |
+
inputs=[gr.Image(type='filepath', label="Upload Image"),
|
| 149 |
+
gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
label="Object to Detect",
|
| 151 |
placeholder="Enter any text, comma separated if multiple objects needed",
|
| 152 |
show_label=True,
|
| 153 |
lines=1,
|
| 154 |
+
)],
|
| 155 |
+
outputs=[
|
| 156 |
+
gr.JSON(label="Output JSON"),
|
| 157 |
+
gr.Gallery(label="Result"),
|
| 158 |
+
],
|
| 159 |
+
examples=[
|
| 160 |
+
["images/tiger.jpeg", "animal from cat family"],
|
| 161 |
+
["images/car.jpeg", "a blue sports car"],
|
| 162 |
+
["images/bags.jpeg", "black bag next to the red bag"],
|
| 163 |
+
["images/deer.jpeg", "deer jumping and running across the road"],
|
| 164 |
+
["images/penn.jpeg", "sign board"]
|
| 165 |
+
],
|
| 166 |
+
title="Segment Anything",
|
| 167 |
+
description="Zero-Shot Object Detection, Segmentation and Cropping",
|
| 168 |
+
article="https://segment-anything.com",
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|