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,195 +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 download files from the Hub with the CLI.
|
|
16
|
-
|
|
17
|
-
Usage:
|
|
18
|
-
huggingface-cli download --help
|
|
19
|
-
|
|
20
|
-
# Download file
|
|
21
|
-
huggingface-cli download gpt2 config.json
|
|
22
|
-
|
|
23
|
-
# Download entire repo
|
|
24
|
-
huggingface-cli download fffiloni/zeroscope --repo-type=space --revision=refs/pr/78
|
|
25
|
-
|
|
26
|
-
# Download repo with filters
|
|
27
|
-
huggingface-cli download gpt2 --include="*.safetensors"
|
|
28
|
-
|
|
29
|
-
# Download with token
|
|
30
|
-
huggingface-cli download Wauplin/private-model --token=hf_***
|
|
31
|
-
|
|
32
|
-
# Download quietly (no progress bar, no warnings, only the returned path)
|
|
33
|
-
huggingface-cli download gpt2 config.json --quiet
|
|
34
|
-
|
|
35
|
-
# Download to local dir
|
|
36
|
-
huggingface-cli download gpt2 --local-dir=./models/gpt2
|
|
37
|
-
"""
|
|
38
|
-
|
|
39
|
-
import warnings
|
|
40
|
-
from argparse import Namespace, _SubParsersAction
|
|
41
|
-
from typing import 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
|
-
from ._cli_utils import show_deprecation_warning
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
logger = logging.get_logger(__name__)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
class DownloadCommand(BaseHuggingfaceCLICommand):
|
|
56
|
-
@staticmethod
|
|
57
|
-
def register_subcommand(parser: _SubParsersAction):
|
|
58
|
-
download_parser = parser.add_parser("download", help="Download files from the Hub")
|
|
59
|
-
download_parser.add_argument(
|
|
60
|
-
"repo_id", type=str, help="ID of the repo to download from (e.g. `username/repo-name`)."
|
|
61
|
-
)
|
|
62
|
-
download_parser.add_argument(
|
|
63
|
-
"filenames", type=str, nargs="*", help="Files to download (e.g. `config.json`, `data/metadata.jsonl`)."
|
|
64
|
-
)
|
|
65
|
-
download_parser.add_argument(
|
|
66
|
-
"--repo-type",
|
|
67
|
-
choices=["model", "dataset", "space"],
|
|
68
|
-
default="model",
|
|
69
|
-
help="Type of repo to download from (defaults to 'model').",
|
|
70
|
-
)
|
|
71
|
-
download_parser.add_argument(
|
|
72
|
-
"--revision",
|
|
73
|
-
type=str,
|
|
74
|
-
help="An optional Git revision id which can be a branch name, a tag, or a commit hash.",
|
|
75
|
-
)
|
|
76
|
-
download_parser.add_argument(
|
|
77
|
-
"--include", nargs="*", type=str, help="Glob patterns to match files to download."
|
|
78
|
-
)
|
|
79
|
-
download_parser.add_argument(
|
|
80
|
-
"--exclude", nargs="*", type=str, help="Glob patterns to exclude from files to download."
|
|
81
|
-
)
|
|
82
|
-
download_parser.add_argument(
|
|
83
|
-
"--cache-dir", type=str, help="Path to the directory where to save the downloaded files."
|
|
84
|
-
)
|
|
85
|
-
download_parser.add_argument(
|
|
86
|
-
"--local-dir",
|
|
87
|
-
type=str,
|
|
88
|
-
help=(
|
|
89
|
-
"If set, the downloaded file will be placed under this directory. Check out"
|
|
90
|
-
" https://huggingface.co/docs/huggingface_hub/guides/download#download-files-to-local-folder for more"
|
|
91
|
-
" details."
|
|
92
|
-
),
|
|
93
|
-
)
|
|
94
|
-
download_parser.add_argument(
|
|
95
|
-
"--local-dir-use-symlinks",
|
|
96
|
-
choices=["auto", "True", "False"],
|
|
97
|
-
help=("Deprecated and ignored. Downloading to a local directory does not use symlinks anymore."),
|
|
98
|
-
)
|
|
99
|
-
download_parser.add_argument(
|
|
100
|
-
"--force-download",
|
|
101
|
-
action="store_true",
|
|
102
|
-
help="If True, the files will be downloaded even if they are already cached.",
|
|
103
|
-
)
|
|
104
|
-
download_parser.add_argument(
|
|
105
|
-
"--resume-download",
|
|
106
|
-
action="store_true",
|
|
107
|
-
help="Deprecated and ignored. Downloading a file to local dir always attempts to resume previously interrupted downloads (unless hf-transfer is enabled).",
|
|
108
|
-
)
|
|
109
|
-
download_parser.add_argument(
|
|
110
|
-
"--token", type=str, help="A User Access Token generated from https://huggingface.co/settings/tokens"
|
|
111
|
-
)
|
|
112
|
-
download_parser.add_argument(
|
|
113
|
-
"--quiet",
|
|
114
|
-
action="store_true",
|
|
115
|
-
help="If True, progress bars are disabled and only the path to the download files is printed.",
|
|
116
|
-
)
|
|
117
|
-
download_parser.add_argument(
|
|
118
|
-
"--max-workers",
|
|
119
|
-
type=int,
|
|
120
|
-
default=8,
|
|
121
|
-
help="Maximum number of workers to use for downloading files. Default is 8.",
|
|
122
|
-
)
|
|
123
|
-
download_parser.set_defaults(func=DownloadCommand)
|
|
124
|
-
|
|
125
|
-
def __init__(self, args: Namespace) -> None:
|
|
126
|
-
self.token = args.token
|
|
127
|
-
self.repo_id: str = args.repo_id
|
|
128
|
-
self.filenames: list[str] = args.filenames
|
|
129
|
-
self.repo_type: str = args.repo_type
|
|
130
|
-
self.revision: Optional[str] = args.revision
|
|
131
|
-
self.include: Optional[list[str]] = args.include
|
|
132
|
-
self.exclude: Optional[list[str]] = args.exclude
|
|
133
|
-
self.cache_dir: Optional[str] = args.cache_dir
|
|
134
|
-
self.local_dir: Optional[str] = args.local_dir
|
|
135
|
-
self.force_download: bool = args.force_download
|
|
136
|
-
self.quiet: bool = args.quiet
|
|
137
|
-
self.max_workers: int = args.max_workers
|
|
138
|
-
|
|
139
|
-
def run(self) -> None:
|
|
140
|
-
show_deprecation_warning("huggingface-cli download", "hf download")
|
|
141
|
-
|
|
142
|
-
if self.quiet:
|
|
143
|
-
disable_progress_bars()
|
|
144
|
-
with warnings.catch_warnings():
|
|
145
|
-
warnings.simplefilter("ignore")
|
|
146
|
-
print(self._download()) # Print path to downloaded files
|
|
147
|
-
enable_progress_bars()
|
|
148
|
-
else:
|
|
149
|
-
logging.set_verbosity_info()
|
|
150
|
-
print(self._download()) # Print path to downloaded files
|
|
151
|
-
logging.set_verbosity_warning()
|
|
152
|
-
|
|
153
|
-
def _download(self) -> str:
|
|
154
|
-
# Warn user if patterns are ignored
|
|
155
|
-
if len(self.filenames) > 0:
|
|
156
|
-
if self.include is not None and len(self.include) > 0:
|
|
157
|
-
warnings.warn("Ignoring `--include` since filenames have being explicitly set.")
|
|
158
|
-
if self.exclude is not None and len(self.exclude) > 0:
|
|
159
|
-
warnings.warn("Ignoring `--exclude` since filenames have being explicitly set.")
|
|
160
|
-
|
|
161
|
-
# Single file to download: use `hf_hub_download`
|
|
162
|
-
if len(self.filenames) == 1:
|
|
163
|
-
return hf_hub_download(
|
|
164
|
-
repo_id=self.repo_id,
|
|
165
|
-
repo_type=self.repo_type,
|
|
166
|
-
revision=self.revision,
|
|
167
|
-
filename=self.filenames[0],
|
|
168
|
-
cache_dir=self.cache_dir,
|
|
169
|
-
force_download=self.force_download,
|
|
170
|
-
token=self.token,
|
|
171
|
-
local_dir=self.local_dir,
|
|
172
|
-
library_name="huggingface-cli",
|
|
173
|
-
)
|
|
174
|
-
|
|
175
|
-
# Otherwise: use `snapshot_download` to ensure all files comes from same revision
|
|
176
|
-
elif len(self.filenames) == 0:
|
|
177
|
-
allow_patterns = self.include
|
|
178
|
-
ignore_patterns = self.exclude
|
|
179
|
-
else:
|
|
180
|
-
allow_patterns = self.filenames
|
|
181
|
-
ignore_patterns = None
|
|
182
|
-
|
|
183
|
-
return snapshot_download(
|
|
184
|
-
repo_id=self.repo_id,
|
|
185
|
-
repo_type=self.repo_type,
|
|
186
|
-
revision=self.revision,
|
|
187
|
-
allow_patterns=allow_patterns,
|
|
188
|
-
ignore_patterns=ignore_patterns,
|
|
189
|
-
force_download=self.force_download,
|
|
190
|
-
cache_dir=self.cache_dir,
|
|
191
|
-
token=self.token,
|
|
192
|
-
local_dir=self.local_dir,
|
|
193
|
-
library_name="huggingface-cli",
|
|
194
|
-
max_workers=self.max_workers,
|
|
195
|
-
)
|
huggingface_hub/commands/env.py
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 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
|
-
"""Contains command to print information about the environment.
|
|
15
|
-
|
|
16
|
-
Usage:
|
|
17
|
-
huggingface-cli env
|
|
18
|
-
"""
|
|
19
|
-
|
|
20
|
-
from argparse import _SubParsersAction
|
|
21
|
-
|
|
22
|
-
from ..utils import dump_environment_info
|
|
23
|
-
from . import BaseHuggingfaceCLICommand
|
|
24
|
-
from ._cli_utils import show_deprecation_warning
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class EnvironmentCommand(BaseHuggingfaceCLICommand):
|
|
28
|
-
def __init__(self, args):
|
|
29
|
-
self.args = args
|
|
30
|
-
|
|
31
|
-
@staticmethod
|
|
32
|
-
def register_subcommand(parser: _SubParsersAction):
|
|
33
|
-
env_parser = parser.add_parser("env", help="Print information about the environment.")
|
|
34
|
-
env_parser.set_defaults(func=EnvironmentCommand)
|
|
35
|
-
|
|
36
|
-
def run(self) -> None:
|
|
37
|
-
show_deprecation_warning("huggingface-cli env", "hf env")
|
|
38
|
-
|
|
39
|
-
dump_environment_info()
|
|
@@ -1,65 +0,0 @@
|
|
|
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.commands._cli_utils import show_deprecation_warning
|
|
18
|
-
from huggingface_hub.commands.delete_cache import DeleteCacheCommand
|
|
19
|
-
from huggingface_hub.commands.download import DownloadCommand
|
|
20
|
-
from huggingface_hub.commands.env import EnvironmentCommand
|
|
21
|
-
from huggingface_hub.commands.lfs import LfsCommands
|
|
22
|
-
from huggingface_hub.commands.repo import RepoCommands
|
|
23
|
-
from huggingface_hub.commands.repo_files import RepoFilesCommand
|
|
24
|
-
from huggingface_hub.commands.scan_cache import ScanCacheCommand
|
|
25
|
-
from huggingface_hub.commands.tag import TagCommands
|
|
26
|
-
from huggingface_hub.commands.upload import UploadCommand
|
|
27
|
-
from huggingface_hub.commands.upload_large_folder import UploadLargeFolderCommand
|
|
28
|
-
from huggingface_hub.commands.user import UserCommands
|
|
29
|
-
from huggingface_hub.commands.version import VersionCommand
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def main():
|
|
33
|
-
parser = ArgumentParser("huggingface-cli", usage="huggingface-cli <command> [<args>]")
|
|
34
|
-
commands_parser = parser.add_subparsers(help="huggingface-cli command helpers")
|
|
35
|
-
|
|
36
|
-
# Register commands
|
|
37
|
-
DownloadCommand.register_subcommand(commands_parser)
|
|
38
|
-
UploadCommand.register_subcommand(commands_parser)
|
|
39
|
-
RepoFilesCommand.register_subcommand(commands_parser)
|
|
40
|
-
EnvironmentCommand.register_subcommand(commands_parser)
|
|
41
|
-
UserCommands.register_subcommand(commands_parser)
|
|
42
|
-
RepoCommands.register_subcommand(commands_parser)
|
|
43
|
-
LfsCommands.register_subcommand(commands_parser)
|
|
44
|
-
ScanCacheCommand.register_subcommand(commands_parser)
|
|
45
|
-
DeleteCacheCommand.register_subcommand(commands_parser)
|
|
46
|
-
TagCommands.register_subcommand(commands_parser)
|
|
47
|
-
VersionCommand.register_subcommand(commands_parser)
|
|
48
|
-
|
|
49
|
-
# Experimental
|
|
50
|
-
UploadLargeFolderCommand.register_subcommand(commands_parser)
|
|
51
|
-
|
|
52
|
-
# Let's go
|
|
53
|
-
args = parser.parse_args()
|
|
54
|
-
if not hasattr(args, "func"):
|
|
55
|
-
show_deprecation_warning("huggingface-cli", "hf")
|
|
56
|
-
parser.print_help()
|
|
57
|
-
exit(1)
|
|
58
|
-
|
|
59
|
-
# Run
|
|
60
|
-
service = args.func(args)
|
|
61
|
-
service.run()
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if __name__ == "__main__":
|
|
65
|
-
main()
|
huggingface_hub/commands/lfs.py
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Implementation of a custom transfer agent for the transfer type "multipart" for
|
|
3
|
-
git-lfs.
|
|
4
|
-
|
|
5
|
-
Inspired by:
|
|
6
|
-
github.com/cbartz/git-lfs-swift-transfer-agent/blob/master/git_lfs_swift_transfer.py
|
|
7
|
-
|
|
8
|
-
Spec is: github.com/git-lfs/git-lfs/blob/master/docs/custom-transfers.md
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
To launch debugger while developing:
|
|
12
|
-
|
|
13
|
-
``` [lfs "customtransfer.multipart"]
|
|
14
|
-
path = /path/to/huggingface_hub/.env/bin/python args = -m debugpy --listen 5678
|
|
15
|
-
--wait-for-client
|
|
16
|
-
/path/to/huggingface_hub/src/huggingface_hub/commands/huggingface_cli.py
|
|
17
|
-
lfs-multipart-upload ```"""
|
|
18
|
-
|
|
19
|
-
import json
|
|
20
|
-
import os
|
|
21
|
-
import subprocess
|
|
22
|
-
import sys
|
|
23
|
-
from argparse import _SubParsersAction
|
|
24
|
-
from typing import Optional
|
|
25
|
-
|
|
26
|
-
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
27
|
-
from huggingface_hub.lfs import LFS_MULTIPART_UPLOAD_COMMAND
|
|
28
|
-
|
|
29
|
-
from ..utils import get_session, hf_raise_for_status, logging
|
|
30
|
-
from ..utils._lfs import SliceFileObj
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
logger = logging.get_logger(__name__)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
class LfsCommands(BaseHuggingfaceCLICommand):
|
|
37
|
-
"""
|
|
38
|
-
Implementation of a custom transfer agent for the transfer type "multipart"
|
|
39
|
-
for git-lfs. This lets users upload large files >5GB 🔥. Spec for LFS custom
|
|
40
|
-
transfer agent is:
|
|
41
|
-
https://github.com/git-lfs/git-lfs/blob/master/docs/custom-transfers.md
|
|
42
|
-
|
|
43
|
-
This introduces two commands to the CLI:
|
|
44
|
-
|
|
45
|
-
1. $ huggingface-cli lfs-enable-largefiles
|
|
46
|
-
|
|
47
|
-
This should be executed once for each model repo that contains a model file
|
|
48
|
-
>5GB. It's documented in the error message you get if you just try to git
|
|
49
|
-
push a 5GB file without having enabled it before.
|
|
50
|
-
|
|
51
|
-
2. $ huggingface-cli lfs-multipart-upload
|
|
52
|
-
|
|
53
|
-
This command is called by lfs directly and is not meant to be called by the
|
|
54
|
-
user.
|
|
55
|
-
"""
|
|
56
|
-
|
|
57
|
-
@staticmethod
|
|
58
|
-
def register_subcommand(parser: _SubParsersAction):
|
|
59
|
-
enable_parser = parser.add_parser(
|
|
60
|
-
"lfs-enable-largefiles", help="Configure your repository to enable upload of files > 5GB."
|
|
61
|
-
)
|
|
62
|
-
enable_parser.add_argument("path", type=str, help="Local path to repository you want to configure.")
|
|
63
|
-
enable_parser.set_defaults(func=lambda args: LfsEnableCommand(args))
|
|
64
|
-
|
|
65
|
-
# Command will get called by git-lfs, do not call it directly.
|
|
66
|
-
upload_parser = parser.add_parser(LFS_MULTIPART_UPLOAD_COMMAND, add_help=False)
|
|
67
|
-
upload_parser.set_defaults(func=lambda args: LfsUploadCommand(args))
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
class LfsEnableCommand:
|
|
71
|
-
def __init__(self, args):
|
|
72
|
-
self.args = args
|
|
73
|
-
|
|
74
|
-
def run(self):
|
|
75
|
-
local_path = os.path.abspath(self.args.path)
|
|
76
|
-
if not os.path.isdir(local_path):
|
|
77
|
-
print("This does not look like a valid git repo.")
|
|
78
|
-
exit(1)
|
|
79
|
-
subprocess.run(
|
|
80
|
-
"git config lfs.customtransfer.multipart.path huggingface-cli".split(),
|
|
81
|
-
check=True,
|
|
82
|
-
cwd=local_path,
|
|
83
|
-
)
|
|
84
|
-
subprocess.run(
|
|
85
|
-
f"git config lfs.customtransfer.multipart.args {LFS_MULTIPART_UPLOAD_COMMAND}".split(),
|
|
86
|
-
check=True,
|
|
87
|
-
cwd=local_path,
|
|
88
|
-
)
|
|
89
|
-
print("Local repo set up for largefiles")
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
def write_msg(msg: dict):
|
|
93
|
-
"""Write out the message in Line delimited JSON."""
|
|
94
|
-
msg_str = json.dumps(msg) + "\n"
|
|
95
|
-
sys.stdout.write(msg_str)
|
|
96
|
-
sys.stdout.flush()
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
def read_msg() -> Optional[dict]:
|
|
100
|
-
"""Read Line delimited JSON from stdin."""
|
|
101
|
-
msg = json.loads(sys.stdin.readline().strip())
|
|
102
|
-
|
|
103
|
-
if "terminate" in (msg.get("type"), msg.get("event")):
|
|
104
|
-
# terminate message received
|
|
105
|
-
return None
|
|
106
|
-
|
|
107
|
-
if msg.get("event") not in ("download", "upload"):
|
|
108
|
-
logger.critical("Received unexpected message")
|
|
109
|
-
sys.exit(1)
|
|
110
|
-
|
|
111
|
-
return msg
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
class LfsUploadCommand:
|
|
115
|
-
def __init__(self, args) -> None:
|
|
116
|
-
self.args = args
|
|
117
|
-
|
|
118
|
-
def run(self) -> None:
|
|
119
|
-
# Immediately after invoking a custom transfer process, git-lfs
|
|
120
|
-
# sends initiation data to the process over stdin.
|
|
121
|
-
# This tells the process useful information about the configuration.
|
|
122
|
-
init_msg = json.loads(sys.stdin.readline().strip())
|
|
123
|
-
if not (init_msg.get("event") == "init" and init_msg.get("operation") == "upload"):
|
|
124
|
-
write_msg({"error": {"code": 32, "message": "Wrong lfs init operation"}})
|
|
125
|
-
sys.exit(1)
|
|
126
|
-
|
|
127
|
-
# The transfer process should use the information it needs from the
|
|
128
|
-
# initiation structure, and also perform any one-off setup tasks it
|
|
129
|
-
# needs to do. It should then respond on stdout with a simple empty
|
|
130
|
-
# confirmation structure, as follows:
|
|
131
|
-
write_msg({})
|
|
132
|
-
|
|
133
|
-
# After the initiation exchange, git-lfs will send any number of
|
|
134
|
-
# transfer requests to the stdin of the transfer process, in a serial sequence.
|
|
135
|
-
while True:
|
|
136
|
-
msg = read_msg()
|
|
137
|
-
if msg is None:
|
|
138
|
-
# When all transfers have been processed, git-lfs will send
|
|
139
|
-
# a terminate event to the stdin of the transfer process.
|
|
140
|
-
# On receiving this message the transfer process should
|
|
141
|
-
# clean up and terminate. No response is expected.
|
|
142
|
-
sys.exit(0)
|
|
143
|
-
|
|
144
|
-
oid = msg["oid"]
|
|
145
|
-
filepath = msg["path"]
|
|
146
|
-
completion_url = msg["action"]["href"]
|
|
147
|
-
header = msg["action"]["header"]
|
|
148
|
-
chunk_size = int(header.pop("chunk_size"))
|
|
149
|
-
presigned_urls: list[str] = list(header.values())
|
|
150
|
-
|
|
151
|
-
# Send a "started" progress event to allow other workers to start.
|
|
152
|
-
# Otherwise they're delayed until first "progress" event is reported,
|
|
153
|
-
# i.e. after the first 5GB by default (!)
|
|
154
|
-
write_msg(
|
|
155
|
-
{
|
|
156
|
-
"event": "progress",
|
|
157
|
-
"oid": oid,
|
|
158
|
-
"bytesSoFar": 1,
|
|
159
|
-
"bytesSinceLast": 0,
|
|
160
|
-
}
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
parts = []
|
|
164
|
-
with open(filepath, "rb") as file:
|
|
165
|
-
for i, presigned_url in enumerate(presigned_urls):
|
|
166
|
-
with SliceFileObj(
|
|
167
|
-
file,
|
|
168
|
-
seek_from=i * chunk_size,
|
|
169
|
-
read_limit=chunk_size,
|
|
170
|
-
) as data:
|
|
171
|
-
r = get_session().put(presigned_url, data=data)
|
|
172
|
-
hf_raise_for_status(r)
|
|
173
|
-
parts.append(
|
|
174
|
-
{
|
|
175
|
-
"etag": r.headers.get("etag"),
|
|
176
|
-
"partNumber": i + 1,
|
|
177
|
-
}
|
|
178
|
-
)
|
|
179
|
-
# In order to support progress reporting while data is uploading / downloading,
|
|
180
|
-
# the transfer process should post messages to stdout
|
|
181
|
-
write_msg(
|
|
182
|
-
{
|
|
183
|
-
"event": "progress",
|
|
184
|
-
"oid": oid,
|
|
185
|
-
"bytesSoFar": (i + 1) * chunk_size,
|
|
186
|
-
"bytesSinceLast": chunk_size,
|
|
187
|
-
}
|
|
188
|
-
)
|
|
189
|
-
# Not precise but that's ok.
|
|
190
|
-
|
|
191
|
-
r = get_session().post(
|
|
192
|
-
completion_url,
|
|
193
|
-
json={
|
|
194
|
-
"oid": oid,
|
|
195
|
-
"parts": parts,
|
|
196
|
-
},
|
|
197
|
-
)
|
|
198
|
-
hf_raise_for_status(r)
|
|
199
|
-
|
|
200
|
-
write_msg({"event": "complete", "oid": oid})
|
huggingface_hub/commands/repo.py
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 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
|
-
"""Contains commands to interact with repositories on the Hugging Face Hub.
|
|
15
|
-
|
|
16
|
-
Usage:
|
|
17
|
-
# create a new dataset repo on the Hub
|
|
18
|
-
huggingface-cli repo create my-cool-dataset --repo-type=dataset
|
|
19
|
-
|
|
20
|
-
# create a private model repo on the Hub
|
|
21
|
-
huggingface-cli repo create my-cool-model --private
|
|
22
|
-
"""
|
|
23
|
-
|
|
24
|
-
import argparse
|
|
25
|
-
from argparse import _SubParsersAction
|
|
26
|
-
from typing import Optional
|
|
27
|
-
|
|
28
|
-
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
29
|
-
from huggingface_hub.commands._cli_utils import ANSI
|
|
30
|
-
from huggingface_hub.constants import SPACES_SDK_TYPES
|
|
31
|
-
from huggingface_hub.hf_api import HfApi
|
|
32
|
-
from huggingface_hub.utils import logging
|
|
33
|
-
|
|
34
|
-
from ._cli_utils import show_deprecation_warning
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
logger = logging.get_logger(__name__)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class RepoCommands(BaseHuggingfaceCLICommand):
|
|
41
|
-
@staticmethod
|
|
42
|
-
def register_subcommand(parser: _SubParsersAction):
|
|
43
|
-
repo_parser = parser.add_parser("repo", help="{create} Commands to interact with your huggingface.co repos.")
|
|
44
|
-
repo_subparsers = repo_parser.add_subparsers(help="huggingface.co repos related commands")
|
|
45
|
-
repo_create_parser = repo_subparsers.add_parser("create", help="Create a new repo on huggingface.co")
|
|
46
|
-
repo_create_parser.add_argument(
|
|
47
|
-
"repo_id",
|
|
48
|
-
type=str,
|
|
49
|
-
help="The ID of the repo to create to (e.g. `username/repo-name`). The username is optional and will be set to your username if not provided.",
|
|
50
|
-
)
|
|
51
|
-
repo_create_parser.add_argument(
|
|
52
|
-
"--repo-type",
|
|
53
|
-
type=str,
|
|
54
|
-
help='Optional: set to "dataset" or "space" if creating a dataset or space, default is model.',
|
|
55
|
-
)
|
|
56
|
-
repo_create_parser.add_argument(
|
|
57
|
-
"--space_sdk",
|
|
58
|
-
type=str,
|
|
59
|
-
help='Optional: Hugging Face Spaces SDK type. Required when --type is set to "space".',
|
|
60
|
-
choices=SPACES_SDK_TYPES,
|
|
61
|
-
)
|
|
62
|
-
repo_create_parser.add_argument(
|
|
63
|
-
"--private",
|
|
64
|
-
action="store_true",
|
|
65
|
-
help="Whether to create a private repository. Defaults to public unless the organization's default is private.",
|
|
66
|
-
)
|
|
67
|
-
repo_create_parser.add_argument(
|
|
68
|
-
"--token",
|
|
69
|
-
type=str,
|
|
70
|
-
help="Hugging Face token. Will default to the locally saved token if not provided.",
|
|
71
|
-
)
|
|
72
|
-
repo_create_parser.add_argument(
|
|
73
|
-
"--exist-ok",
|
|
74
|
-
action="store_true",
|
|
75
|
-
help="Do not raise an error if repo already exists.",
|
|
76
|
-
)
|
|
77
|
-
repo_create_parser.add_argument(
|
|
78
|
-
"--resource-group-id",
|
|
79
|
-
type=str,
|
|
80
|
-
help="Resource group in which to create the repo. Resource groups is only available for Enterprise Hub organizations.",
|
|
81
|
-
)
|
|
82
|
-
repo_create_parser.add_argument(
|
|
83
|
-
"--type",
|
|
84
|
-
type=str,
|
|
85
|
-
help="[Deprecated]: use --repo-type instead.",
|
|
86
|
-
)
|
|
87
|
-
repo_create_parser.add_argument(
|
|
88
|
-
"-y",
|
|
89
|
-
"--yes",
|
|
90
|
-
action="store_true",
|
|
91
|
-
help="[Deprecated] no effect.",
|
|
92
|
-
)
|
|
93
|
-
repo_create_parser.add_argument(
|
|
94
|
-
"--organization", type=str, help="[Deprecated] Pass the organization namespace directly in the repo_id."
|
|
95
|
-
)
|
|
96
|
-
repo_create_parser.set_defaults(func=lambda args: RepoCreateCommand(args))
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
class RepoCreateCommand:
|
|
100
|
-
def __init__(self, args: argparse.Namespace):
|
|
101
|
-
self.repo_id: str = args.repo_id
|
|
102
|
-
self.repo_type: Optional[str] = args.repo_type or args.type
|
|
103
|
-
self.space_sdk: Optional[str] = args.space_sdk
|
|
104
|
-
self.organization: Optional[str] = args.organization
|
|
105
|
-
self.yes: bool = args.yes
|
|
106
|
-
self.private: bool = args.private
|
|
107
|
-
self.token: Optional[str] = args.token
|
|
108
|
-
self.exist_ok: bool = args.exist_ok
|
|
109
|
-
self.resource_group_id: Optional[str] = args.resource_group_id
|
|
110
|
-
|
|
111
|
-
if args.type is not None:
|
|
112
|
-
print(
|
|
113
|
-
ANSI.yellow(
|
|
114
|
-
"The --type argument is deprecated and will be removed in a future version. Use --repo-type instead."
|
|
115
|
-
)
|
|
116
|
-
)
|
|
117
|
-
if self.organization is not None:
|
|
118
|
-
print(
|
|
119
|
-
ANSI.yellow(
|
|
120
|
-
"The --organization argument is deprecated and will be removed in a future version. Pass the organization namespace directly in the repo_id."
|
|
121
|
-
)
|
|
122
|
-
)
|
|
123
|
-
if self.yes:
|
|
124
|
-
print(
|
|
125
|
-
ANSI.yellow(
|
|
126
|
-
"The --yes argument is deprecated and will be removed in a future version. It does not have any effect."
|
|
127
|
-
)
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
self._api = HfApi()
|
|
131
|
-
|
|
132
|
-
def run(self):
|
|
133
|
-
show_deprecation_warning("huggingface-cli repo", "hf repo")
|
|
134
|
-
|
|
135
|
-
if self.organization is not None:
|
|
136
|
-
if "/" in self.repo_id:
|
|
137
|
-
print(ANSI.red("You cannot pass both --organization and a repo_id with a namespace."))
|
|
138
|
-
exit(1)
|
|
139
|
-
self.repo_id = f"{self.organization}/{self.repo_id}"
|
|
140
|
-
|
|
141
|
-
repo_url = self._api.create_repo(
|
|
142
|
-
repo_id=self.repo_id,
|
|
143
|
-
repo_type=self.repo_type,
|
|
144
|
-
private=self.private,
|
|
145
|
-
token=self.token,
|
|
146
|
-
exist_ok=self.exist_ok,
|
|
147
|
-
resource_group_id=self.resource_group_id,
|
|
148
|
-
space_sdk=self.space_sdk,
|
|
149
|
-
)
|
|
150
|
-
print(f"Successfully created {ANSI.bold(repo_url.repo_id)} on the Hub.")
|
|
151
|
-
print(f"Your repo is now available at {ANSI.bold(repo_url)}")
|