kadirnar/torchyolo
17
1def attempt_download_from_hub(repo_id, hf_token=None):2 # https://github.com/fcakyon/yolov5-pip/blob/main/yolov5/utils/downloads.py3 from huggingface_hub import hf_hub_download, list_repo_files4 from huggingface_hub.utils._errors import RepositoryNotFoundError5 from huggingface_hub.utils._validators import HFValidationError6 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 file16 except (RepositoryNotFoundError, HFValidationError):17 return None