File tree Expand file tree Collapse file tree 1 file changed +16
-13
lines changed Expand file tree Collapse file tree 1 file changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -130,25 +130,28 @@ def push_to_hf_hub(
130
130
revision = None ,
131
131
model_config = None ,
132
132
):
133
+ if isinstance (use_auth_token , str ):
134
+ token = use_auth_token
135
+ else :
136
+ token = HfFolder .get_token ()
137
+ if token is None :
138
+ raise ValueError (
139
+ "You must login to the Hugging Face hub on this computer by typing `huggingface-cli login` and "
140
+ "entering your credentials to use `use_auth_token=True`. Alternatively, you can pass your own "
141
+ "token as the `use_auth_token` argument."
142
+ )
143
+
133
144
if repo_namespace_or_url :
134
145
repo_owner , repo_name = repo_namespace_or_url .rstrip ('/' ).split ('/' )[- 2 :]
135
146
else :
136
- if isinstance (use_auth_token , str ):
137
- token = use_auth_token
138
- else :
139
- token = HfFolder .get_token ()
140
-
141
- if token is None :
142
- raise ValueError (
143
- "You must login to the Hugging Face hub on this computer by typing `transformers-cli login` and "
144
- "entering your credentials to use `use_auth_token=True`. Alternatively, you can pass your own "
145
- "token as the `use_auth_token` argument."
146
- )
147
-
148
147
repo_owner = HfApi ().whoami (token )['name' ]
149
148
repo_name = Path (local_dir ).name
150
149
151
- repo_url = f'https://huggingface.co/{ repo_owner } /{ repo_name } '
150
+ repo_id = f'{ repo_owner } /{ repo_name } '
151
+ repo_url = f'https://huggingface.co/{ repo_id } '
152
+
153
+ # Create repo if doesn't exist yet
154
+ HfApi ().create_repo (repo_id , token = use_auth_token , exist_ok = True )
152
155
153
156
repo = Repository (
154
157
local_dir ,
You can’t perform that action at this time.
0 commit comments