Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -24,8 +24,29 @@ category_dict = {
|
|
24 |
77: 'teddy bear', 78: 'hair drier', 79: 'toothbrush'
|
25 |
}
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
@spaces.GPU(duration=200)
|
28 |
def LeYOLO_inference(image, model_id, image_size, conf_threshold, iou_threshold):
|
|
|
29 |
model = model = YOLO(f"kadirnar/{model_id}")
|
30 |
results = model(source=image, imgsz=image_size, iou=iou_threshold, conf=conf_threshold, verbose=False)[0]
|
31 |
detections = sv.Detections.from_ultralytics(results)
|
@@ -48,12 +69,12 @@ def app():
|
|
48 |
model_id = gr.Dropdown(
|
49 |
label="Model",
|
50 |
choices=[
|
51 |
-
"LeYOLOSmall",
|
52 |
-
"LeYOLONano",
|
53 |
-
"LeYOLOMedium",
|
54 |
-
"LeYOLOLarge",
|
55 |
],
|
56 |
-
value="LeYOLOMedium",
|
57 |
)
|
58 |
image_size = gr.Slider(
|
59 |
label="Image Size",
|
@@ -97,14 +118,14 @@ def app():
|
|
97 |
examples=[
|
98 |
[
|
99 |
"dog.jpeg",
|
100 |
-
"
|
101 |
640,
|
102 |
0.25,
|
103 |
0.45,
|
104 |
],
|
105 |
[
|
106 |
"zidane.jpg",
|
107 |
-
"LeYOLOMedium",
|
108 |
640,
|
109 |
0.25,
|
110 |
0.45,
|
|
|
24 |
77: 'teddy bear', 78: 'hair drier', 79: 'toothbrush'
|
25 |
}
|
26 |
|
27 |
+
|
28 |
+
def attempt_download_from_hub(repo_id, hf_token=None):
|
29 |
+
# https://github.com/fcakyon/yolov5-pip/blob/main/yolov5/utils/downloads.py
|
30 |
+
from huggingface_hub import hf_hub_download, list_repo_files
|
31 |
+
from huggingface_hub.utils._errors import RepositoryNotFoundError
|
32 |
+
from huggingface_hub.utils._validators import HFValidationError
|
33 |
+
try:
|
34 |
+
repo_files = list_repo_files(repo_id=repo_id, repo_type='model', token=hf_token)
|
35 |
+
model_file = [f for f in repo_files if f.endswith('.pt')][0]
|
36 |
+
file = hf_hub_download(
|
37 |
+
repo_id=repo_id,
|
38 |
+
filename=model_file,
|
39 |
+
repo_type='model',
|
40 |
+
token=hf_token,
|
41 |
+
)
|
42 |
+
return file
|
43 |
+
except (RepositoryNotFoundError, HFValidationError):
|
44 |
+
return None
|
45 |
+
|
46 |
+
|
47 |
@spaces.GPU(duration=200)
|
48 |
def LeYOLO_inference(image, model_id, image_size, conf_threshold, iou_threshold):
|
49 |
+
MODEL_PATH = attempt_download_from_hub("kadirnar/yolov10x")
|
50 |
model = model = YOLO(f"kadirnar/{model_id}")
|
51 |
results = model(source=image, imgsz=image_size, iou=iou_threshold, conf=conf_threshold, verbose=False)[0]
|
52 |
detections = sv.Detections.from_ultralytics(results)
|
|
|
69 |
model_id = gr.Dropdown(
|
70 |
label="Model",
|
71 |
choices=[
|
72 |
+
"kadirnar/LeYOLOSmall",
|
73 |
+
"kadirnar/LeYOLONano",
|
74 |
+
"kadirnar/LeYOLOMedium",
|
75 |
+
"kadirnar/LeYOLOLarge",
|
76 |
],
|
77 |
+
value="kadirnar/LeYOLOMedium",
|
78 |
)
|
79 |
image_size = gr.Slider(
|
80 |
label="Image Size",
|
|
|
118 |
examples=[
|
119 |
[
|
120 |
"dog.jpeg",
|
121 |
+
"kadirnar/LeYOLOMedium",
|
122 |
640,
|
123 |
0.25,
|
124 |
0.45,
|
125 |
],
|
126 |
[
|
127 |
"zidane.jpg",
|
128 |
+
"kadirnar/LeYOLOMedium",
|
129 |
640,
|
130 |
0.25,
|
131 |
0.45,
|