Steven Chen
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,12 +3,12 @@ import cv2
|
|
| 3 |
import tempfile
|
| 4 |
from ultralytics import YOLOv10
|
| 5 |
import supervision as sv
|
| 6 |
-
import
|
| 7 |
|
| 8 |
|
| 9 |
def download_models(model_id):
|
| 10 |
-
|
| 11 |
-
return
|
| 12 |
|
| 13 |
box_annotator = sv.BoxAnnotator()
|
| 14 |
category_dict = {
|
|
@@ -31,10 +31,9 @@ category_dict = {
|
|
| 31 |
}
|
| 32 |
|
| 33 |
|
| 34 |
-
@spaces.GPU(duration=200)
|
| 35 |
def yolov10_inference(image, video, model_id, image_size, conf_threshold, iou_threshold):
|
| 36 |
model_path = download_models(model_id)
|
| 37 |
-
model = YOLOv10
|
| 38 |
|
| 39 |
if image:
|
| 40 |
results = model(source=image, imgsz=image_size, iou=iou_threshold, conf=conf_threshold, verbose=False)[0]
|
|
@@ -100,14 +99,14 @@ def app():
|
|
| 100 |
model_id = gr.Dropdown(
|
| 101 |
label="Model",
|
| 102 |
choices=[
|
| 103 |
-
"yolov10n",
|
| 104 |
-
"yolov10s",
|
| 105 |
-
"yolov10m",
|
| 106 |
-
"yolov10b",
|
| 107 |
-
"yolov10l",
|
| 108 |
-
"yolov10x",
|
| 109 |
],
|
| 110 |
-
value="yolov10m",
|
| 111 |
)
|
| 112 |
image_size = gr.Slider(
|
| 113 |
label="Image Size",
|
|
@@ -167,14 +166,14 @@ def app():
|
|
| 167 |
examples=[
|
| 168 |
[
|
| 169 |
"ultralytics/assets/bus.jpg",
|
| 170 |
-
"yolov10s",
|
| 171 |
640,
|
| 172 |
0.25,
|
| 173 |
0.45,
|
| 174 |
],
|
| 175 |
[
|
| 176 |
"ultralytics/assets/zidane.jpg",
|
| 177 |
-
"yolov10s",
|
| 178 |
640,
|
| 179 |
0.25,
|
| 180 |
0.45,
|
|
@@ -212,4 +211,4 @@ with gradio_app:
|
|
| 212 |
app()
|
| 213 |
|
| 214 |
if __name__ == '__main__':
|
| 215 |
-
gradio_app.launch()
|
|
|
|
| 3 |
import tempfile
|
| 4 |
from ultralytics import YOLOv10
|
| 5 |
import supervision as sv
|
| 6 |
+
from huggingface_hub import hf_hub_download
|
| 7 |
|
| 8 |
|
| 9 |
def download_models(model_id):
|
| 10 |
+
hf_hub_download("jameslahm/yolov10x", filename=f"{model_id}", local_dir=f"./")
|
| 11 |
+
return f"./{model_id}"
|
| 12 |
|
| 13 |
box_annotator = sv.BoxAnnotator()
|
| 14 |
category_dict = {
|
|
|
|
| 31 |
}
|
| 32 |
|
| 33 |
|
|
|
|
| 34 |
def yolov10_inference(image, video, model_id, image_size, conf_threshold, iou_threshold):
|
| 35 |
model_path = download_models(model_id)
|
| 36 |
+
model = YOLOv10(model_path)
|
| 37 |
|
| 38 |
if image:
|
| 39 |
results = model(source=image, imgsz=image_size, iou=iou_threshold, conf=conf_threshold, verbose=False)[0]
|
|
|
|
| 99 |
model_id = gr.Dropdown(
|
| 100 |
label="Model",
|
| 101 |
choices=[
|
| 102 |
+
"yolov10n.pt",
|
| 103 |
+
"yolov10s.pt",
|
| 104 |
+
"yolov10m.pt",
|
| 105 |
+
"yolov10b.pt",
|
| 106 |
+
"yolov10l.pt",
|
| 107 |
+
"yolov10x.pt",
|
| 108 |
],
|
| 109 |
+
value="yolov10m.pt",
|
| 110 |
)
|
| 111 |
image_size = gr.Slider(
|
| 112 |
label="Image Size",
|
|
|
|
| 166 |
examples=[
|
| 167 |
[
|
| 168 |
"ultralytics/assets/bus.jpg",
|
| 169 |
+
"yolov10s.pt",
|
| 170 |
640,
|
| 171 |
0.25,
|
| 172 |
0.45,
|
| 173 |
],
|
| 174 |
[
|
| 175 |
"ultralytics/assets/zidane.jpg",
|
| 176 |
+
"yolov10s.pt",
|
| 177 |
640,
|
| 178 |
0.25,
|
| 179 |
0.45,
|
|
|
|
| 211 |
app()
|
| 212 |
|
| 213 |
if __name__ == '__main__':
|
| 214 |
+
gradio_app.launch()
|