Spaces:
Running
on
Zero
Running
on
Zero
update
Browse files
app.py
CHANGED
@@ -4,6 +4,24 @@ import os
|
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def download_models(model_id):
|
8 |
hf_hub_download("merve/yolov9", filename=f"{model_id}", local_dir=f"./{model_id}")
|
9 |
return f"./{model_id}"
|
@@ -26,7 +44,7 @@ def yolov9_inference(img_path, model_id, image_size, conf_threshold, iou_thresho
|
|
26 |
import yolov9
|
27 |
|
28 |
# Load the model
|
29 |
-
model_path =
|
30 |
model = yolov9.load(model_path, device="cuda")
|
31 |
|
32 |
# Set model parameters
|
|
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
|
6 |
|
7 |
+
def attempt_download_from_hub(repo_id, hf_token=None):
|
8 |
+
# https://github.com/fcakyon/yolov5-pip/blob/main/yolov5/utils/downloads.py
|
9 |
+
from huggingface_hub import hf_hub_download, list_repo_files
|
10 |
+
from huggingface_hub.utils._errors import RepositoryNotFoundError
|
11 |
+
from huggingface_hub.utils._validators import HFValidationError
|
12 |
+
try:
|
13 |
+
repo_files = list_repo_files(repo_id=repo_id, repo_type='model', token=hf_token)
|
14 |
+
model_file = [f for f in repo_files if f.endswith('.pt')][0]
|
15 |
+
file = hf_hub_download(
|
16 |
+
repo_id=repo_id,
|
17 |
+
filename=model_file,
|
18 |
+
repo_type='model',
|
19 |
+
token=hf_token,
|
20 |
+
)
|
21 |
+
return file
|
22 |
+
except (RepositoryNotFoundError, HFValidationError):
|
23 |
+
return None
|
24 |
+
|
25 |
def download_models(model_id):
|
26 |
hf_hub_download("merve/yolov9", filename=f"{model_id}", local_dir=f"./{model_id}")
|
27 |
return f"./{model_id}"
|
|
|
44 |
import yolov9
|
45 |
|
46 |
# Load the model
|
47 |
+
model_path = attempt_download_from_hub(model_id, hf_token=None)
|
48 |
model = yolov9.load(model_path, device="cuda")
|
49 |
|
50 |
# Set model parameters
|