Spaces:
Sleeping
Sleeping
onuralpszr
commited on
Commit
β’
7e9d826
1
Parent(s):
7999f9e
feat: π model dropdown menu and dot color select fixed
Browse filesSigned-off-by: Onuralp SEZER <[email protected]>
- .gitignore +4 -0
- app.py +28 -15
.gitignore
CHANGED
@@ -165,5 +165,9 @@ cython_debug/
|
|
165 |
.LSOverride
|
166 |
|
167 |
# YoloV8 files
|
|
|
168 |
yolov8s-seg.pt
|
|
|
|
|
|
|
169 |
yolov8s.pt
|
|
|
165 |
.LSOverride
|
166 |
|
167 |
# YoloV8 files
|
168 |
+
yolov8n-seg.pt
|
169 |
yolov8s-seg.pt
|
170 |
+
yolov8m-seg.pt
|
171 |
+
yolov8l-seg.pt
|
172 |
+
yolov8x-seg.pt
|
173 |
yolov8s.pt
|
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os # added for cache_examples
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
@@ -43,9 +44,9 @@ DESC = """
|
|
43 |
""" # noqa: E501 title/docs
|
44 |
|
45 |
|
46 |
-
def load_model(img):
|
47 |
# Load model, get results and return detections/labels
|
48 |
-
model = YOLO(
|
49 |
result = model(img, verbose=False, imgsz=1280)[0]
|
50 |
detections = sv.Detections.from_ultralytics(result)
|
51 |
labels = [
|
@@ -71,6 +72,7 @@ def calculate_crop_dim(a, b):
|
|
71 |
|
72 |
def annotator(
|
73 |
img,
|
|
|
74 |
annotators,
|
75 |
colorbb,
|
76 |
colormask,
|
@@ -80,6 +82,7 @@ def annotator(
|
|
80 |
colorlabel,
|
81 |
colorhalo,
|
82 |
colortri,
|
|
|
83 |
):
|
84 |
"""
|
85 |
Function that changes the color of annotators
|
@@ -93,7 +96,7 @@ def annotator(
|
|
93 |
|
94 |
img = img[..., ::-1].copy() # BGR to RGB using numpy
|
95 |
|
96 |
-
detections, labels = load_model(img)
|
97 |
|
98 |
if "Blur" in annotators:
|
99 |
# Apply Blur
|
@@ -101,7 +104,7 @@ def annotator(
|
|
101 |
img = blur_annotator.annotate(img, detections=detections)
|
102 |
|
103 |
if "BoundingBox" in annotators:
|
104 |
-
# Draw
|
105 |
box_annotator = sv.BoundingBoxAnnotator(sv.Color.from_hex(str(colorbb)))
|
106 |
img = box_annotator.annotate(img, detections=detections)
|
107 |
|
@@ -111,7 +114,7 @@ def annotator(
|
|
111 |
img = mask_annotator.annotate(img, detections=detections)
|
112 |
|
113 |
if "Ellipse" in annotators:
|
114 |
-
# Draw
|
115 |
ellipse_annotator = sv.EllipseAnnotator(sv.Color.from_hex(str(colorellipse)))
|
116 |
img = ellipse_annotator.annotate(img, detections=detections)
|
117 |
|
@@ -121,7 +124,7 @@ def annotator(
|
|
121 |
img = corner_annotator.annotate(img, detections=detections)
|
122 |
|
123 |
if "Circle" in annotators:
|
124 |
-
# Draw
|
125 |
circle_annotator = sv.CircleAnnotator(sv.Color.from_hex(str(colorcir)))
|
126 |
img = circle_annotator.annotate(img, detections=detections)
|
127 |
|
@@ -132,7 +135,7 @@ def annotator(
|
|
132 |
img = label_annotator.annotate(img, detections=detections, labels=labels)
|
133 |
|
134 |
if "Pixelate" in annotators:
|
135 |
-
#
|
136 |
pixelate_annotator = sv.PixelateAnnotator()
|
137 |
img = pixelate_annotator.annotate(img, detections=detections)
|
138 |
|
@@ -147,8 +150,8 @@ def annotator(
|
|
147 |
img = heatmap_annotator.annotate(img, detections=detections)
|
148 |
|
149 |
if "Dot" in annotators:
|
150 |
-
#
|
151 |
-
dot_annotator = sv.DotAnnotator()
|
152 |
img = dot_annotator.annotate(img, detections=detections)
|
153 |
|
154 |
if "Triangle" in annotators:
|
@@ -186,6 +189,20 @@ with gr.Blocks(theme=purple_theme) as app:
|
|
186 |
gr.HTML(SUBTITLE)
|
187 |
gr.HTML(BANNER)
|
188 |
gr.HTML(DESC)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
annotators = gr.CheckboxGroup(
|
190 |
choices=[
|
191 |
"BoundingBox",
|
@@ -209,21 +226,15 @@ with gr.Blocks(theme=purple_theme) as app:
|
|
209 |
with gr.Row(variant="compact"):
|
210 |
with gr.Column():
|
211 |
colorbb = gr.ColorPicker(value="#A351FB", label="BoundingBox")
|
212 |
-
with gr.Column():
|
213 |
colormask = gr.ColorPicker(value="#A351FB", label="Mask")
|
214 |
-
with gr.Column():
|
215 |
colorellipse = gr.ColorPicker(value="#A351FB", label="Ellipse")
|
216 |
with gr.Column():
|
217 |
colorbc = gr.ColorPicker(value="#A351FB", label="BoxCorner")
|
218 |
-
with gr.Column():
|
219 |
colorcir = gr.ColorPicker(value="#A351FB", label="Circle")
|
220 |
-
with gr.Column():
|
221 |
colorlabel = gr.ColorPicker(value="#A351FB", label="Label")
|
222 |
with gr.Column():
|
223 |
colorhalo = gr.ColorPicker(value="#A351FB", label="Halo")
|
224 |
-
with gr.Column():
|
225 |
colordot = gr.ColorPicker(value="#A351FB", label="Dot")
|
226 |
-
with gr.Column():
|
227 |
colortri = gr.ColorPicker(value="#A351FB", label="Triangle")
|
228 |
|
229 |
with gr.Row():
|
@@ -239,6 +250,7 @@ with gr.Blocks(theme=purple_theme) as app:
|
|
239 |
annotator,
|
240 |
inputs=[
|
241 |
image_input,
|
|
|
242 |
annotators,
|
243 |
colorbb,
|
244 |
colormask,
|
@@ -248,6 +260,7 @@ with gr.Blocks(theme=purple_theme) as app:
|
|
248 |
colorlabel,
|
249 |
colorhalo,
|
250 |
colortri,
|
|
|
251 |
],
|
252 |
outputs=image_output,
|
253 |
)
|
|
|
1 |
import os # added for cache_examples
|
2 |
+
from pathlib import Path
|
3 |
|
4 |
import gradio as gr
|
5 |
import numpy as np
|
|
|
44 |
""" # noqa: E501 title/docs
|
45 |
|
46 |
|
47 |
+
def load_model(img, model: str | Path = "yolov8s-seg.pt"):
|
48 |
# Load model, get results and return detections/labels
|
49 |
+
model = YOLO(model=model)
|
50 |
result = model(img, verbose=False, imgsz=1280)[0]
|
51 |
detections = sv.Detections.from_ultralytics(result)
|
52 |
labels = [
|
|
|
72 |
|
73 |
def annotator(
|
74 |
img,
|
75 |
+
model,
|
76 |
annotators,
|
77 |
colorbb,
|
78 |
colormask,
|
|
|
82 |
colorlabel,
|
83 |
colorhalo,
|
84 |
colortri,
|
85 |
+
colordot,
|
86 |
):
|
87 |
"""
|
88 |
Function that changes the color of annotators
|
|
|
96 |
|
97 |
img = img[..., ::-1].copy() # BGR to RGB using numpy
|
98 |
|
99 |
+
detections, labels = load_model(img, model)
|
100 |
|
101 |
if "Blur" in annotators:
|
102 |
# Apply Blur
|
|
|
104 |
img = blur_annotator.annotate(img, detections=detections)
|
105 |
|
106 |
if "BoundingBox" in annotators:
|
107 |
+
# Draw Boundingbox
|
108 |
box_annotator = sv.BoundingBoxAnnotator(sv.Color.from_hex(str(colorbb)))
|
109 |
img = box_annotator.annotate(img, detections=detections)
|
110 |
|
|
|
114 |
img = mask_annotator.annotate(img, detections=detections)
|
115 |
|
116 |
if "Ellipse" in annotators:
|
117 |
+
# Draw Ellipse
|
118 |
ellipse_annotator = sv.EllipseAnnotator(sv.Color.from_hex(str(colorellipse)))
|
119 |
img = ellipse_annotator.annotate(img, detections=detections)
|
120 |
|
|
|
124 |
img = corner_annotator.annotate(img, detections=detections)
|
125 |
|
126 |
if "Circle" in annotators:
|
127 |
+
# Draw Circle
|
128 |
circle_annotator = sv.CircleAnnotator(sv.Color.from_hex(str(colorcir)))
|
129 |
img = circle_annotator.annotate(img, detections=detections)
|
130 |
|
|
|
135 |
img = label_annotator.annotate(img, detections=detections, labels=labels)
|
136 |
|
137 |
if "Pixelate" in annotators:
|
138 |
+
# Apply PixelateAnnotator
|
139 |
pixelate_annotator = sv.PixelateAnnotator()
|
140 |
img = pixelate_annotator.annotate(img, detections=detections)
|
141 |
|
|
|
150 |
img = heatmap_annotator.annotate(img, detections=detections)
|
151 |
|
152 |
if "Dot" in annotators:
|
153 |
+
# Dot DotAnnotator
|
154 |
+
dot_annotator = sv.DotAnnotator(sv.Color.from_hex(str(colordot)))
|
155 |
img = dot_annotator.annotate(img, detections=detections)
|
156 |
|
157 |
if "Triangle" in annotators:
|
|
|
189 |
gr.HTML(SUBTITLE)
|
190 |
gr.HTML(BANNER)
|
191 |
gr.HTML(DESC)
|
192 |
+
|
193 |
+
models = gr.Dropdown(
|
194 |
+
[
|
195 |
+
"yolov8n-seg.pt",
|
196 |
+
"yolov8s-seg.pt",
|
197 |
+
"yolov8m-seg.pt",
|
198 |
+
"yolov8l-seg.pt",
|
199 |
+
"yolov8x-seg.pt",
|
200 |
+
],
|
201 |
+
type="value",
|
202 |
+
value="yolov8s-seg.pt",
|
203 |
+
label="Select Model:",
|
204 |
+
)
|
205 |
+
|
206 |
annotators = gr.CheckboxGroup(
|
207 |
choices=[
|
208 |
"BoundingBox",
|
|
|
226 |
with gr.Row(variant="compact"):
|
227 |
with gr.Column():
|
228 |
colorbb = gr.ColorPicker(value="#A351FB", label="BoundingBox")
|
|
|
229 |
colormask = gr.ColorPicker(value="#A351FB", label="Mask")
|
|
|
230 |
colorellipse = gr.ColorPicker(value="#A351FB", label="Ellipse")
|
231 |
with gr.Column():
|
232 |
colorbc = gr.ColorPicker(value="#A351FB", label="BoxCorner")
|
|
|
233 |
colorcir = gr.ColorPicker(value="#A351FB", label="Circle")
|
|
|
234 |
colorlabel = gr.ColorPicker(value="#A351FB", label="Label")
|
235 |
with gr.Column():
|
236 |
colorhalo = gr.ColorPicker(value="#A351FB", label="Halo")
|
|
|
237 |
colordot = gr.ColorPicker(value="#A351FB", label="Dot")
|
|
|
238 |
colortri = gr.ColorPicker(value="#A351FB", label="Triangle")
|
239 |
|
240 |
with gr.Row():
|
|
|
250 |
annotator,
|
251 |
inputs=[
|
252 |
image_input,
|
253 |
+
models,
|
254 |
annotators,
|
255 |
colorbb,
|
256 |
colormask,
|
|
|
260 |
colorlabel,
|
261 |
colorhalo,
|
262 |
colortri,
|
263 |
+
colordot,
|
264 |
],
|
265 |
outputs=image_output,
|
266 |
)
|