huggingface-hub 1.0.0rc2__py3-none-any.whl → 1.0.0rc3__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 +4 -7
- huggingface_hub/_login.py +2 -2
- huggingface_hub/_snapshot_download.py +119 -21
- huggingface_hub/_upload_large_folder.py +1 -2
- huggingface_hub/cli/_cli_utils.py +12 -6
- huggingface_hub/cli/download.py +32 -7
- huggingface_hub/dataclasses.py +132 -3
- huggingface_hub/errors.py +4 -0
- huggingface_hub/file_download.py +216 -17
- huggingface_hub/hf_api.py +127 -14
- huggingface_hub/hf_file_system.py +38 -21
- huggingface_hub/inference/_client.py +3 -2
- huggingface_hub/inference/_generated/_async_client.py +3 -2
- huggingface_hub/inference/_generated/types/image_to_image.py +6 -2
- huggingface_hub/inference/_mcp/mcp_client.py +4 -3
- huggingface_hub/inference/_providers/__init__.py +5 -0
- huggingface_hub/inference/_providers/_common.py +1 -0
- huggingface_hub/inference/_providers/fal_ai.py +2 -0
- huggingface_hub/inference/_providers/zai_org.py +17 -0
- huggingface_hub/utils/__init__.py +1 -2
- huggingface_hub/utils/_cache_manager.py +1 -1
- huggingface_hub/utils/_http.py +10 -38
- huggingface_hub/utils/_validators.py +2 -2
- {huggingface_hub-1.0.0rc2.dist-info → huggingface_hub-1.0.0rc3.dist-info}/METADATA +1 -1
- {huggingface_hub-1.0.0rc2.dist-info → huggingface_hub-1.0.0rc3.dist-info}/RECORD +29 -43
- {huggingface_hub-1.0.0rc2.dist-info → huggingface_hub-1.0.0rc3.dist-info}/entry_points.txt +0 -1
- huggingface_hub/commands/__init__.py +0 -27
- huggingface_hub/commands/_cli_utils.py +0 -74
- huggingface_hub/commands/delete_cache.py +0 -476
- huggingface_hub/commands/download.py +0 -195
- 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 -159
- huggingface_hub/commands/upload.py +0 -318
- huggingface_hub/commands/upload_large_folder.py +0 -131
- huggingface_hub/commands/user.py +0 -207
- huggingface_hub/commands/version.py +0 -40
- {huggingface_hub-1.0.0rc2.dist-info → huggingface_hub-1.0.0rc3.dist-info}/LICENSE +0 -0
- {huggingface_hub-1.0.0rc2.dist-info → huggingface_hub-1.0.0rc3.dist-info}/WHEEL +0 -0
- {huggingface_hub-1.0.0rc2.dist-info → huggingface_hub-1.0.0rc3.dist-info}/top_level.txt +0 -0
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
# coding=utf-8
|
|
2
|
-
# Copyright 2023-present, the HuggingFace Inc. team.
|
|
3
|
-
#
|
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
# you may not use this file except in compliance with the License.
|
|
6
|
-
# You may obtain a copy of the License at
|
|
7
|
-
#
|
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
#
|
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
# See the License for the specific language governing permissions and
|
|
14
|
-
# limitations under the License.
|
|
15
|
-
"""Contains command to update or delete files in a repository using the CLI.
|
|
16
|
-
|
|
17
|
-
Usage:
|
|
18
|
-
# delete all
|
|
19
|
-
huggingface-cli repo-files <repo_id> delete "*"
|
|
20
|
-
|
|
21
|
-
# delete single file
|
|
22
|
-
huggingface-cli repo-files <repo_id> delete file.txt
|
|
23
|
-
|
|
24
|
-
# delete single folder
|
|
25
|
-
huggingface-cli repo-files <repo_id> delete folder/
|
|
26
|
-
|
|
27
|
-
# delete multiple
|
|
28
|
-
huggingface-cli repo-files <repo_id> delete file.txt folder/ file2.txt
|
|
29
|
-
|
|
30
|
-
# delete multiple patterns
|
|
31
|
-
huggingface-cli repo-files <repo_id> delete file.txt "*.json" "folder/*.parquet"
|
|
32
|
-
|
|
33
|
-
# delete from different revision / repo-type
|
|
34
|
-
huggingface-cli repo-files <repo_id> delete file.txt --revision=refs/pr/1 --repo-type=dataset
|
|
35
|
-
"""
|
|
36
|
-
|
|
37
|
-
from argparse import _SubParsersAction
|
|
38
|
-
from typing import Optional
|
|
39
|
-
|
|
40
|
-
from huggingface_hub import logging
|
|
41
|
-
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
42
|
-
from huggingface_hub.hf_api import HfApi
|
|
43
|
-
|
|
44
|
-
from ._cli_utils import show_deprecation_warning
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
logger = logging.get_logger(__name__)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class DeleteFilesSubCommand:
|
|
51
|
-
def __init__(self, args) -> None:
|
|
52
|
-
self.args = args
|
|
53
|
-
self.repo_id: str = args.repo_id
|
|
54
|
-
self.repo_type: Optional[str] = args.repo_type
|
|
55
|
-
self.revision: Optional[str] = args.revision
|
|
56
|
-
self.api: HfApi = HfApi(token=args.token, library_name="huggingface-cli")
|
|
57
|
-
self.patterns: list[str] = args.patterns
|
|
58
|
-
self.commit_message: Optional[str] = args.commit_message
|
|
59
|
-
self.commit_description: Optional[str] = args.commit_description
|
|
60
|
-
self.create_pr: bool = args.create_pr
|
|
61
|
-
self.token: Optional[str] = args.token
|
|
62
|
-
|
|
63
|
-
def run(self) -> None:
|
|
64
|
-
show_deprecation_warning("huggingface-cli repo-files", "hf repo-files")
|
|
65
|
-
|
|
66
|
-
logging.set_verbosity_info()
|
|
67
|
-
url = self.api.delete_files(
|
|
68
|
-
delete_patterns=self.patterns,
|
|
69
|
-
repo_id=self.repo_id,
|
|
70
|
-
repo_type=self.repo_type,
|
|
71
|
-
revision=self.revision,
|
|
72
|
-
commit_message=self.commit_message,
|
|
73
|
-
commit_description=self.commit_description,
|
|
74
|
-
create_pr=self.create_pr,
|
|
75
|
-
)
|
|
76
|
-
print(f"Files correctly deleted from repo. Commit: {url}.")
|
|
77
|
-
logging.set_verbosity_warning()
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
class RepoFilesCommand(BaseHuggingfaceCLICommand):
|
|
81
|
-
@staticmethod
|
|
82
|
-
def register_subcommand(parser: _SubParsersAction):
|
|
83
|
-
repo_files_parser = parser.add_parser("repo-files", help="Manage files in a repo on the Hub")
|
|
84
|
-
repo_files_parser.add_argument(
|
|
85
|
-
"repo_id", type=str, help="The ID of the repo to manage (e.g. `username/repo-name`)."
|
|
86
|
-
)
|
|
87
|
-
repo_files_subparsers = repo_files_parser.add_subparsers(
|
|
88
|
-
help="Action to execute against the files.",
|
|
89
|
-
required=True,
|
|
90
|
-
)
|
|
91
|
-
delete_subparser = repo_files_subparsers.add_parser(
|
|
92
|
-
"delete",
|
|
93
|
-
help="Delete files from a repo on the Hub",
|
|
94
|
-
)
|
|
95
|
-
delete_subparser.set_defaults(func=lambda args: DeleteFilesSubCommand(args))
|
|
96
|
-
delete_subparser.add_argument(
|
|
97
|
-
"patterns",
|
|
98
|
-
nargs="+",
|
|
99
|
-
type=str,
|
|
100
|
-
help="Glob patterns to match files to delete.",
|
|
101
|
-
)
|
|
102
|
-
delete_subparser.add_argument(
|
|
103
|
-
"--repo-type",
|
|
104
|
-
choices=["model", "dataset", "space"],
|
|
105
|
-
default="model",
|
|
106
|
-
help="Type of the repo to upload to (e.g. `dataset`).",
|
|
107
|
-
)
|
|
108
|
-
delete_subparser.add_argument(
|
|
109
|
-
"--revision",
|
|
110
|
-
type=str,
|
|
111
|
-
help=(
|
|
112
|
-
"An optional Git revision to push to. It can be a branch name "
|
|
113
|
-
"or a PR reference. If revision does not"
|
|
114
|
-
" exist and `--create-pr` is not set, a branch will be automatically created."
|
|
115
|
-
),
|
|
116
|
-
)
|
|
117
|
-
delete_subparser.add_argument(
|
|
118
|
-
"--commit-message", type=str, help="The summary / title / first line of the generated commit."
|
|
119
|
-
)
|
|
120
|
-
delete_subparser.add_argument(
|
|
121
|
-
"--commit-description", type=str, help="The description of the generated commit."
|
|
122
|
-
)
|
|
123
|
-
delete_subparser.add_argument(
|
|
124
|
-
"--create-pr", action="store_true", help="Whether to create a new Pull Request for these changes."
|
|
125
|
-
)
|
|
126
|
-
repo_files_parser.add_argument(
|
|
127
|
-
"--token",
|
|
128
|
-
type=str,
|
|
129
|
-
help="A User Access Token generated from https://huggingface.co/settings/tokens",
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
repo_files_parser.set_defaults(func=RepoFilesCommand)
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
# coding=utf-8
|
|
2
|
-
# Copyright 2022-present, the HuggingFace Inc. team.
|
|
3
|
-
#
|
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
# you may not use this file except in compliance with the License.
|
|
6
|
-
# You may obtain a copy of the License at
|
|
7
|
-
#
|
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
#
|
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
# See the License for the specific language governing permissions and
|
|
14
|
-
# limitations under the License.
|
|
15
|
-
"""Contains command to scan the HF cache directory.
|
|
16
|
-
|
|
17
|
-
Usage:
|
|
18
|
-
huggingface-cli scan-cache
|
|
19
|
-
huggingface-cli scan-cache -v
|
|
20
|
-
huggingface-cli scan-cache -vvv
|
|
21
|
-
huggingface-cli scan-cache --dir ~/.cache/huggingface/hub
|
|
22
|
-
"""
|
|
23
|
-
|
|
24
|
-
import time
|
|
25
|
-
from argparse import Namespace, _SubParsersAction
|
|
26
|
-
from typing import Optional
|
|
27
|
-
|
|
28
|
-
from ..utils import CacheNotFound, HFCacheInfo, scan_cache_dir
|
|
29
|
-
from . import BaseHuggingfaceCLICommand
|
|
30
|
-
from ._cli_utils import ANSI, show_deprecation_warning, tabulate
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class ScanCacheCommand(BaseHuggingfaceCLICommand):
|
|
34
|
-
@staticmethod
|
|
35
|
-
def register_subcommand(parser: _SubParsersAction):
|
|
36
|
-
scan_cache_parser = parser.add_parser("scan-cache", help="Scan cache directory.")
|
|
37
|
-
|
|
38
|
-
scan_cache_parser.add_argument(
|
|
39
|
-
"--dir",
|
|
40
|
-
type=str,
|
|
41
|
-
default=None,
|
|
42
|
-
help="cache directory to scan (optional). Default to the default HuggingFace cache.",
|
|
43
|
-
)
|
|
44
|
-
scan_cache_parser.add_argument(
|
|
45
|
-
"-v",
|
|
46
|
-
"--verbose",
|
|
47
|
-
action="count",
|
|
48
|
-
default=0,
|
|
49
|
-
help="show a more verbose output",
|
|
50
|
-
)
|
|
51
|
-
scan_cache_parser.set_defaults(func=ScanCacheCommand)
|
|
52
|
-
|
|
53
|
-
def __init__(self, args: Namespace) -> None:
|
|
54
|
-
self.verbosity: int = args.verbose
|
|
55
|
-
self.cache_dir: Optional[str] = args.dir
|
|
56
|
-
|
|
57
|
-
def run(self):
|
|
58
|
-
show_deprecation_warning("huggingface-cli scan-cache", "hf cache scan")
|
|
59
|
-
|
|
60
|
-
try:
|
|
61
|
-
t0 = time.time()
|
|
62
|
-
hf_cache_info = scan_cache_dir(self.cache_dir)
|
|
63
|
-
t1 = time.time()
|
|
64
|
-
except CacheNotFound as exc:
|
|
65
|
-
cache_dir = exc.cache_dir
|
|
66
|
-
print(f"Cache directory not found: {cache_dir}")
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
self._print_hf_cache_info_as_table(hf_cache_info)
|
|
70
|
-
|
|
71
|
-
print(
|
|
72
|
-
f"\nDone in {round(t1 - t0, 1)}s. Scanned {len(hf_cache_info.repos)} repo(s)"
|
|
73
|
-
f" for a total of {ANSI.red(hf_cache_info.size_on_disk_str)}."
|
|
74
|
-
)
|
|
75
|
-
if len(hf_cache_info.warnings) > 0:
|
|
76
|
-
message = f"Got {len(hf_cache_info.warnings)} warning(s) while scanning."
|
|
77
|
-
if self.verbosity >= 3:
|
|
78
|
-
print(ANSI.gray(message))
|
|
79
|
-
for warning in hf_cache_info.warnings:
|
|
80
|
-
print(ANSI.gray(str(warning)))
|
|
81
|
-
else:
|
|
82
|
-
print(ANSI.gray(message + " Use -vvv to print details."))
|
|
83
|
-
|
|
84
|
-
def _print_hf_cache_info_as_table(self, hf_cache_info: HFCacheInfo) -> None:
|
|
85
|
-
print(get_table(hf_cache_info, verbosity=self.verbosity))
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def get_table(hf_cache_info: HFCacheInfo, *, verbosity: int = 0) -> str:
|
|
89
|
-
"""Generate a table from the [`HFCacheInfo`] object.
|
|
90
|
-
|
|
91
|
-
Pass `verbosity=0` to get a table with a single row per repo, with columns
|
|
92
|
-
"repo_id", "repo_type", "size_on_disk", "nb_files", "last_accessed", "last_modified", "refs", "local_path".
|
|
93
|
-
|
|
94
|
-
Pass `verbosity=1` to get a table with a row per repo and revision (thus multiple rows can appear for a single repo), with columns
|
|
95
|
-
"repo_id", "repo_type", "revision", "size_on_disk", "nb_files", "last_modified", "refs", "local_path".
|
|
96
|
-
|
|
97
|
-
Example:
|
|
98
|
-
```py
|
|
99
|
-
>>> from huggingface_hub.utils import scan_cache_dir
|
|
100
|
-
>>> from huggingface_hub.commands.scan_cache import get_table
|
|
101
|
-
|
|
102
|
-
>>> hf_cache_info = scan_cache_dir()
|
|
103
|
-
HFCacheInfo(...)
|
|
104
|
-
|
|
105
|
-
>>> print(get_table(hf_cache_info, verbosity=0))
|
|
106
|
-
REPO ID REPO TYPE SIZE ON DISK NB FILES LAST_ACCESSED LAST_MODIFIED REFS LOCAL PATH
|
|
107
|
-
--------------------------------------------------- --------- ------------ -------- ------------- ------------- ---- --------------------------------------------------------------------------------------------------
|
|
108
|
-
roberta-base model 2.7M 5 1 day ago 1 week ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--roberta-base
|
|
109
|
-
suno/bark model 8.8K 1 1 week ago 1 week ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--suno--bark
|
|
110
|
-
t5-base model 893.8M 4 4 days ago 7 months ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--t5-base
|
|
111
|
-
t5-large model 3.0G 4 5 weeks ago 5 months ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--t5-large
|
|
112
|
-
|
|
113
|
-
>>> print(get_table(hf_cache_info, verbosity=1))
|
|
114
|
-
REPO ID REPO TYPE REVISION SIZE ON DISK NB FILES LAST_MODIFIED REFS LOCAL PATH
|
|
115
|
-
--------------------------------------------------- --------- ---------------------------------------- ------------ -------- ------------- ---- -----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
116
|
-
roberta-base model e2da8e2f811d1448a5b465c236feacd80ffbac7b 2.7M 5 1 week ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--roberta-base\\snapshots\\e2da8e2f811d1448a5b465c236feacd80ffbac7b
|
|
117
|
-
suno/bark model 70a8a7d34168586dc5d028fa9666aceade177992 8.8K 1 1 week ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--suno--bark\\snapshots\\70a8a7d34168586dc5d028fa9666aceade177992
|
|
118
|
-
t5-base model a9723ea7f1b39c1eae772870f3b547bf6ef7e6c1 893.8M 4 7 months ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--t5-base\\snapshots\\a9723ea7f1b39c1eae772870f3b547bf6ef7e6c1
|
|
119
|
-
t5-large model 150ebc2c4b72291e770f58e6057481c8d2ed331a 3.0G 4 5 months ago main C:\\Users\\admin\\.cache\\huggingface\\hub\\models--t5-large\\snapshots\\150ebc2c4b72291e770f58e6057481c8d2ed331a ```
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Args:
|
|
123
|
-
hf_cache_info ([`HFCacheInfo`]):
|
|
124
|
-
The HFCacheInfo object to print.
|
|
125
|
-
verbosity (`int`, *optional*):
|
|
126
|
-
The verbosity level. Defaults to 0.
|
|
127
|
-
|
|
128
|
-
Returns:
|
|
129
|
-
`str`: The table as a string.
|
|
130
|
-
"""
|
|
131
|
-
if verbosity == 0:
|
|
132
|
-
return tabulate(
|
|
133
|
-
rows=[
|
|
134
|
-
[
|
|
135
|
-
repo.repo_id,
|
|
136
|
-
repo.repo_type,
|
|
137
|
-
"{:>12}".format(repo.size_on_disk_str),
|
|
138
|
-
repo.nb_files,
|
|
139
|
-
repo.last_accessed_str,
|
|
140
|
-
repo.last_modified_str,
|
|
141
|
-
", ".join(sorted(repo.refs)),
|
|
142
|
-
str(repo.repo_path),
|
|
143
|
-
]
|
|
144
|
-
for repo in sorted(hf_cache_info.repos, key=lambda repo: repo.repo_path)
|
|
145
|
-
],
|
|
146
|
-
headers=[
|
|
147
|
-
"REPO ID",
|
|
148
|
-
"REPO TYPE",
|
|
149
|
-
"SIZE ON DISK",
|
|
150
|
-
"NB FILES",
|
|
151
|
-
"LAST_ACCESSED",
|
|
152
|
-
"LAST_MODIFIED",
|
|
153
|
-
"REFS",
|
|
154
|
-
"LOCAL PATH",
|
|
155
|
-
],
|
|
156
|
-
)
|
|
157
|
-
else:
|
|
158
|
-
return tabulate(
|
|
159
|
-
rows=[
|
|
160
|
-
[
|
|
161
|
-
repo.repo_id,
|
|
162
|
-
repo.repo_type,
|
|
163
|
-
revision.commit_hash,
|
|
164
|
-
"{:>12}".format(revision.size_on_disk_str),
|
|
165
|
-
revision.nb_files,
|
|
166
|
-
revision.last_modified_str,
|
|
167
|
-
", ".join(sorted(revision.refs)),
|
|
168
|
-
str(revision.snapshot_path),
|
|
169
|
-
]
|
|
170
|
-
for repo in sorted(hf_cache_info.repos, key=lambda repo: repo.repo_path)
|
|
171
|
-
for revision in sorted(repo.revisions, key=lambda revision: revision.commit_hash)
|
|
172
|
-
],
|
|
173
|
-
headers=[
|
|
174
|
-
"REPO ID",
|
|
175
|
-
"REPO TYPE",
|
|
176
|
-
"REVISION",
|
|
177
|
-
"SIZE ON DISK",
|
|
178
|
-
"NB FILES",
|
|
179
|
-
"LAST_MODIFIED",
|
|
180
|
-
"REFS",
|
|
181
|
-
"LOCAL PATH",
|
|
182
|
-
],
|
|
183
|
-
)
|
huggingface_hub/commands/tag.py
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
# coding=utf-8
|
|
2
|
-
# Copyright 2024-present, the HuggingFace Inc. team.
|
|
3
|
-
#
|
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
# you may not use this file except in compliance with the License.
|
|
6
|
-
# You may obtain a copy of the License at
|
|
7
|
-
#
|
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
#
|
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
# See the License for the specific language governing permissions and
|
|
14
|
-
# limitations under the License.
|
|
15
|
-
|
|
16
|
-
"""Contains commands to perform tag management with the CLI.
|
|
17
|
-
|
|
18
|
-
Usage Examples:
|
|
19
|
-
- Create a tag:
|
|
20
|
-
$ huggingface-cli tag user/my-model 1.0 --message "First release"
|
|
21
|
-
$ huggingface-cli tag user/my-model 1.0 -m "First release" --revision develop
|
|
22
|
-
$ huggingface-cli tag user/my-dataset 1.0 -m "First release" --repo-type dataset
|
|
23
|
-
$ huggingface-cli tag user/my-space 1.0
|
|
24
|
-
- List all tags:
|
|
25
|
-
$ huggingface-cli tag -l user/my-model
|
|
26
|
-
$ huggingface-cli tag --list user/my-dataset --repo-type dataset
|
|
27
|
-
- Delete a tag:
|
|
28
|
-
$ huggingface-cli tag -d user/my-model 1.0
|
|
29
|
-
$ huggingface-cli tag --delete user/my-dataset 1.0 --repo-type dataset
|
|
30
|
-
$ huggingface-cli tag -d user/my-space 1.0 -y
|
|
31
|
-
"""
|
|
32
|
-
|
|
33
|
-
from argparse import Namespace, _SubParsersAction
|
|
34
|
-
|
|
35
|
-
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
36
|
-
from huggingface_hub.constants import (
|
|
37
|
-
REPO_TYPES,
|
|
38
|
-
)
|
|
39
|
-
from huggingface_hub.hf_api import HfApi
|
|
40
|
-
|
|
41
|
-
from ..errors import HfHubHTTPError, RepositoryNotFoundError, RevisionNotFoundError
|
|
42
|
-
from ._cli_utils import ANSI, show_deprecation_warning
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
class TagCommands(BaseHuggingfaceCLICommand):
|
|
46
|
-
@staticmethod
|
|
47
|
-
def register_subcommand(parser: _SubParsersAction):
|
|
48
|
-
tag_parser = parser.add_parser("tag", help="(create, list, delete) tags for a repo in the hub")
|
|
49
|
-
|
|
50
|
-
tag_parser.add_argument("repo_id", type=str, help="The ID of the repo to tag (e.g. `username/repo-name`).")
|
|
51
|
-
tag_parser.add_argument("tag", nargs="?", type=str, help="The name of the tag for creation or deletion.")
|
|
52
|
-
tag_parser.add_argument("-m", "--message", type=str, help="The description of the tag to create.")
|
|
53
|
-
tag_parser.add_argument("--revision", type=str, help="The git revision to tag.")
|
|
54
|
-
tag_parser.add_argument(
|
|
55
|
-
"--token", type=str, help="A User Access Token generated from https://huggingface.co/settings/tokens."
|
|
56
|
-
)
|
|
57
|
-
tag_parser.add_argument(
|
|
58
|
-
"--repo-type",
|
|
59
|
-
choices=["model", "dataset", "space"],
|
|
60
|
-
default="model",
|
|
61
|
-
help="Set the type of repository (model, dataset, or space).",
|
|
62
|
-
)
|
|
63
|
-
tag_parser.add_argument("-y", "--yes", action="store_true", help="Answer Yes to prompts automatically.")
|
|
64
|
-
|
|
65
|
-
tag_parser.add_argument("-l", "--list", action="store_true", help="List tags for a repository.")
|
|
66
|
-
tag_parser.add_argument("-d", "--delete", action="store_true", help="Delete a tag for a repository.")
|
|
67
|
-
|
|
68
|
-
tag_parser.set_defaults(func=lambda args: handle_commands(args))
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def handle_commands(args: Namespace):
|
|
72
|
-
show_deprecation_warning("huggingface-cli tag", "hf repo tag")
|
|
73
|
-
|
|
74
|
-
if args.list:
|
|
75
|
-
return TagListCommand(args)
|
|
76
|
-
elif args.delete:
|
|
77
|
-
return TagDeleteCommand(args)
|
|
78
|
-
else:
|
|
79
|
-
return TagCreateCommand(args)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
class TagCommand:
|
|
83
|
-
def __init__(self, args: Namespace):
|
|
84
|
-
self.args = args
|
|
85
|
-
self.api = HfApi(token=self.args.token)
|
|
86
|
-
self.repo_id = self.args.repo_id
|
|
87
|
-
self.repo_type = self.args.repo_type
|
|
88
|
-
if self.repo_type not in REPO_TYPES:
|
|
89
|
-
print("Invalid repo --repo-type")
|
|
90
|
-
exit(1)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
class TagCreateCommand(TagCommand):
|
|
94
|
-
def run(self):
|
|
95
|
-
print(f"You are about to create tag {ANSI.bold(self.args.tag)} on {self.repo_type} {ANSI.bold(self.repo_id)}")
|
|
96
|
-
|
|
97
|
-
try:
|
|
98
|
-
self.api.create_tag(
|
|
99
|
-
repo_id=self.repo_id,
|
|
100
|
-
tag=self.args.tag,
|
|
101
|
-
tag_message=self.args.message,
|
|
102
|
-
revision=self.args.revision,
|
|
103
|
-
repo_type=self.repo_type,
|
|
104
|
-
)
|
|
105
|
-
except RepositoryNotFoundError:
|
|
106
|
-
print(f"{self.repo_type.capitalize()} {ANSI.bold(self.repo_id)} not found.")
|
|
107
|
-
exit(1)
|
|
108
|
-
except RevisionNotFoundError:
|
|
109
|
-
print(f"Revision {ANSI.bold(self.args.revision)} not found.")
|
|
110
|
-
exit(1)
|
|
111
|
-
except HfHubHTTPError as e:
|
|
112
|
-
if e.response.status_code == 409:
|
|
113
|
-
print(f"Tag {ANSI.bold(self.args.tag)} already exists on {ANSI.bold(self.repo_id)}")
|
|
114
|
-
exit(1)
|
|
115
|
-
raise e
|
|
116
|
-
|
|
117
|
-
print(f"Tag {ANSI.bold(self.args.tag)} created on {ANSI.bold(self.repo_id)}")
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
class TagListCommand(TagCommand):
|
|
121
|
-
def run(self):
|
|
122
|
-
try:
|
|
123
|
-
refs = self.api.list_repo_refs(
|
|
124
|
-
repo_id=self.repo_id,
|
|
125
|
-
repo_type=self.repo_type,
|
|
126
|
-
)
|
|
127
|
-
except RepositoryNotFoundError:
|
|
128
|
-
print(f"{self.repo_type.capitalize()} {ANSI.bold(self.repo_id)} not found.")
|
|
129
|
-
exit(1)
|
|
130
|
-
except HfHubHTTPError as e:
|
|
131
|
-
print(e)
|
|
132
|
-
print(ANSI.red(e.response.text))
|
|
133
|
-
exit(1)
|
|
134
|
-
if len(refs.tags) == 0:
|
|
135
|
-
print("No tags found")
|
|
136
|
-
exit(0)
|
|
137
|
-
print(f"Tags for {self.repo_type} {ANSI.bold(self.repo_id)}:")
|
|
138
|
-
for tag in refs.tags:
|
|
139
|
-
print(tag.name)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
class TagDeleteCommand(TagCommand):
|
|
143
|
-
def run(self):
|
|
144
|
-
print(f"You are about to delete tag {ANSI.bold(self.args.tag)} on {self.repo_type} {ANSI.bold(self.repo_id)}")
|
|
145
|
-
|
|
146
|
-
if not self.args.yes:
|
|
147
|
-
choice = input("Proceed? [Y/n] ").lower()
|
|
148
|
-
if choice not in ("", "y", "yes"):
|
|
149
|
-
print("Abort")
|
|
150
|
-
exit()
|
|
151
|
-
try:
|
|
152
|
-
self.api.delete_tag(repo_id=self.repo_id, tag=self.args.tag, repo_type=self.repo_type)
|
|
153
|
-
except RepositoryNotFoundError:
|
|
154
|
-
print(f"{self.repo_type.capitalize()} {ANSI.bold(self.repo_id)} not found.")
|
|
155
|
-
exit(1)
|
|
156
|
-
except RevisionNotFoundError:
|
|
157
|
-
print(f"Tag {ANSI.bold(self.args.tag)} not found on {ANSI.bold(self.repo_id)}")
|
|
158
|
-
exit(1)
|
|
159
|
-
print(f"Tag {ANSI.bold(self.args.tag)} deleted on {ANSI.bold(self.repo_id)}")
|