From ae0a0db7de06fa994a5ca0cb790422837eba924e Mon Sep 17 00:00:00 2001 From: Wauplin Date: Tue, 15 Nov 2022 15:17:20 +0100 Subject: [PATCH] Create repo before cloning with Repository.clone_from --- timm/models/hub.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/timm/models/hub.py b/timm/models/hub.py index 8b63ff7e..938f10eb 100644 --- a/timm/models/hub.py +++ b/timm/models/hub.py @@ -130,25 +130,28 @@ def push_to_hf_hub( revision=None, model_config=None, ): + if isinstance(use_auth_token, str): + token = use_auth_token + else: + token = HfFolder.get_token() + if token is None: + raise ValueError( + "You must login to the Hugging Face hub on this computer by typing `huggingface-cli login` and " + "entering your credentials to use `use_auth_token=True`. Alternatively, you can pass your own " + "token as the `use_auth_token` argument." + ) + if repo_namespace_or_url: repo_owner, repo_name = repo_namespace_or_url.rstrip('/').split('/')[-2:] else: - if isinstance(use_auth_token, str): - token = use_auth_token - else: - token = HfFolder.get_token() - - if token is None: - raise ValueError( - "You must login to the Hugging Face hub on this computer by typing `transformers-cli login` and " - "entering your credentials to use `use_auth_token=True`. Alternatively, you can pass your own " - "token as the `use_auth_token` argument." - ) - repo_owner = HfApi().whoami(token)['name'] repo_name = Path(local_dir).name - repo_url = f'https://huggingface.co/{repo_owner}/{repo_name}' + repo_id = f'{repo_owner}/{repo_name}' + repo_url = f'https://huggingface.co/{repo_id}' + + # Create repo if doesn't exist yet + HfApi().create_repo(repo_id, token=use_auth_token, exist_ok=True) repo = Repository( local_dir,