kadirnar commited on
Commit
4306cde
1 Parent(s): cab2267

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +107 -23
app.py CHANGED
@@ -12,11 +12,11 @@ def download_models(model_id):
12
  MODEL_PATH = 'yolov10n.pt'
13
  model = YOLOv10(MODEL_PATH)
14
  box_annotator = sv.BoxAnnotator()
15
- model_path = download_models(model_id)
16
 
17
  @spaces.GPU(duration=200)
18
- def detect(image):
19
- results = model(source=image, conf=0.25, verbose=False)[0]
 
20
  detections = sv.Detections.from_ultralytics(results)
21
 
22
  labels = [
@@ -27,29 +27,113 @@ def detect(image):
27
 
28
  return annotated_image
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  gradio_app = gr.Blocks()
31
  with gradio_app:
32
- gr.HTML(
33
  """
34
- <h1 style='text-align: center'>
35
- YOLOv10: Real-Time End-to-End Object Detection
36
- </h1>
37
- """)
38
- gr.HTML(
39
  """
40
- <h3 style='text-align: center'>
41
- Follow me for more!
42
- <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>
43
- </h3>
44
- """)
45
-
46
- input_image = gr.Image(type="numpy")
47
- output_image = gr.Image(type="numpy", label="Annotated Image")
48
-
49
- gr.Interface(
50
- fn=detect,
51
- inputs=input_image,
52
- outputs=output_image,
53
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
- gradio_app.launch()
 
12
  MODEL_PATH = 'yolov10n.pt'
13
  model = YOLOv10(MODEL_PATH)
14
  box_annotator = sv.BoxAnnotator()
 
15
 
16
  @spaces.GPU(duration=200)
17
+ def detect(image, model_id, image_size, conf_threshold, iou_threshold):
18
+ model_path = download_models(model_id)
19
+ results = model(source=image, conf=conf, imgsz=image_size, iou, verbose=False)[0]
20
  detections = sv.Detections.from_ultralytics(results)
21
 
22
  labels = [
 
27
 
28
  return annotated_image
29
 
30
+ def app():
31
+ with gr.Blocks():
32
+ with gr.Row():
33
+ with gr.Column():
34
+ image = gr.Image(type="numpy", label="Image")
35
+
36
+ model_id = gr.Dropdown(
37
+ label="Model",
38
+ choices=[
39
+ "yolov10n.pt",
40
+ "yolov10s.pt",
41
+ "yolov10m.pt",
42
+ "yolov10b.pt",
43
+ "yolov10x.pt",
44
+ ],
45
+ value="yolov10s.pt",
46
+ )
47
+ image_size = gr.Slider(
48
+ label="Image Size",
49
+ minimum=320,
50
+ maximum=1280,
51
+ step=32,
52
+ value=640,
53
+ )
54
+ conf_threshold = gr.Slider(
55
+ label="Confidence Threshold",
56
+ minimum=0.1,
57
+ maximum=1.0,
58
+ step=0.1,
59
+ value=0.25,
60
+ )
61
+ iou_threshold = gr.Slider(
62
+ label="IoU Threshold",
63
+ minimum=0.1,
64
+ maximum=1.0,
65
+ step=0.1,
66
+ value=0.45,
67
+ )
68
+ yolov10_infer = gr.Button(value="Detect Objects")
69
+
70
+ with gr.Column():
71
+ output_image = gr.Image(type="numpy", label="Annotated Image")
72
+
73
+ yolov10_infer.click(
74
+ fn=yolov10_inference,
75
+ inputs=[
76
+ image,
77
+ model_id,
78
+ image_size,
79
+ conf_threshold,
80
+ iou_threshold,
81
+ ],
82
+ outputs=[output_image],
83
+ )
84
+
85
+ gr.Examples(
86
+ examples=[
87
+ [
88
+ "images/example1.jpg",
89
+ "yolov10s.pt",
90
+ 640,
91
+ 0.25,
92
+ 0.45,
93
+ ],
94
+ [
95
+ "images/example2.jpg",
96
+ "yolov10m.pt",
97
+ 640,
98
+ 0.25,
99
+ 0.45,
100
+ ],
101
+ ],
102
+ fn=yolov10_inference,
103
+ inputs=[
104
+ image,
105
+ model_path,
106
+ image_size,
107
+ conf_threshold,
108
+ iou_threshold,
109
+ ],
110
+ outputs=[output_image],
111
+ cache_examples=True,
112
+ )
113
+
114
  gradio_app = gr.Blocks()
115
  with gradio_app:
116
+ gr.Markdown(
117
  """
118
+ # YOLOv10: State-of-the-Art Object Detection
 
 
 
 
119
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  )
121
+ gr.Markdown(
122
+ """
123
+ Detect objects in images using the YOLOv10 model. Select a pre-trained model, adjust the inference settings, and upload an image to see the detected objects.
124
+ """
125
+ )
126
+ with gr.Row():
127
+ gr.Markdown(
128
+ """
129
+ Follow me for more projects and updates:
130
+ - [Twitter](https://twitter.com/kadirnar_ai)
131
+ - [GitHub](https://github.com/kadirnar)
132
+ - [LinkedIn](https://www.linkedin.com/in/kadir-nar/)
133
+ - [HuggingFace](https://www.huggingface.co/kadirnar/)
134
+ """
135
+ )
136
+
137
+ app()
138
 
139
+ gradio_app.launch(debug=True)