Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from ultralytics import YOLO
|
3 |
+
import spaces
|
4 |
+
|
5 |
+
@spaces.GPU(duration=200)
|
6 |
+
def LeYOLO_inference(image, model_id, image_size, conf_threshold, iou_threshold):
|
7 |
+
model = YOLO(f"{model_id}.pt")
|
8 |
+
results = model(source=image, imgsz=image_size, iou=iou_threshold, conf=conf_threshold, verbose=False)[0]
|
9 |
+
|
10 |
+
|
11 |
+
def app():
|
12 |
+
with gr.Blocks():
|
13 |
+
with gr.Row():
|
14 |
+
with gr.Column():
|
15 |
+
image = gr.Image(type="pil", label="Image")
|
16 |
+
|
17 |
+
model_id = gr.Dropdown(
|
18 |
+
label="Model",
|
19 |
+
choices=[
|
20 |
+
"yolov10n",
|
21 |
+
"yolov10s",
|
22 |
+
"yolov10m",
|
23 |
+
"yolov10b",
|
24 |
+
"yolov10l",
|
25 |
+
"yolov10x",
|
26 |
+
],
|
27 |
+
value="yolov10m",
|
28 |
+
)
|
29 |
+
image_size = gr.Slider(
|
30 |
+
label="Image Size",
|
31 |
+
minimum=320,
|
32 |
+
maximum=1280,
|
33 |
+
step=32,
|
34 |
+
value=640,
|
35 |
+
)
|
36 |
+
conf_threshold = gr.Slider(
|
37 |
+
label="Confidence Threshold",
|
38 |
+
minimum=0.1,
|
39 |
+
maximum=1.0,
|
40 |
+
step=0.1,
|
41 |
+
value=0.25,
|
42 |
+
)
|
43 |
+
iou_threshold = gr.Slider(
|
44 |
+
label="IoU Threshold",
|
45 |
+
minimum=0.1,
|
46 |
+
maximum=1.0,
|
47 |
+
step=0.1,
|
48 |
+
value=0.45,
|
49 |
+
)
|
50 |
+
yolov10_infer = gr.Button(value="Detect Objects")
|
51 |
+
|
52 |
+
with gr.Column():
|
53 |
+
output_image = gr.Image(type="pil", label="Annotated Image")
|
54 |
+
|
55 |
+
yolov10_infer.click(
|
56 |
+
fn=yolov10_inference,
|
57 |
+
inputs=[
|
58 |
+
image,
|
59 |
+
model_id,
|
60 |
+
image_size,
|
61 |
+
conf_threshold,
|
62 |
+
iou_threshold,
|
63 |
+
],
|
64 |
+
outputs=[output_image],
|
65 |
+
)
|
66 |
+
|
67 |
+
gr.Examples(
|
68 |
+
examples=[
|
69 |
+
[
|
70 |
+
"dog.jpeg",
|
71 |
+
"yolov10x",
|
72 |
+
640,
|
73 |
+
0.25,
|
74 |
+
0.45,
|
75 |
+
],
|
76 |
+
[
|
77 |
+
"huggingface.jpg",
|
78 |
+
"yolov10m",
|
79 |
+
640,
|
80 |
+
0.25,
|
81 |
+
0.45,
|
82 |
+
],
|
83 |
+
[
|
84 |
+
"zidane.jpg",
|
85 |
+
"yolov10b",
|
86 |
+
640,
|
87 |
+
0.25,
|
88 |
+
0.45,
|
89 |
+
],
|
90 |
+
],
|
91 |
+
fn=LeYOLO_inference,
|
92 |
+
inputs=[
|
93 |
+
image,
|
94 |
+
model_id,
|
95 |
+
image_size,
|
96 |
+
conf_threshold,
|
97 |
+
iou_threshold,
|
98 |
+
],
|
99 |
+
outputs=[output_image],
|
100 |
+
cache_examples="lazy",
|
101 |
+
)
|
102 |
+
|
103 |
+
gradio_app = gr.Blocks()
|
104 |
+
with gradio_app:
|
105 |
+
gr.HTML(
|
106 |
+
"""
|
107 |
+
<h1 style='text-align: center'>
|
108 |
+
YOLOv10: Real-Time End-to-End Object Detection
|
109 |
+
</h1>
|
110 |
+
""")
|
111 |
+
gr.HTML(
|
112 |
+
"""
|
113 |
+
<h3 style='text-align: center'>
|
114 |
+
Follow me for more!
|
115 |
+
<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> | <a href='https://www.huggingface.co/kadirnar/' target='_blank'>HuggingFace</a>
|
116 |
+
</h3>
|
117 |
+
""")
|
118 |
+
with gr.Row():
|
119 |
+
with gr.Column():
|
120 |
+
app()
|
121 |
+
|
122 |
+
gradio_app.launch(debug=True)
|