huggingface-hub 0.33.5__py3-none-any.whl → 0.34.0rc0__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 +487 -525
- huggingface_hub/_commit_api.py +21 -28
- huggingface_hub/_jobs_api.py +145 -0
- huggingface_hub/_local_folder.py +7 -1
- huggingface_hub/_login.py +5 -5
- huggingface_hub/_oauth.py +1 -1
- huggingface_hub/_snapshot_download.py +11 -6
- huggingface_hub/_upload_large_folder.py +46 -23
- huggingface_hub/cli/__init__.py +27 -0
- huggingface_hub/cli/_cli_utils.py +69 -0
- huggingface_hub/cli/auth.py +210 -0
- huggingface_hub/cli/cache.py +405 -0
- huggingface_hub/cli/download.py +181 -0
- huggingface_hub/cli/hf.py +66 -0
- huggingface_hub/cli/jobs.py +522 -0
- huggingface_hub/cli/lfs.py +198 -0
- huggingface_hub/cli/repo.py +243 -0
- huggingface_hub/cli/repo_files.py +128 -0
- huggingface_hub/cli/system.py +52 -0
- huggingface_hub/cli/upload.py +316 -0
- huggingface_hub/cli/upload_large_folder.py +132 -0
- huggingface_hub/commands/_cli_utils.py +5 -0
- huggingface_hub/commands/delete_cache.py +3 -1
- huggingface_hub/commands/download.py +4 -0
- huggingface_hub/commands/env.py +3 -0
- huggingface_hub/commands/huggingface_cli.py +2 -0
- huggingface_hub/commands/repo.py +4 -0
- huggingface_hub/commands/repo_files.py +4 -0
- huggingface_hub/commands/scan_cache.py +3 -1
- huggingface_hub/commands/tag.py +3 -1
- huggingface_hub/commands/upload.py +4 -0
- huggingface_hub/commands/upload_large_folder.py +3 -1
- huggingface_hub/commands/user.py +11 -1
- huggingface_hub/commands/version.py +3 -0
- huggingface_hub/constants.py +1 -0
- huggingface_hub/file_download.py +16 -5
- huggingface_hub/hf_api.py +519 -7
- huggingface_hub/hf_file_system.py +8 -16
- huggingface_hub/hub_mixin.py +3 -3
- huggingface_hub/inference/_client.py +38 -39
- huggingface_hub/inference/_common.py +38 -11
- huggingface_hub/inference/_generated/_async_client.py +50 -51
- huggingface_hub/inference/_generated/types/__init__.py +1 -0
- huggingface_hub/inference/_generated/types/image_to_video.py +60 -0
- huggingface_hub/inference/_mcp/cli.py +36 -18
- huggingface_hub/inference/_mcp/constants.py +8 -0
- huggingface_hub/inference/_mcp/types.py +3 -0
- huggingface_hub/inference/_providers/__init__.py +4 -1
- huggingface_hub/inference/_providers/_common.py +3 -6
- huggingface_hub/inference/_providers/fal_ai.py +85 -42
- huggingface_hub/inference/_providers/hf_inference.py +17 -9
- huggingface_hub/inference/_providers/replicate.py +19 -1
- huggingface_hub/keras_mixin.py +2 -2
- huggingface_hub/repocard.py +1 -1
- huggingface_hub/repository.py +2 -2
- huggingface_hub/utils/_auth.py +1 -1
- huggingface_hub/utils/_cache_manager.py +2 -2
- huggingface_hub/utils/_dotenv.py +51 -0
- huggingface_hub/utils/_headers.py +1 -1
- huggingface_hub/utils/_runtime.py +1 -1
- huggingface_hub/utils/_xet.py +6 -2
- huggingface_hub/utils/_xet_progress_reporting.py +141 -0
- {huggingface_hub-0.33.5.dist-info → huggingface_hub-0.34.0rc0.dist-info}/METADATA +7 -8
- {huggingface_hub-0.33.5.dist-info → huggingface_hub-0.34.0rc0.dist-info}/RECORD +68 -51
- {huggingface_hub-0.33.5.dist-info → huggingface_hub-0.34.0rc0.dist-info}/entry_points.txt +1 -0
- {huggingface_hub-0.33.5.dist-info → huggingface_hub-0.34.0rc0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.33.5.dist-info → huggingface_hub-0.34.0rc0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.33.5.dist-info → huggingface_hub-0.34.0rc0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 202-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 download files from the Hub with the CLI.
|
|
16
|
+
|
|
17
|
+
Usage:
|
|
18
|
+
hf download --help
|
|
19
|
+
|
|
20
|
+
# Download file
|
|
21
|
+
hf download gpt2 config.json
|
|
22
|
+
|
|
23
|
+
# Download entire repo
|
|
24
|
+
hf download fffiloni/zeroscope --repo-type=space --revision=refs/pr/78
|
|
25
|
+
|
|
26
|
+
# Download repo with filters
|
|
27
|
+
hf download gpt2 --include="*.safetensors"
|
|
28
|
+
|
|
29
|
+
# Download with token
|
|
30
|
+
hf download Wauplin/private-model --token=hf_***
|
|
31
|
+
|
|
32
|
+
# Download quietly (no progress bar, no warnings, only the returned path)
|
|
33
|
+
hf download gpt2 config.json --quiet
|
|
34
|
+
|
|
35
|
+
# Download to local dir
|
|
36
|
+
hf download gpt2 --local-dir=./models/gpt2
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
import warnings
|
|
40
|
+
from argparse import Namespace, _SubParsersAction
|
|
41
|
+
from typing import List, Optional
|
|
42
|
+
|
|
43
|
+
from huggingface_hub import logging
|
|
44
|
+
from huggingface_hub._snapshot_download import snapshot_download
|
|
45
|
+
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
46
|
+
from huggingface_hub.file_download import hf_hub_download
|
|
47
|
+
from huggingface_hub.utils import disable_progress_bars, enable_progress_bars
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
logger = logging.get_logger(__name__)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class DownloadCommand(BaseHuggingfaceCLICommand):
|
|
54
|
+
@staticmethod
|
|
55
|
+
def register_subcommand(parser: _SubParsersAction):
|
|
56
|
+
download_parser = parser.add_parser("download", help="Download files from the Hub")
|
|
57
|
+
download_parser.add_argument(
|
|
58
|
+
"repo_id", type=str, help="ID of the repo to download from (e.g. `username/repo-name`)."
|
|
59
|
+
)
|
|
60
|
+
download_parser.add_argument(
|
|
61
|
+
"filenames", type=str, nargs="*", help="Files to download (e.g. `config.json`, `data/metadata.jsonl`)."
|
|
62
|
+
)
|
|
63
|
+
download_parser.add_argument(
|
|
64
|
+
"--repo-type",
|
|
65
|
+
choices=["model", "dataset", "space"],
|
|
66
|
+
default="model",
|
|
67
|
+
help="Type of repo to download from (defaults to 'model').",
|
|
68
|
+
)
|
|
69
|
+
download_parser.add_argument(
|
|
70
|
+
"--revision",
|
|
71
|
+
type=str,
|
|
72
|
+
help="An optional Git revision id which can be a branch name, a tag, or a commit hash.",
|
|
73
|
+
)
|
|
74
|
+
download_parser.add_argument(
|
|
75
|
+
"--include", nargs="*", type=str, help="Glob patterns to match files to download."
|
|
76
|
+
)
|
|
77
|
+
download_parser.add_argument(
|
|
78
|
+
"--exclude", nargs="*", type=str, help="Glob patterns to exclude from files to download."
|
|
79
|
+
)
|
|
80
|
+
download_parser.add_argument(
|
|
81
|
+
"--cache-dir", type=str, help="Path to the directory where to save the downloaded files."
|
|
82
|
+
)
|
|
83
|
+
download_parser.add_argument(
|
|
84
|
+
"--local-dir",
|
|
85
|
+
type=str,
|
|
86
|
+
help=(
|
|
87
|
+
"If set, the downloaded file will be placed under this directory. Check out"
|
|
88
|
+
" https://huggingface.co/docs/huggingface_hub/guides/download#download-files-to-local-folder for more"
|
|
89
|
+
" details."
|
|
90
|
+
),
|
|
91
|
+
)
|
|
92
|
+
download_parser.add_argument(
|
|
93
|
+
"--force-download",
|
|
94
|
+
action="store_true",
|
|
95
|
+
help="If True, the files will be downloaded even if they are already cached.",
|
|
96
|
+
)
|
|
97
|
+
download_parser.add_argument(
|
|
98
|
+
"--token", type=str, help="A User Access Token generated from https://huggingface.co/settings/tokens"
|
|
99
|
+
)
|
|
100
|
+
download_parser.add_argument(
|
|
101
|
+
"--quiet",
|
|
102
|
+
action="store_true",
|
|
103
|
+
help="If True, progress bars are disabled and only the path to the download files is printed.",
|
|
104
|
+
)
|
|
105
|
+
download_parser.add_argument(
|
|
106
|
+
"--max-workers",
|
|
107
|
+
type=int,
|
|
108
|
+
default=8,
|
|
109
|
+
help="Maximum number of workers to use for downloading files. Default is 8.",
|
|
110
|
+
)
|
|
111
|
+
download_parser.set_defaults(func=DownloadCommand)
|
|
112
|
+
|
|
113
|
+
def __init__(self, args: Namespace) -> None:
|
|
114
|
+
self.token = args.token
|
|
115
|
+
self.repo_id: str = args.repo_id
|
|
116
|
+
self.filenames: List[str] = args.filenames
|
|
117
|
+
self.repo_type: str = args.repo_type
|
|
118
|
+
self.revision: Optional[str] = args.revision
|
|
119
|
+
self.include: Optional[List[str]] = args.include
|
|
120
|
+
self.exclude: Optional[List[str]] = args.exclude
|
|
121
|
+
self.cache_dir: Optional[str] = args.cache_dir
|
|
122
|
+
self.local_dir: Optional[str] = args.local_dir
|
|
123
|
+
self.force_download: bool = args.force_download
|
|
124
|
+
self.quiet: bool = args.quiet
|
|
125
|
+
self.max_workers: int = args.max_workers
|
|
126
|
+
|
|
127
|
+
def run(self) -> None:
|
|
128
|
+
if self.quiet:
|
|
129
|
+
disable_progress_bars()
|
|
130
|
+
with warnings.catch_warnings():
|
|
131
|
+
warnings.simplefilter("ignore")
|
|
132
|
+
print(self._download()) # Print path to downloaded files
|
|
133
|
+
enable_progress_bars()
|
|
134
|
+
else:
|
|
135
|
+
logging.set_verbosity_info()
|
|
136
|
+
print(self._download()) # Print path to downloaded files
|
|
137
|
+
logging.set_verbosity_warning()
|
|
138
|
+
|
|
139
|
+
def _download(self) -> str:
|
|
140
|
+
# Warn user if patterns are ignored
|
|
141
|
+
if len(self.filenames) > 0:
|
|
142
|
+
if self.include is not None and len(self.include) > 0:
|
|
143
|
+
warnings.warn("Ignoring `--include` since filenames have being explicitly set.")
|
|
144
|
+
if self.exclude is not None and len(self.exclude) > 0:
|
|
145
|
+
warnings.warn("Ignoring `--exclude` since filenames have being explicitly set.")
|
|
146
|
+
|
|
147
|
+
# Single file to download: use `hf_hub_download`
|
|
148
|
+
if len(self.filenames) == 1:
|
|
149
|
+
return hf_hub_download(
|
|
150
|
+
repo_id=self.repo_id,
|
|
151
|
+
repo_type=self.repo_type,
|
|
152
|
+
revision=self.revision,
|
|
153
|
+
filename=self.filenames[0],
|
|
154
|
+
cache_dir=self.cache_dir,
|
|
155
|
+
force_download=self.force_download,
|
|
156
|
+
token=self.token,
|
|
157
|
+
local_dir=self.local_dir,
|
|
158
|
+
library_name="hf",
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
# Otherwise: use `snapshot_download` to ensure all files comes from same revision
|
|
162
|
+
elif len(self.filenames) == 0:
|
|
163
|
+
allow_patterns = self.include
|
|
164
|
+
ignore_patterns = self.exclude
|
|
165
|
+
else:
|
|
166
|
+
allow_patterns = self.filenames
|
|
167
|
+
ignore_patterns = None
|
|
168
|
+
|
|
169
|
+
return snapshot_download(
|
|
170
|
+
repo_id=self.repo_id,
|
|
171
|
+
repo_type=self.repo_type,
|
|
172
|
+
revision=self.revision,
|
|
173
|
+
allow_patterns=allow_patterns,
|
|
174
|
+
ignore_patterns=ignore_patterns,
|
|
175
|
+
force_download=self.force_download,
|
|
176
|
+
cache_dir=self.cache_dir,
|
|
177
|
+
token=self.token,
|
|
178
|
+
local_dir=self.local_dir,
|
|
179
|
+
library_name="hf",
|
|
180
|
+
max_workers=self.max_workers,
|
|
181
|
+
)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Copyright 2020 The HuggingFace Team. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from argparse import ArgumentParser
|
|
16
|
+
|
|
17
|
+
from huggingface_hub.cli.auth import AuthCommands
|
|
18
|
+
from huggingface_hub.cli.cache import CacheCommand
|
|
19
|
+
from huggingface_hub.cli.download import DownloadCommand
|
|
20
|
+
from huggingface_hub.cli.jobs import JobsCommands
|
|
21
|
+
from huggingface_hub.cli.lfs import LfsCommands
|
|
22
|
+
from huggingface_hub.cli.repo import RepoCommands
|
|
23
|
+
from huggingface_hub.cli.repo_files import RepoFilesCommand
|
|
24
|
+
from huggingface_hub.cli.system import EnvironmentCommand, VersionCommand
|
|
25
|
+
from huggingface_hub.cli.upload import UploadCommand
|
|
26
|
+
from huggingface_hub.cli.upload_large_folder import UploadLargeFolderCommand
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def main():
|
|
30
|
+
parser = ArgumentParser("hf", usage="hf <command> [<args>]")
|
|
31
|
+
commands_parser = parser.add_subparsers(help="hf command helpers")
|
|
32
|
+
|
|
33
|
+
# Register commands
|
|
34
|
+
AuthCommands.register_subcommand(commands_parser)
|
|
35
|
+
CacheCommand.register_subcommand(commands_parser)
|
|
36
|
+
DownloadCommand.register_subcommand(commands_parser)
|
|
37
|
+
JobsCommands.register_subcommand(commands_parser)
|
|
38
|
+
RepoCommands.register_subcommand(commands_parser)
|
|
39
|
+
RepoFilesCommand.register_subcommand(commands_parser)
|
|
40
|
+
UploadCommand.register_subcommand(commands_parser)
|
|
41
|
+
UploadLargeFolderCommand.register_subcommand(commands_parser)
|
|
42
|
+
|
|
43
|
+
# System commands
|
|
44
|
+
EnvironmentCommand.register_subcommand(commands_parser)
|
|
45
|
+
VersionCommand.register_subcommand(commands_parser)
|
|
46
|
+
|
|
47
|
+
# LFS commands (hidden in --help)
|
|
48
|
+
LfsCommands.register_subcommand(commands_parser)
|
|
49
|
+
|
|
50
|
+
# Legacy commands
|
|
51
|
+
|
|
52
|
+
# Experimental
|
|
53
|
+
|
|
54
|
+
# Let's go
|
|
55
|
+
args = parser.parse_args()
|
|
56
|
+
if not hasattr(args, "func"):
|
|
57
|
+
parser.print_help()
|
|
58
|
+
exit(1)
|
|
59
|
+
|
|
60
|
+
# Run
|
|
61
|
+
service = args.func(args)
|
|
62
|
+
service.run()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if __name__ == "__main__":
|
|
66
|
+
main()
|