Spaces:
Runtime error
Runtime error
Upload utils.py
Browse files
utils.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def attempt_download_from_hub(repo_id, hf_token=None):
|
| 2 |
+
# https://github.com/fcakyon/yolov5-pip/blob/main/yolov5/utils/downloads.py
|
| 3 |
+
from huggingface_hub import hf_hub_download, list_repo_files
|
| 4 |
+
from huggingface_hub.utils._errors import RepositoryNotFoundError
|
| 5 |
+
from huggingface_hub.utils._validators import HFValidationError
|
| 6 |
+
try:
|
| 7 |
+
repo_files = list_repo_files(repo_id=repo_id, repo_type='model', token=hf_token)
|
| 8 |
+
model_file = [f for f in repo_files if f.endswith('.pt')][0]
|
| 9 |
+
file = hf_hub_download(
|
| 10 |
+
repo_id=repo_id,
|
| 11 |
+
filename=model_file,
|
| 12 |
+
repo_type='model',
|
| 13 |
+
token=hf_token,
|
| 14 |
+
)
|
| 15 |
+
return file
|
| 16 |
+
except (RepositoryNotFoundError, HFValidationError):
|
| 17 |
+
return None
|