huggingface-hub 0.36.0__py3-none-any.whl → 1.0.0__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 +33 -45
- huggingface_hub/_commit_api.py +39 -43
- 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 +17 -43
- huggingface_hub/_oauth.py +8 -8
- huggingface_hub/_snapshot_download.py +135 -50
- huggingface_hub/_space_api.py +4 -4
- huggingface_hub/_tensorboard_logger.py +5 -5
- huggingface_hub/_upload_large_folder.py +18 -32
- 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 +143 -39
- huggingface_hub/cli/auth.py +105 -171
- huggingface_hub/cli/cache.py +594 -361
- huggingface_hub/cli/download.py +120 -112
- huggingface_hub/cli/hf.py +38 -41
- huggingface_hub/cli/jobs.py +689 -1017
- huggingface_hub/cli/lfs.py +120 -143
- huggingface_hub/cli/repo.py +282 -216
- huggingface_hub/cli/repo_files.py +50 -84
- huggingface_hub/cli/system.py +6 -25
- huggingface_hub/cli/upload.py +198 -220
- huggingface_hub/cli/upload_large_folder.py +91 -106
- huggingface_hub/community.py +5 -5
- huggingface_hub/constants.py +17 -52
- huggingface_hub/dataclasses.py +135 -21
- huggingface_hub/errors.py +47 -30
- huggingface_hub/fastai_utils.py +8 -9
- huggingface_hub/file_download.py +351 -303
- huggingface_hub/hf_api.py +398 -570
- huggingface_hub/hf_file_system.py +101 -66
- huggingface_hub/hub_mixin.py +32 -54
- huggingface_hub/inference/_client.py +177 -162
- huggingface_hub/inference/_common.py +38 -54
- huggingface_hub/inference/_generated/_async_client.py +218 -258
- 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 +12 -4
- huggingface_hub/inference/_providers/_common.py +62 -24
- 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 +21 -94
- huggingface_hub/repocard.py +15 -16
- huggingface_hub/repocard_data.py +57 -57
- 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 +11 -6
- huggingface_hub/utils/_auth.py +5 -5
- huggingface_hub/utils/_cache_manager.py +49 -74
- 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 +371 -208
- huggingface_hub/utils/_pagination.py +4 -4
- huggingface_hub/utils/_parsing.py +98 -0
- huggingface_hub/utils/_paths.py +5 -5
- huggingface_hub/utils/_runtime.py +59 -23
- huggingface_hub/utils/_safetensors.py +21 -21
- huggingface_hub/utils/_subprocess.py +9 -9
- huggingface_hub/utils/_telemetry.py +3 -3
- huggingface_hub/{commands/_cli_utils.py → utils/_terminal.py} +4 -9
- 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.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/METADATA +16 -35
- huggingface_hub-1.0.0.dist-info/RECORD +152 -0
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/entry_points.txt +0 -1
- huggingface_hub/commands/__init__.py +0 -27
- huggingface_hub/commands/delete_cache.py +0 -476
- huggingface_hub/commands/download.py +0 -204
- huggingface_hub/commands/env.py +0 -39
- huggingface_hub/commands/huggingface_cli.py +0 -65
- huggingface_hub/commands/lfs.py +0 -200
- huggingface_hub/commands/repo.py +0 -151
- huggingface_hub/commands/repo_files.py +0 -132
- huggingface_hub/commands/scan_cache.py +0 -183
- huggingface_hub/commands/tag.py +0 -161
- huggingface_hub/commands/upload.py +0 -318
- huggingface_hub/commands/upload_large_folder.py +0 -131
- huggingface_hub/commands/user.py +0 -208
- huggingface_hub/commands/version.py +0 -40
- huggingface_hub/inference_api.py +0 -217
- huggingface_hub/keras_mixin.py +0 -497
- huggingface_hub/repository.py +0 -1471
- huggingface_hub/serialization/_tensorflow.py +0 -92
- huggingface_hub/utils/_hf_folder.py +0 -68
- huggingface_hub-0.36.0.dist-info/RECORD +0 -170
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/top_level.txt +0 -0
huggingface_hub/cli/repo.py
CHANGED
|
@@ -21,229 +21,295 @@ Usage:
|
|
|
21
21
|
hf repo create my-cool-model --private
|
|
22
22
|
"""
|
|
23
23
|
|
|
24
|
-
import
|
|
25
|
-
from
|
|
26
|
-
from typing import Optional
|
|
24
|
+
import enum
|
|
25
|
+
from typing import Annotated, Optional
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
import typer
|
|
29
28
|
|
|
30
|
-
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
31
|
-
from huggingface_hub.commands._cli_utils import ANSI
|
|
32
|
-
from huggingface_hub.constants import REPO_TYPES, SPACES_SDK_TYPES
|
|
33
29
|
from huggingface_hub.errors import HfHubHTTPError, RepositoryNotFoundError, RevisionNotFoundError
|
|
34
|
-
from huggingface_hub.
|
|
35
|
-
|
|
30
|
+
from huggingface_hub.utils import ANSI, logging
|
|
31
|
+
|
|
32
|
+
from ._cli_utils import (
|
|
33
|
+
PrivateOpt,
|
|
34
|
+
RepoIdArg,
|
|
35
|
+
RepoType,
|
|
36
|
+
RepoTypeOpt,
|
|
37
|
+
RevisionOpt,
|
|
38
|
+
TokenOpt,
|
|
39
|
+
get_hf_api,
|
|
40
|
+
typer_factory,
|
|
41
|
+
)
|
|
36
42
|
|
|
37
43
|
|
|
38
44
|
logger = logging.get_logger(__name__)
|
|
39
45
|
|
|
46
|
+
repo_cli = typer_factory(help="Manage repos on the Hub.")
|
|
47
|
+
tag_cli = typer_factory(help="Manage tags for a repo on the Hub.")
|
|
48
|
+
branch_cli = typer_factory(help="Manage branches for a repo on the Hub.")
|
|
49
|
+
repo_cli.add_typer(tag_cli, name="tag")
|
|
50
|
+
repo_cli.add_typer(branch_cli, name="branch")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class GatedChoices(str, enum.Enum):
|
|
54
|
+
auto = "auto"
|
|
55
|
+
manual = "manual"
|
|
56
|
+
false = "false"
|
|
40
57
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
repo_create_parser.add_argument(
|
|
58
|
-
"--repo-type",
|
|
59
|
-
type=str,
|
|
60
|
-
help='Optional: set to "dataset" or "space" if creating a dataset or space, default is model.',
|
|
61
|
-
)
|
|
62
|
-
repo_create_parser.add_argument(
|
|
63
|
-
"--space_sdk",
|
|
64
|
-
type=str,
|
|
65
|
-
help='Optional: Hugging Face Spaces SDK type. Required when --type is set to "space".',
|
|
66
|
-
choices=SPACES_SDK_TYPES,
|
|
67
|
-
)
|
|
68
|
-
repo_create_parser.add_argument(
|
|
69
|
-
"--private",
|
|
70
|
-
action="store_true",
|
|
71
|
-
help="Whether to create a private repository. Defaults to public unless the organization's default is private.",
|
|
72
|
-
)
|
|
73
|
-
repo_create_parser.add_argument(
|
|
74
|
-
"--token",
|
|
75
|
-
type=str,
|
|
76
|
-
help="Hugging Face token. Will default to the locally saved token if not provided.",
|
|
77
|
-
)
|
|
78
|
-
repo_create_parser.add_argument(
|
|
79
|
-
"--exist-ok",
|
|
80
|
-
action="store_true",
|
|
58
|
+
|
|
59
|
+
@repo_cli.command("create", help="Create a new repo on the Hub.")
|
|
60
|
+
def repo_create(
|
|
61
|
+
repo_id: RepoIdArg,
|
|
62
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
63
|
+
space_sdk: Annotated[
|
|
64
|
+
Optional[str],
|
|
65
|
+
typer.Option(
|
|
66
|
+
help="Hugging Face Spaces SDK type. Required when --type is set to 'space'.",
|
|
67
|
+
),
|
|
68
|
+
] = None,
|
|
69
|
+
private: PrivateOpt = False,
|
|
70
|
+
token: TokenOpt = None,
|
|
71
|
+
exist_ok: Annotated[
|
|
72
|
+
bool,
|
|
73
|
+
typer.Option(
|
|
81
74
|
help="Do not raise an error if repo already exists.",
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
),
|
|
76
|
+
] = False,
|
|
77
|
+
resource_group_id: Annotated[
|
|
78
|
+
Optional[str],
|
|
79
|
+
typer.Option(
|
|
86
80
|
help="Resource group in which to create the repo. Resource groups is only available for Enterprise Hub organizations.",
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
81
|
+
),
|
|
82
|
+
] = None,
|
|
83
|
+
) -> None:
|
|
84
|
+
api = get_hf_api(token=token)
|
|
85
|
+
repo_url = api.create_repo(
|
|
86
|
+
repo_id=repo_id,
|
|
87
|
+
repo_type=repo_type.value,
|
|
88
|
+
private=private,
|
|
89
|
+
token=token,
|
|
90
|
+
exist_ok=exist_ok,
|
|
91
|
+
resource_group_id=resource_group_id,
|
|
92
|
+
space_sdk=space_sdk,
|
|
93
|
+
)
|
|
94
|
+
print(f"Successfully created {ANSI.bold(repo_url.repo_id)} on the Hub.")
|
|
95
|
+
print(f"Your repo is now available at {ANSI.bold(repo_url)}")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@repo_cli.command("delete", help="Delete a repo from the Hub. this is an irreversible operation.")
|
|
99
|
+
def repo_delete(
|
|
100
|
+
repo_id: RepoIdArg,
|
|
101
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
102
|
+
token: TokenOpt = None,
|
|
103
|
+
missing_ok: Annotated[
|
|
104
|
+
bool,
|
|
105
|
+
typer.Option(
|
|
106
|
+
help="If set to True, do not raise an error if repo does not exist.",
|
|
107
|
+
),
|
|
108
|
+
] = False,
|
|
109
|
+
) -> None:
|
|
110
|
+
api = get_hf_api(token=token)
|
|
111
|
+
api.delete_repo(
|
|
112
|
+
repo_id=repo_id,
|
|
113
|
+
repo_type=repo_type.value,
|
|
114
|
+
missing_ok=missing_ok,
|
|
115
|
+
)
|
|
116
|
+
print(f"Successfully deleted {ANSI.bold(repo_id)} on the Hub.")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
@repo_cli.command("move", help="Move a repository from a namespace to another namespace.")
|
|
120
|
+
def repo_move(
|
|
121
|
+
from_id: RepoIdArg,
|
|
122
|
+
to_id: RepoIdArg,
|
|
123
|
+
token: TokenOpt = None,
|
|
124
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
125
|
+
) -> None:
|
|
126
|
+
api = get_hf_api(token=token)
|
|
127
|
+
api.move_repo(
|
|
128
|
+
from_id=from_id,
|
|
129
|
+
to_id=to_id,
|
|
130
|
+
repo_type=repo_type.value,
|
|
131
|
+
)
|
|
132
|
+
print(f"Successfully moved {ANSI.bold(from_id)} to {ANSI.bold(to_id)} on the Hub.")
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@repo_cli.command("settings", help="Update the settings of a repository.")
|
|
136
|
+
def repo_settings(
|
|
137
|
+
repo_id: RepoIdArg,
|
|
138
|
+
gated: Annotated[
|
|
139
|
+
Optional[GatedChoices],
|
|
140
|
+
typer.Option(
|
|
141
|
+
help="The gated status for the repository.",
|
|
142
|
+
),
|
|
143
|
+
] = None,
|
|
144
|
+
private: Annotated[
|
|
145
|
+
Optional[bool],
|
|
146
|
+
typer.Option(
|
|
147
|
+
help="Whether the repository should be private.",
|
|
148
|
+
),
|
|
149
|
+
] = None,
|
|
150
|
+
token: TokenOpt = None,
|
|
151
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
152
|
+
) -> None:
|
|
153
|
+
api = get_hf_api(token=token)
|
|
154
|
+
api.update_repo_settings(
|
|
155
|
+
repo_id=repo_id,
|
|
156
|
+
gated=(gated.value if gated else None), # type: ignore [arg-type]
|
|
157
|
+
private=private,
|
|
158
|
+
repo_type=repo_type.value,
|
|
159
|
+
)
|
|
160
|
+
print(f"Successfully updated the settings of {ANSI.bold(repo_id)} on the Hub.")
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
@branch_cli.command("create", help="Create a new branch for a repo on the Hub.")
|
|
164
|
+
def branch_create(
|
|
165
|
+
repo_id: RepoIdArg,
|
|
166
|
+
branch: Annotated[
|
|
167
|
+
str,
|
|
168
|
+
typer.Argument(
|
|
169
|
+
help="The name of the branch to create.",
|
|
170
|
+
),
|
|
171
|
+
],
|
|
172
|
+
revision: RevisionOpt = None,
|
|
173
|
+
token: TokenOpt = None,
|
|
174
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
175
|
+
exist_ok: Annotated[
|
|
176
|
+
bool,
|
|
177
|
+
typer.Option(
|
|
178
|
+
help="If set to True, do not raise an error if branch already exists.",
|
|
179
|
+
),
|
|
180
|
+
] = False,
|
|
181
|
+
) -> None:
|
|
182
|
+
api = get_hf_api(token=token)
|
|
183
|
+
api.create_branch(
|
|
184
|
+
repo_id=repo_id,
|
|
185
|
+
branch=branch,
|
|
186
|
+
revision=revision,
|
|
187
|
+
repo_type=repo_type.value,
|
|
188
|
+
exist_ok=exist_ok,
|
|
189
|
+
)
|
|
190
|
+
print(f"Successfully created {ANSI.bold(branch)} branch on {repo_type.value} {ANSI.bold(repo_id)}")
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
@branch_cli.command("delete", help="Delete a branch from a repo on the Hub.")
|
|
194
|
+
def branch_delete(
|
|
195
|
+
repo_id: RepoIdArg,
|
|
196
|
+
branch: Annotated[
|
|
197
|
+
str,
|
|
198
|
+
typer.Argument(
|
|
199
|
+
help="The name of the branch to delete.",
|
|
200
|
+
),
|
|
201
|
+
],
|
|
202
|
+
token: TokenOpt = None,
|
|
203
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
204
|
+
) -> None:
|
|
205
|
+
api = get_hf_api(token=token)
|
|
206
|
+
api.delete_branch(
|
|
207
|
+
repo_id=repo_id,
|
|
208
|
+
branch=branch,
|
|
209
|
+
repo_type=repo_type.value,
|
|
210
|
+
)
|
|
211
|
+
print(f"Successfully deleted {ANSI.bold(branch)} branch on {repo_type.value} {ANSI.bold(repo_id)}")
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
@tag_cli.command("create", help="Create a tag for a repo.")
|
|
215
|
+
def tag_create(
|
|
216
|
+
repo_id: RepoIdArg,
|
|
217
|
+
tag: Annotated[
|
|
218
|
+
str,
|
|
219
|
+
typer.Argument(
|
|
220
|
+
help="The name of the tag to create.",
|
|
221
|
+
),
|
|
222
|
+
],
|
|
223
|
+
message: Annotated[
|
|
224
|
+
Optional[str],
|
|
225
|
+
typer.Option(
|
|
226
|
+
"-m",
|
|
227
|
+
"--message",
|
|
228
|
+
help="The description of the tag to create.",
|
|
229
|
+
),
|
|
230
|
+
] = None,
|
|
231
|
+
revision: RevisionOpt = None,
|
|
232
|
+
token: TokenOpt = None,
|
|
233
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
234
|
+
) -> None:
|
|
235
|
+
repo_type_str = repo_type.value
|
|
236
|
+
api = get_hf_api(token=token)
|
|
237
|
+
print(f"You are about to create tag {ANSI.bold(tag)} on {repo_type_str} {ANSI.bold(repo_id)}")
|
|
238
|
+
try:
|
|
239
|
+
api.create_tag(repo_id=repo_id, tag=tag, tag_message=message, revision=revision, repo_type=repo_type_str)
|
|
240
|
+
except RepositoryNotFoundError:
|
|
241
|
+
print(f"{repo_type_str.capitalize()} {ANSI.bold(repo_id)} not found.")
|
|
242
|
+
raise typer.Exit(code=1)
|
|
243
|
+
except RevisionNotFoundError:
|
|
244
|
+
print(f"Revision {ANSI.bold(str(revision))} not found.")
|
|
245
|
+
raise typer.Exit(code=1)
|
|
246
|
+
except HfHubHTTPError as e:
|
|
247
|
+
if e.response.status_code == 409:
|
|
248
|
+
print(f"Tag {ANSI.bold(tag)} already exists on {ANSI.bold(repo_id)}")
|
|
249
|
+
raise typer.Exit(code=1)
|
|
250
|
+
raise e
|
|
251
|
+
print(f"Tag {ANSI.bold(tag)} created on {ANSI.bold(repo_id)}")
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@tag_cli.command("list", help="List tags for a repo.")
|
|
255
|
+
def tag_list(
|
|
256
|
+
repo_id: RepoIdArg,
|
|
257
|
+
token: TokenOpt = None,
|
|
258
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
259
|
+
) -> None:
|
|
260
|
+
repo_type_str = repo_type.value
|
|
261
|
+
api = get_hf_api(token=token)
|
|
262
|
+
try:
|
|
263
|
+
refs = api.list_repo_refs(repo_id=repo_id, repo_type=repo_type_str)
|
|
264
|
+
except RepositoryNotFoundError:
|
|
265
|
+
print(f"{repo_type_str.capitalize()} {ANSI.bold(repo_id)} not found.")
|
|
266
|
+
raise typer.Exit(code=1)
|
|
267
|
+
except HfHubHTTPError as e:
|
|
268
|
+
print(e)
|
|
269
|
+
print(ANSI.red(e.response.text))
|
|
270
|
+
raise typer.Exit(code=1)
|
|
271
|
+
if len(refs.tags) == 0:
|
|
272
|
+
print("No tags found")
|
|
273
|
+
raise typer.Exit(code=0)
|
|
274
|
+
print(f"Tags for {repo_type_str} {ANSI.bold(repo_id)}:")
|
|
275
|
+
for t in refs.tags:
|
|
276
|
+
print(t.name)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
@tag_cli.command("delete", help="Delete a tag for a repo.")
|
|
280
|
+
def tag_delete(
|
|
281
|
+
repo_id: RepoIdArg,
|
|
282
|
+
tag: Annotated[
|
|
283
|
+
str,
|
|
284
|
+
typer.Argument(
|
|
285
|
+
help="The name of the tag to delete.",
|
|
286
|
+
),
|
|
287
|
+
],
|
|
288
|
+
yes: Annotated[
|
|
289
|
+
bool,
|
|
290
|
+
typer.Option(
|
|
291
|
+
"-y",
|
|
292
|
+
"--yes",
|
|
293
|
+
help="Answer Yes to prompt automatically",
|
|
294
|
+
),
|
|
295
|
+
] = False,
|
|
296
|
+
token: TokenOpt = None,
|
|
297
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
298
|
+
) -> None:
|
|
299
|
+
repo_type_str = repo_type.value
|
|
300
|
+
print(f"You are about to delete tag {ANSI.bold(tag)} on {repo_type_str} {ANSI.bold(repo_id)}")
|
|
301
|
+
if not yes:
|
|
302
|
+
choice = input("Proceed? [Y/n] ").lower()
|
|
303
|
+
if choice not in ("", "y", "yes"):
|
|
304
|
+
print("Abort")
|
|
305
|
+
raise typer.Exit()
|
|
306
|
+
api = get_hf_api(token=token)
|
|
307
|
+
try:
|
|
308
|
+
api.delete_tag(repo_id=repo_id, tag=tag, repo_type=repo_type_str)
|
|
309
|
+
except RepositoryNotFoundError:
|
|
310
|
+
print(f"{repo_type_str.capitalize()} {ANSI.bold(repo_id)} not found.")
|
|
311
|
+
raise typer.Exit(code=1)
|
|
312
|
+
except RevisionNotFoundError:
|
|
313
|
+
print(f"Tag {ANSI.bold(tag)} not found on {ANSI.bold(repo_id)}")
|
|
314
|
+
raise typer.Exit(code=1)
|
|
315
|
+
print(f"Tag {ANSI.bold(tag)} deleted on {ANSI.bold(repo_id)}")
|