huggingface-hub 0.35.1__py3-none-any.whl → 1.0.0rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of huggingface-hub might be problematic. Click here for more details.
- huggingface_hub/__init__.py +28 -45
- huggingface_hub/_commit_api.py +28 -28
- huggingface_hub/_commit_scheduler.py +11 -8
- huggingface_hub/_inference_endpoints.py +8 -8
- huggingface_hub/_jobs_api.py +20 -20
- huggingface_hub/_login.py +13 -39
- huggingface_hub/_oauth.py +8 -8
- huggingface_hub/_snapshot_download.py +14 -28
- huggingface_hub/_space_api.py +4 -4
- huggingface_hub/_tensorboard_logger.py +5 -5
- huggingface_hub/_upload_large_folder.py +15 -15
- huggingface_hub/_webhooks_payload.py +3 -3
- huggingface_hub/_webhooks_server.py +2 -2
- huggingface_hub/cli/__init__.py +0 -14
- huggingface_hub/cli/_cli_utils.py +80 -3
- huggingface_hub/cli/auth.py +104 -150
- huggingface_hub/cli/cache.py +102 -126
- huggingface_hub/cli/download.py +93 -110
- huggingface_hub/cli/hf.py +37 -41
- huggingface_hub/cli/jobs.py +689 -1017
- huggingface_hub/cli/lfs.py +120 -143
- huggingface_hub/cli/repo.py +158 -216
- huggingface_hub/cli/repo_files.py +50 -84
- huggingface_hub/cli/system.py +6 -25
- huggingface_hub/cli/upload.py +198 -212
- huggingface_hub/cli/upload_large_folder.py +90 -105
- huggingface_hub/commands/_cli_utils.py +2 -2
- huggingface_hub/commands/delete_cache.py +11 -11
- huggingface_hub/commands/download.py +4 -13
- huggingface_hub/commands/lfs.py +4 -4
- huggingface_hub/commands/repo_files.py +2 -2
- huggingface_hub/commands/tag.py +1 -3
- huggingface_hub/commands/upload.py +4 -4
- huggingface_hub/commands/upload_large_folder.py +3 -3
- huggingface_hub/commands/user.py +4 -5
- huggingface_hub/community.py +5 -5
- huggingface_hub/constants.py +3 -41
- huggingface_hub/dataclasses.py +16 -22
- huggingface_hub/errors.py +43 -30
- huggingface_hub/fastai_utils.py +8 -9
- huggingface_hub/file_download.py +154 -253
- huggingface_hub/hf_api.py +329 -558
- huggingface_hub/hf_file_system.py +104 -62
- huggingface_hub/hub_mixin.py +32 -54
- huggingface_hub/inference/_client.py +178 -163
- huggingface_hub/inference/_common.py +38 -54
- huggingface_hub/inference/_generated/_async_client.py +219 -259
- huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +3 -3
- huggingface_hub/inference/_generated/types/base.py +10 -7
- huggingface_hub/inference/_generated/types/chat_completion.py +16 -16
- huggingface_hub/inference/_generated/types/depth_estimation.py +2 -2
- huggingface_hub/inference/_generated/types/document_question_answering.py +2 -2
- huggingface_hub/inference/_generated/types/feature_extraction.py +2 -2
- huggingface_hub/inference/_generated/types/fill_mask.py +2 -2
- huggingface_hub/inference/_generated/types/sentence_similarity.py +3 -3
- huggingface_hub/inference/_generated/types/summarization.py +2 -2
- huggingface_hub/inference/_generated/types/table_question_answering.py +4 -4
- huggingface_hub/inference/_generated/types/text2text_generation.py +2 -2
- huggingface_hub/inference/_generated/types/text_generation.py +10 -10
- huggingface_hub/inference/_generated/types/text_to_video.py +2 -2
- huggingface_hub/inference/_generated/types/token_classification.py +2 -2
- huggingface_hub/inference/_generated/types/translation.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_classification.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_image_classification.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_object_detection.py +1 -3
- huggingface_hub/inference/_mcp/agent.py +3 -3
- huggingface_hub/inference/_mcp/constants.py +1 -2
- huggingface_hub/inference/_mcp/mcp_client.py +33 -22
- huggingface_hub/inference/_mcp/types.py +10 -10
- huggingface_hub/inference/_mcp/utils.py +4 -4
- huggingface_hub/inference/_providers/__init__.py +2 -13
- huggingface_hub/inference/_providers/_common.py +24 -25
- huggingface_hub/inference/_providers/black_forest_labs.py +6 -6
- huggingface_hub/inference/_providers/cohere.py +3 -3
- huggingface_hub/inference/_providers/fal_ai.py +25 -25
- huggingface_hub/inference/_providers/featherless_ai.py +4 -4
- huggingface_hub/inference/_providers/fireworks_ai.py +3 -3
- huggingface_hub/inference/_providers/hf_inference.py +13 -13
- huggingface_hub/inference/_providers/hyperbolic.py +4 -4
- huggingface_hub/inference/_providers/nebius.py +10 -10
- huggingface_hub/inference/_providers/novita.py +5 -5
- huggingface_hub/inference/_providers/nscale.py +4 -4
- huggingface_hub/inference/_providers/replicate.py +15 -15
- huggingface_hub/inference/_providers/sambanova.py +6 -6
- huggingface_hub/inference/_providers/together.py +7 -7
- huggingface_hub/lfs.py +24 -33
- huggingface_hub/repocard.py +16 -17
- huggingface_hub/repocard_data.py +56 -56
- huggingface_hub/serialization/__init__.py +0 -1
- huggingface_hub/serialization/_base.py +9 -9
- huggingface_hub/serialization/_dduf.py +7 -7
- huggingface_hub/serialization/_torch.py +28 -28
- huggingface_hub/utils/__init__.py +10 -4
- huggingface_hub/utils/_auth.py +5 -5
- huggingface_hub/utils/_cache_manager.py +31 -31
- huggingface_hub/utils/_deprecation.py +1 -1
- huggingface_hub/utils/_dotenv.py +3 -3
- huggingface_hub/utils/_fixes.py +0 -10
- huggingface_hub/utils/_git_credential.py +3 -3
- huggingface_hub/utils/_headers.py +7 -29
- huggingface_hub/utils/_http.py +369 -209
- huggingface_hub/utils/_pagination.py +4 -4
- huggingface_hub/utils/_paths.py +5 -5
- huggingface_hub/utils/_runtime.py +15 -13
- huggingface_hub/utils/_safetensors.py +21 -21
- huggingface_hub/utils/_subprocess.py +9 -9
- huggingface_hub/utils/_telemetry.py +3 -3
- huggingface_hub/utils/_typing.py +3 -3
- huggingface_hub/utils/_validators.py +53 -72
- huggingface_hub/utils/_xet.py +16 -16
- huggingface_hub/utils/_xet_progress_reporting.py +1 -1
- huggingface_hub/utils/insecure_hashlib.py +3 -9
- huggingface_hub/utils/tqdm.py +3 -3
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/METADATA +17 -26
- huggingface_hub-1.0.0rc1.dist-info/RECORD +161 -0
- huggingface_hub/inference/_providers/publicai.py +0 -6
- huggingface_hub/inference/_providers/scaleway.py +0 -28
- huggingface_hub/inference_api.py +0 -217
- huggingface_hub/keras_mixin.py +0 -500
- huggingface_hub/repository.py +0 -1477
- huggingface_hub/serialization/_tensorflow.py +0 -95
- huggingface_hub/utils/_hf_folder.py +0 -68
- huggingface_hub-0.35.1.dist-info/RECORD +0 -168
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/top_level.txt +0 -0
huggingface_hub/cli/upload.py
CHANGED
|
@@ -49,174 +49,112 @@ Usage:
|
|
|
49
49
|
import os
|
|
50
50
|
import time
|
|
51
51
|
import warnings
|
|
52
|
-
from
|
|
53
|
-
|
|
52
|
+
from typing import Annotated, Optional
|
|
53
|
+
|
|
54
|
+
import typer
|
|
54
55
|
|
|
55
56
|
from huggingface_hub import logging
|
|
56
57
|
from huggingface_hub._commit_scheduler import CommitScheduler
|
|
57
|
-
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
58
58
|
from huggingface_hub.constants import HF_HUB_ENABLE_HF_TRANSFER
|
|
59
59
|
from huggingface_hub.errors import RevisionNotFoundError
|
|
60
|
-
from huggingface_hub.hf_api import HfApi
|
|
61
60
|
from huggingface_hub.utils import disable_progress_bars, enable_progress_bars
|
|
62
61
|
from huggingface_hub.utils._runtime import is_xet_available
|
|
63
62
|
|
|
63
|
+
from ._cli_utils import PrivateOpt, RepoIdArg, RepoType, RepoTypeOpt, RevisionOpt, TokenOpt, get_hf_api
|
|
64
|
+
|
|
64
65
|
|
|
65
66
|
logger = logging.get_logger(__name__)
|
|
66
67
|
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
)
|
|
74
|
-
upload_parser.add_argument(
|
|
75
|
-
"repo_id", type=str, help="The ID of the repo to upload to (e.g. `username/repo-name`)."
|
|
76
|
-
)
|
|
77
|
-
upload_parser.add_argument(
|
|
78
|
-
"local_path",
|
|
79
|
-
nargs="?",
|
|
69
|
+
def upload(
|
|
70
|
+
repo_id: RepoIdArg,
|
|
71
|
+
local_path: Annotated[
|
|
72
|
+
Optional[str],
|
|
73
|
+
typer.Argument(
|
|
80
74
|
help="Local path to the file or folder to upload. Wildcard patterns are supported. Defaults to current directory.",
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
),
|
|
76
|
+
] = None,
|
|
77
|
+
path_in_repo: Annotated[
|
|
78
|
+
Optional[str],
|
|
79
|
+
typer.Argument(
|
|
85
80
|
help="Path of the file or folder in the repo. Defaults to the relative path of the file or folder.",
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
" exists."
|
|
107
|
-
),
|
|
108
|
-
)
|
|
109
|
-
upload_parser.add_argument("--include", nargs="*", type=str, help="Glob patterns to match files to upload.")
|
|
110
|
-
upload_parser.add_argument(
|
|
111
|
-
"--exclude", nargs="*", type=str, help="Glob patterns to exclude from files to upload."
|
|
112
|
-
)
|
|
113
|
-
upload_parser.add_argument(
|
|
114
|
-
"--delete",
|
|
115
|
-
nargs="*",
|
|
116
|
-
type=str,
|
|
81
|
+
),
|
|
82
|
+
] = None,
|
|
83
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
84
|
+
revision: RevisionOpt = None,
|
|
85
|
+
private: PrivateOpt = False,
|
|
86
|
+
include: Annotated[
|
|
87
|
+
Optional[list[str]],
|
|
88
|
+
typer.Option(
|
|
89
|
+
help="Glob patterns to match files to upload.",
|
|
90
|
+
),
|
|
91
|
+
] = None,
|
|
92
|
+
exclude: Annotated[
|
|
93
|
+
Optional[list[str]],
|
|
94
|
+
typer.Option(
|
|
95
|
+
help="Glob patterns to exclude from files to upload.",
|
|
96
|
+
),
|
|
97
|
+
] = None,
|
|
98
|
+
delete: Annotated[
|
|
99
|
+
Optional[list[str]],
|
|
100
|
+
typer.Option(
|
|
117
101
|
help="Glob patterns for file to be deleted from the repo while committing.",
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
help="
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
"
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if
|
|
168
|
-
if
|
|
169
|
-
|
|
170
|
-
if
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
self.path_in_repo = "."
|
|
175
|
-
elif args.local_path is None and os.path.isfile(repo_name):
|
|
176
|
-
# Implicit case 1: user provided only a repo_id which happen to be a local file as well => upload it with same name
|
|
177
|
-
self.local_path = repo_name
|
|
178
|
-
self.path_in_repo = repo_name
|
|
179
|
-
elif args.local_path is None and os.path.isdir(repo_name):
|
|
180
|
-
# Implicit case 2: user provided only a repo_id which happen to be a local folder as well => upload it at root
|
|
181
|
-
self.local_path = repo_name
|
|
182
|
-
self.path_in_repo = "."
|
|
183
|
-
elif args.local_path is None:
|
|
184
|
-
# Implicit case 3: user provided only a repo_id that does not match a local file or folder
|
|
185
|
-
# => the user must explicitly provide a local_path => raise exception
|
|
186
|
-
raise ValueError(f"'{repo_name}' is not a local file or folder. Please set `local_path` explicitly.")
|
|
187
|
-
elif args.path_in_repo is None and os.path.isfile(args.local_path):
|
|
188
|
-
# Explicit local path to file, no path in repo => upload it at root with same name
|
|
189
|
-
self.local_path = args.local_path
|
|
190
|
-
self.path_in_repo = os.path.basename(args.local_path)
|
|
191
|
-
elif args.path_in_repo is None:
|
|
192
|
-
# Explicit local path to folder, no path in repo => upload at root
|
|
193
|
-
self.local_path = args.local_path
|
|
194
|
-
self.path_in_repo = "."
|
|
195
|
-
else:
|
|
196
|
-
# Finally, if both paths are explicit
|
|
197
|
-
self.local_path = args.local_path
|
|
198
|
-
self.path_in_repo = args.path_in_repo
|
|
199
|
-
|
|
200
|
-
def run(self) -> None:
|
|
201
|
-
if self.quiet:
|
|
202
|
-
disable_progress_bars()
|
|
203
|
-
with warnings.catch_warnings():
|
|
204
|
-
warnings.simplefilter("ignore")
|
|
205
|
-
print(self._upload())
|
|
206
|
-
enable_progress_bars()
|
|
207
|
-
else:
|
|
208
|
-
logging.set_verbosity_info()
|
|
209
|
-
print(self._upload())
|
|
210
|
-
logging.set_verbosity_warning()
|
|
211
|
-
|
|
212
|
-
def _upload(self) -> str:
|
|
213
|
-
if os.path.isfile(self.local_path):
|
|
214
|
-
if self.include is not None and len(self.include) > 0:
|
|
215
|
-
warnings.warn("Ignoring `--include` since a single file is uploaded.")
|
|
216
|
-
if self.exclude is not None and len(self.exclude) > 0:
|
|
217
|
-
warnings.warn("Ignoring `--exclude` since a single file is uploaded.")
|
|
218
|
-
if self.delete is not None and len(self.delete) > 0:
|
|
219
|
-
warnings.warn("Ignoring `--delete` since a single file is uploaded.")
|
|
102
|
+
),
|
|
103
|
+
] = None,
|
|
104
|
+
commit_message: Annotated[
|
|
105
|
+
Optional[str],
|
|
106
|
+
typer.Option(
|
|
107
|
+
help="The summary / title / first line of the generated commit.",
|
|
108
|
+
),
|
|
109
|
+
] = None,
|
|
110
|
+
commit_description: Annotated[
|
|
111
|
+
Optional[str],
|
|
112
|
+
typer.Option(
|
|
113
|
+
help="The description of the generated commit.",
|
|
114
|
+
),
|
|
115
|
+
] = None,
|
|
116
|
+
create_pr: Annotated[
|
|
117
|
+
bool,
|
|
118
|
+
typer.Option(
|
|
119
|
+
help="Whether to upload content as a new Pull Request.",
|
|
120
|
+
),
|
|
121
|
+
] = False,
|
|
122
|
+
every: Annotated[
|
|
123
|
+
Optional[float],
|
|
124
|
+
typer.Option(
|
|
125
|
+
help="f set, a background job is scheduled to create commits every `every` minutes.",
|
|
126
|
+
),
|
|
127
|
+
] = None,
|
|
128
|
+
token: TokenOpt = None,
|
|
129
|
+
quiet: Annotated[
|
|
130
|
+
bool,
|
|
131
|
+
typer.Option(
|
|
132
|
+
help="Disable progress bars and warnings; print only the returned path.",
|
|
133
|
+
),
|
|
134
|
+
] = False,
|
|
135
|
+
) -> None:
|
|
136
|
+
"""Upload a file or a folder to the Hub. Recommended for single-commit uploads."""
|
|
137
|
+
|
|
138
|
+
if every is not None and every <= 0:
|
|
139
|
+
raise typer.BadParameter("--every must be a positive value", param_hint="every")
|
|
140
|
+
|
|
141
|
+
repo_type_str = repo_type.value
|
|
142
|
+
|
|
143
|
+
api = get_hf_api(token=token)
|
|
144
|
+
|
|
145
|
+
# Resolve local_path and path_in_repo based on implicit/explicit rules
|
|
146
|
+
resolved_local_path, resolved_path_in_repo, resolved_include = _resolve_upload_paths(
|
|
147
|
+
repo_id=repo_id, local_path=local_path, path_in_repo=path_in_repo, include=include
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
def run_upload() -> str:
|
|
151
|
+
if os.path.isfile(resolved_local_path):
|
|
152
|
+
if resolved_include is not None and len(resolved_include) > 0 and isinstance(resolved_include, list):
|
|
153
|
+
warnings.warn("Ignoring --include since a single file is uploaded.")
|
|
154
|
+
if exclude is not None and len(exclude) > 0:
|
|
155
|
+
warnings.warn("Ignoring --exclude since a single file is uploaded.")
|
|
156
|
+
if delete is not None and len(delete) > 0:
|
|
157
|
+
warnings.warn("Ignoring --delete since a single file is uploaded.")
|
|
220
158
|
|
|
221
159
|
if not is_xet_available() and not HF_HUB_ENABLE_HF_TRANSFER:
|
|
222
160
|
logger.info(
|
|
@@ -225,39 +163,45 @@ class UploadCommand(BaseHuggingfaceCLICommand):
|
|
|
225
163
|
)
|
|
226
164
|
|
|
227
165
|
# Schedule commits if `every` is set
|
|
228
|
-
if
|
|
229
|
-
if os.path.isfile(
|
|
166
|
+
if every is not None:
|
|
167
|
+
if os.path.isfile(resolved_local_path):
|
|
230
168
|
# If file => watch entire folder + use allow_patterns
|
|
231
|
-
folder_path = os.path.dirname(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if
|
|
235
|
-
else
|
|
169
|
+
folder_path = os.path.dirname(resolved_local_path)
|
|
170
|
+
pi = (
|
|
171
|
+
resolved_path_in_repo[: -len(resolved_local_path)]
|
|
172
|
+
if resolved_path_in_repo.endswith(resolved_local_path)
|
|
173
|
+
else resolved_path_in_repo
|
|
236
174
|
)
|
|
237
|
-
allow_patterns = [
|
|
238
|
-
ignore_patterns = []
|
|
175
|
+
allow_patterns = [resolved_local_path]
|
|
176
|
+
ignore_patterns: Optional[list[str]] = []
|
|
239
177
|
else:
|
|
240
|
-
folder_path =
|
|
241
|
-
|
|
242
|
-
allow_patterns =
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
178
|
+
folder_path = resolved_local_path
|
|
179
|
+
pi = resolved_path_in_repo
|
|
180
|
+
allow_patterns = (
|
|
181
|
+
resolved_include or []
|
|
182
|
+
if isinstance(resolved_include, list)
|
|
183
|
+
else [resolved_include]
|
|
184
|
+
if isinstance(resolved_include, str)
|
|
185
|
+
else []
|
|
186
|
+
)
|
|
187
|
+
ignore_patterns = exclude or []
|
|
188
|
+
if delete is not None and len(delete) > 0:
|
|
189
|
+
warnings.warn("Ignoring --delete when uploading with scheduled commits.")
|
|
246
190
|
|
|
247
191
|
scheduler = CommitScheduler(
|
|
248
192
|
folder_path=folder_path,
|
|
249
|
-
repo_id=
|
|
250
|
-
repo_type=
|
|
251
|
-
revision=
|
|
193
|
+
repo_id=repo_id,
|
|
194
|
+
repo_type=repo_type_str,
|
|
195
|
+
revision=revision,
|
|
252
196
|
allow_patterns=allow_patterns,
|
|
253
197
|
ignore_patterns=ignore_patterns,
|
|
254
|
-
path_in_repo=
|
|
255
|
-
private=
|
|
256
|
-
every=
|
|
257
|
-
hf_api=
|
|
198
|
+
path_in_repo=pi,
|
|
199
|
+
private=private,
|
|
200
|
+
every=every,
|
|
201
|
+
hf_api=api,
|
|
258
202
|
)
|
|
259
|
-
print(f"Scheduling commits every {
|
|
260
|
-
try:
|
|
203
|
+
print(f"Scheduling commits every {every} minutes to {scheduler.repo_id}.")
|
|
204
|
+
try:
|
|
261
205
|
while True:
|
|
262
206
|
time.sleep(100)
|
|
263
207
|
except KeyboardInterrupt:
|
|
@@ -265,52 +209,94 @@ class UploadCommand(BaseHuggingfaceCLICommand):
|
|
|
265
209
|
return "Stopped scheduled commits."
|
|
266
210
|
|
|
267
211
|
# Otherwise, create repo and proceed with the upload
|
|
268
|
-
if not os.path.isfile(
|
|
269
|
-
raise FileNotFoundError(f"No such file or directory: '{
|
|
270
|
-
|
|
271
|
-
repo_id=
|
|
272
|
-
repo_type=
|
|
212
|
+
if not os.path.isfile(resolved_local_path) and not os.path.isdir(resolved_local_path):
|
|
213
|
+
raise FileNotFoundError(f"No such file or directory: '{resolved_local_path}'.")
|
|
214
|
+
created = api.create_repo(
|
|
215
|
+
repo_id=repo_id,
|
|
216
|
+
repo_type=repo_type_str,
|
|
273
217
|
exist_ok=True,
|
|
274
|
-
private=
|
|
275
|
-
space_sdk="gradio" if
|
|
218
|
+
private=private,
|
|
219
|
+
space_sdk="gradio" if repo_type_str == "space" else None,
|
|
276
220
|
# ^ We don't want it to fail when uploading to a Space => let's set Gradio by default.
|
|
277
221
|
# ^ I'd rather not add CLI args to set it explicitly as we already have `hf repo create` for that.
|
|
278
222
|
).repo_id
|
|
279
223
|
|
|
280
224
|
# Check if branch already exists and if not, create it
|
|
281
|
-
if
|
|
225
|
+
if revision is not None and not create_pr:
|
|
282
226
|
try:
|
|
283
|
-
|
|
227
|
+
api.repo_info(repo_id=created, repo_type=repo_type_str, revision=revision)
|
|
284
228
|
except RevisionNotFoundError:
|
|
285
|
-
logger.info(f"Branch '{
|
|
286
|
-
|
|
229
|
+
logger.info(f"Branch '{revision}' not found. Creating it...")
|
|
230
|
+
api.create_branch(repo_id=created, repo_type=repo_type_str, branch=revision, exist_ok=True)
|
|
287
231
|
# ^ `exist_ok=True` to avoid race concurrency issues
|
|
288
232
|
|
|
289
233
|
# File-based upload
|
|
290
|
-
if os.path.isfile(
|
|
291
|
-
return
|
|
292
|
-
path_or_fileobj=
|
|
293
|
-
path_in_repo=
|
|
294
|
-
repo_id=
|
|
295
|
-
repo_type=
|
|
296
|
-
revision=
|
|
297
|
-
commit_message=
|
|
298
|
-
commit_description=
|
|
299
|
-
create_pr=
|
|
234
|
+
if os.path.isfile(resolved_local_path):
|
|
235
|
+
return api.upload_file(
|
|
236
|
+
path_or_fileobj=resolved_local_path,
|
|
237
|
+
path_in_repo=resolved_path_in_repo,
|
|
238
|
+
repo_id=created,
|
|
239
|
+
repo_type=repo_type_str,
|
|
240
|
+
revision=revision,
|
|
241
|
+
commit_message=commit_message,
|
|
242
|
+
commit_description=commit_description,
|
|
243
|
+
create_pr=create_pr,
|
|
300
244
|
)
|
|
301
245
|
|
|
302
246
|
# Folder-based upload
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
247
|
+
return api.upload_folder(
|
|
248
|
+
folder_path=resolved_local_path,
|
|
249
|
+
path_in_repo=resolved_path_in_repo,
|
|
250
|
+
repo_id=created,
|
|
251
|
+
repo_type=repo_type_str,
|
|
252
|
+
revision=revision,
|
|
253
|
+
commit_message=commit_message,
|
|
254
|
+
commit_description=commit_description,
|
|
255
|
+
create_pr=create_pr,
|
|
256
|
+
allow_patterns=(
|
|
257
|
+
resolved_include
|
|
258
|
+
if isinstance(resolved_include, list)
|
|
259
|
+
else [resolved_include]
|
|
260
|
+
if isinstance(resolved_include, str)
|
|
261
|
+
else None
|
|
262
|
+
),
|
|
263
|
+
ignore_patterns=exclude,
|
|
264
|
+
delete_patterns=delete,
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
if quiet:
|
|
268
|
+
disable_progress_bars()
|
|
269
|
+
with warnings.catch_warnings():
|
|
270
|
+
warnings.simplefilter("ignore")
|
|
271
|
+
print(run_upload())
|
|
272
|
+
enable_progress_bars()
|
|
273
|
+
else:
|
|
274
|
+
print(run_upload())
|
|
275
|
+
logging.set_verbosity_warning()
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _resolve_upload_paths(
|
|
279
|
+
*, repo_id: str, local_path: Optional[str], path_in_repo: Optional[str], include: Optional[list[str]]
|
|
280
|
+
) -> tuple[str, str, Optional[list[str]]]:
|
|
281
|
+
repo_name = repo_id.split("/")[-1]
|
|
282
|
+
resolved_include = include
|
|
283
|
+
|
|
284
|
+
if local_path is not None and any(c in local_path for c in ["*", "?", "["]):
|
|
285
|
+
if include is not None:
|
|
286
|
+
raise ValueError("Cannot set --include when local_path contains a wildcard.")
|
|
287
|
+
if path_in_repo is not None and path_in_repo != ".":
|
|
288
|
+
raise ValueError("Cannot set path_in_repo when local_path contains a wildcard.")
|
|
289
|
+
return ".", local_path, ["."] # will be adjusted below; placeholder for type
|
|
290
|
+
|
|
291
|
+
if local_path is None and os.path.isfile(repo_name):
|
|
292
|
+
return repo_name, repo_name, resolved_include
|
|
293
|
+
if local_path is None and os.path.isdir(repo_name):
|
|
294
|
+
return repo_name, ".", resolved_include
|
|
295
|
+
if local_path is None:
|
|
296
|
+
raise ValueError(f"'{repo_name}' is not a local file or folder. Please set local_path explicitly.")
|
|
297
|
+
|
|
298
|
+
if path_in_repo is None and os.path.isfile(local_path):
|
|
299
|
+
return local_path, os.path.basename(local_path), resolved_include
|
|
300
|
+
if path_in_repo is None:
|
|
301
|
+
return local_path, ".", resolved_include
|
|
302
|
+
return local_path, path_in_repo, resolved_include
|