Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from demo import automask_image_app, automask_video_app, sahi_autoseg_app
|
3 |
|
4 |
|
|
|
5 |
def image_app():
|
6 |
with gr.Blocks():
|
7 |
with gr.Row():
|
@@ -57,6 +58,27 @@ def image_app():
|
|
57 |
],
|
58 |
outputs=[output_image],
|
59 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
|
62 |
def video_app():
|
@@ -89,7 +111,7 @@ def video_app():
|
|
89 |
value=16,
|
90 |
label="Points per Side",
|
91 |
)
|
92 |
-
|
93 |
seg_automask_video_points_per_batch = gr.Slider(
|
94 |
minimum=0,
|
95 |
maximum=64,
|
@@ -114,6 +136,27 @@ def video_app():
|
|
114 |
outputs=[output_video],
|
115 |
)
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
def sahi_app():
|
119 |
with gr.Blocks():
|
@@ -121,33 +164,33 @@ def sahi_app():
|
|
121 |
with gr.Column():
|
122 |
sahi_image_file = gr.Image(type="filepath").style(height=260)
|
123 |
sahi_autoseg_model_type = gr.Dropdown(
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
|
133 |
with gr.Row():
|
134 |
with gr.Column():
|
135 |
sahi_model_type = gr.Dropdown(
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
sahi_image_size = gr.Slider(
|
144 |
minimum=0,
|
145 |
maximum=1600,
|
146 |
step=32,
|
147 |
value=640,
|
148 |
label="Image Size",
|
149 |
-
)
|
150 |
-
|
151 |
sahi_overlap_width = gr.Slider(
|
152 |
minimum=0,
|
153 |
maximum=1,
|
@@ -155,7 +198,7 @@ def sahi_app():
|
|
155 |
value=0.2,
|
156 |
label="Overlap Width",
|
157 |
)
|
158 |
-
|
159 |
sahi_slice_width = gr.Slider(
|
160 |
minimum=0,
|
161 |
maximum=640,
|
@@ -165,13 +208,13 @@ def sahi_app():
|
|
165 |
)
|
166 |
|
167 |
with gr.Row():
|
168 |
-
with gr.Column():
|
169 |
sahi_model_path = gr.Dropdown(
|
170 |
choices=[
|
171 |
"yolov5l.pt",
|
172 |
"yolov5l6.pt",
|
173 |
"yolov8l.pt",
|
174 |
-
"yolov8x.pt"
|
175 |
],
|
176 |
value="yolov5l6.pt",
|
177 |
label="Detector Model Path",
|
@@ -183,7 +226,7 @@ def sahi_app():
|
|
183 |
step=0.1,
|
184 |
value=0.2,
|
185 |
label="Confidence Threshold",
|
186 |
-
)
|
187 |
sahi_overlap_height = gr.Slider(
|
188 |
minimum=0,
|
189 |
maximum=1,
|
@@ -216,29 +259,44 @@ def sahi_app():
|
|
216 |
sahi_slice_width,
|
217 |
sahi_overlap_height,
|
218 |
sahi_overlap_width,
|
219 |
-
|
220 |
],
|
221 |
outputs=[output_image],
|
222 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
|
224 |
def metaseg_app():
|
225 |
app = gr.Blocks()
|
226 |
with app:
|
227 |
-
gr.HTML(
|
228 |
-
"""
|
229 |
-
<h1 style='text-align: center'>
|
230 |
-
MetaSeg: Segment Anything + Video + SAHI
|
231 |
-
</h1>
|
232 |
-
"""
|
233 |
-
)
|
234 |
-
gr.HTML(
|
235 |
-
"""
|
236 |
-
<h3 style='text-align: center'>
|
237 |
-
Follow me for more!
|
238 |
-
<a href='https://twitter.com/kadirnar_ai' target='_blank'>Twitter</a> | <a href='https://github.com/kadirnar' target='_blank'>Github</a> | <a href='https://www.linkedin.com/in/kadir-nar/' target='_blank'>Linkedin</a>
|
239 |
-
</h3>
|
240 |
-
"""
|
241 |
-
)
|
242 |
with gr.Row():
|
243 |
with gr.Column():
|
244 |
with gr.Tab("Image"):
|
@@ -247,7 +305,6 @@ def metaseg_app():
|
|
247 |
video_app()
|
248 |
with gr.Tab("SAHI"):
|
249 |
sahi_app()
|
250 |
-
|
251 |
|
252 |
app.queue(concurrency_count=1)
|
253 |
app.launch(debug=True, enable_queue=True)
|
|
|
2 |
from demo import automask_image_app, automask_video_app, sahi_autoseg_app
|
3 |
|
4 |
|
5 |
+
|
6 |
def image_app():
|
7 |
with gr.Blocks():
|
8 |
with gr.Row():
|
|
|
58 |
],
|
59 |
outputs=[output_image],
|
60 |
)
|
61 |
+
|
62 |
+
gr.Examples(
|
63 |
+
examples=[
|
64 |
+
[
|
65 |
+
"testv1.jpg",
|
66 |
+
"vit_l",
|
67 |
+
16,
|
68 |
+
64,
|
69 |
+
0,
|
70 |
+
],
|
71 |
+
|
72 |
+
],
|
73 |
+
inputs=[
|
74 |
+
seg_automask_image_file,
|
75 |
+
seg_automask_image_model_type,
|
76 |
+
seg_automask_image_points_per_side,
|
77 |
+
seg_automask_image_points_per_batch,
|
78 |
+
seg_automask_image_min_area,
|
79 |
+
],
|
80 |
+
outputs=[output_image],
|
81 |
+
)
|
82 |
|
83 |
|
84 |
def video_app():
|
|
|
111 |
value=16,
|
112 |
label="Points per Side",
|
113 |
)
|
114 |
+
|
115 |
seg_automask_video_points_per_batch = gr.Slider(
|
116 |
minimum=0,
|
117 |
maximum=64,
|
|
|
136 |
outputs=[output_video],
|
137 |
)
|
138 |
|
139 |
+
# examples
|
140 |
+
gr.Examples(
|
141 |
+
examples=[
|
142 |
+
[
|
143 |
+
"testv1.mp4",
|
144 |
+
"vit_l",
|
145 |
+
16,
|
146 |
+
64,
|
147 |
+
0,
|
148 |
+
],
|
149 |
+
],
|
150 |
+
inputs=[
|
151 |
+
seg_automask_video_file,
|
152 |
+
seg_automask_video_model_type,
|
153 |
+
seg_automask_video_points_per_side,
|
154 |
+
seg_automask_video_points_per_batch,
|
155 |
+
seg_automask_video_min_area,
|
156 |
+
],
|
157 |
+
outputs=[output_video],
|
158 |
+
)
|
159 |
+
|
160 |
|
161 |
def sahi_app():
|
162 |
with gr.Blocks():
|
|
|
164 |
with gr.Column():
|
165 |
sahi_image_file = gr.Image(type="filepath").style(height=260)
|
166 |
sahi_autoseg_model_type = gr.Dropdown(
|
167 |
+
choices=[
|
168 |
+
"vit_h",
|
169 |
+
"vit_l",
|
170 |
+
"vit_b",
|
171 |
+
],
|
172 |
+
value="vit_l",
|
173 |
+
label="Sam Model Type",
|
174 |
+
)
|
175 |
|
176 |
with gr.Row():
|
177 |
with gr.Column():
|
178 |
sahi_model_type = gr.Dropdown(
|
179 |
+
choices=[
|
180 |
+
"yolov5",
|
181 |
+
"yolov8",
|
182 |
+
],
|
183 |
+
value="yolov5",
|
184 |
+
label="Detector Model Type",
|
185 |
+
)
|
186 |
sahi_image_size = gr.Slider(
|
187 |
minimum=0,
|
188 |
maximum=1600,
|
189 |
step=32,
|
190 |
value=640,
|
191 |
label="Image Size",
|
192 |
+
)
|
193 |
+
|
194 |
sahi_overlap_width = gr.Slider(
|
195 |
minimum=0,
|
196 |
maximum=1,
|
|
|
198 |
value=0.2,
|
199 |
label="Overlap Width",
|
200 |
)
|
201 |
+
|
202 |
sahi_slice_width = gr.Slider(
|
203 |
minimum=0,
|
204 |
maximum=640,
|
|
|
208 |
)
|
209 |
|
210 |
with gr.Row():
|
211 |
+
with gr.Column():
|
212 |
sahi_model_path = gr.Dropdown(
|
213 |
choices=[
|
214 |
"yolov5l.pt",
|
215 |
"yolov5l6.pt",
|
216 |
"yolov8l.pt",
|
217 |
+
"yolov8x.pt",
|
218 |
],
|
219 |
value="yolov5l6.pt",
|
220 |
label="Detector Model Path",
|
|
|
226 |
step=0.1,
|
227 |
value=0.2,
|
228 |
label="Confidence Threshold",
|
229 |
+
)
|
230 |
sahi_overlap_height = gr.Slider(
|
231 |
minimum=0,
|
232 |
maximum=1,
|
|
|
259 |
sahi_slice_width,
|
260 |
sahi_overlap_height,
|
261 |
sahi_overlap_width,
|
|
|
262 |
],
|
263 |
outputs=[output_image],
|
264 |
)
|
265 |
+
|
266 |
+
gr.Examples(
|
267 |
+
examples=[
|
268 |
+
[
|
269 |
+
"testv2.jpg",
|
270 |
+
"vit_l",
|
271 |
+
"yolov5",
|
272 |
+
"yolov5l6.pt",
|
273 |
+
0.2,
|
274 |
+
640,
|
275 |
+
256,
|
276 |
+
256,
|
277 |
+
0.2,
|
278 |
+
0.2,
|
279 |
+
],
|
280 |
+
],
|
281 |
+
inputs=[
|
282 |
+
sahi_image_file,
|
283 |
+
sahi_autoseg_model_type,
|
284 |
+
sahi_model_type,
|
285 |
+
sahi_model_path,
|
286 |
+
sahi_conf_th,
|
287 |
+
sahi_image_size,
|
288 |
+
sahi_slice_height,
|
289 |
+
sahi_slice_width,
|
290 |
+
sahi_overlap_height,
|
291 |
+
sahi_overlap_width,
|
292 |
+
],
|
293 |
+
outputs=[output_image],
|
294 |
+
)
|
295 |
+
|
296 |
|
297 |
def metaseg_app():
|
298 |
app = gr.Blocks()
|
299 |
with app:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
with gr.Row():
|
301 |
with gr.Column():
|
302 |
with gr.Tab("Image"):
|
|
|
305 |
video_app()
|
306 |
with gr.Tab("SAHI"):
|
307 |
sahi_app()
|
|
|
308 |
|
309 |
app.queue(concurrency_count=1)
|
310 |
app.launch(debug=True, enable_queue=True)
|