huggingface-hub 1.0.0rc1__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.

Files changed (59) hide show
  1. huggingface_hub/__init__.py +4 -7
  2. huggingface_hub/_commit_api.py +126 -66
  3. huggingface_hub/_commit_scheduler.py +4 -7
  4. huggingface_hub/_login.py +10 -16
  5. huggingface_hub/_snapshot_download.py +119 -21
  6. huggingface_hub/_tensorboard_logger.py +2 -5
  7. huggingface_hub/_upload_large_folder.py +1 -2
  8. huggingface_hub/_webhooks_server.py +8 -20
  9. huggingface_hub/cli/_cli_utils.py +12 -6
  10. huggingface_hub/cli/download.py +32 -7
  11. huggingface_hub/cli/repo.py +137 -5
  12. huggingface_hub/dataclasses.py +122 -2
  13. huggingface_hub/errors.py +4 -0
  14. huggingface_hub/fastai_utils.py +22 -32
  15. huggingface_hub/file_download.py +234 -38
  16. huggingface_hub/hf_api.py +385 -424
  17. huggingface_hub/hf_file_system.py +55 -65
  18. huggingface_hub/inference/_client.py +27 -48
  19. huggingface_hub/inference/_generated/_async_client.py +27 -48
  20. huggingface_hub/inference/_generated/types/image_to_image.py +6 -2
  21. huggingface_hub/inference/_mcp/agent.py +2 -5
  22. huggingface_hub/inference/_mcp/mcp_client.py +6 -8
  23. huggingface_hub/inference/_providers/__init__.py +16 -0
  24. huggingface_hub/inference/_providers/_common.py +2 -0
  25. huggingface_hub/inference/_providers/fal_ai.py +2 -0
  26. huggingface_hub/inference/_providers/publicai.py +6 -0
  27. huggingface_hub/inference/_providers/scaleway.py +28 -0
  28. huggingface_hub/inference/_providers/zai_org.py +17 -0
  29. huggingface_hub/lfs.py +14 -8
  30. huggingface_hub/repocard.py +12 -16
  31. huggingface_hub/serialization/_base.py +3 -6
  32. huggingface_hub/serialization/_torch.py +16 -34
  33. huggingface_hub/utils/__init__.py +1 -2
  34. huggingface_hub/utils/_cache_manager.py +42 -72
  35. huggingface_hub/utils/_chunk_utils.py +2 -3
  36. huggingface_hub/utils/_http.py +37 -68
  37. huggingface_hub/utils/_validators.py +2 -2
  38. huggingface_hub/utils/logging.py +8 -11
  39. {huggingface_hub-1.0.0rc1.dist-info → huggingface_hub-1.0.0rc3.dist-info}/METADATA +2 -2
  40. {huggingface_hub-1.0.0rc1.dist-info → huggingface_hub-1.0.0rc3.dist-info}/RECORD +44 -56
  41. {huggingface_hub-1.0.0rc1.dist-info → huggingface_hub-1.0.0rc3.dist-info}/entry_points.txt +0 -1
  42. huggingface_hub/commands/__init__.py +0 -27
  43. huggingface_hub/commands/_cli_utils.py +0 -74
  44. huggingface_hub/commands/delete_cache.py +0 -476
  45. huggingface_hub/commands/download.py +0 -195
  46. huggingface_hub/commands/env.py +0 -39
  47. huggingface_hub/commands/huggingface_cli.py +0 -65
  48. huggingface_hub/commands/lfs.py +0 -200
  49. huggingface_hub/commands/repo.py +0 -151
  50. huggingface_hub/commands/repo_files.py +0 -132
  51. huggingface_hub/commands/scan_cache.py +0 -183
  52. huggingface_hub/commands/tag.py +0 -159
  53. huggingface_hub/commands/upload.py +0 -318
  54. huggingface_hub/commands/upload_large_folder.py +0 -131
  55. huggingface_hub/commands/user.py +0 -207
  56. huggingface_hub/commands/version.py +0 -40
  57. {huggingface_hub-1.0.0rc1.dist-info → huggingface_hub-1.0.0rc3.dist-info}/LICENSE +0 -0
  58. {huggingface_hub-1.0.0rc1.dist-info → huggingface_hub-1.0.0rc3.dist-info}/WHEEL +0 -0
  59. {huggingface_hub-1.0.0rc1.dist-info → huggingface_hub-1.0.0rc3.dist-info}/top_level.txt +0 -0
@@ -1,131 +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 upload a large folder with the CLI."""
16
-
17
- import os
18
- from argparse import Namespace, _SubParsersAction
19
- from typing import Optional
20
-
21
- from huggingface_hub import logging
22
- from huggingface_hub.commands import BaseHuggingfaceCLICommand
23
- from huggingface_hub.hf_api import HfApi
24
- from huggingface_hub.utils import disable_progress_bars
25
-
26
- from ._cli_utils import ANSI, show_deprecation_warning
27
-
28
-
29
- logger = logging.get_logger(__name__)
30
-
31
-
32
- class UploadLargeFolderCommand(BaseHuggingfaceCLICommand):
33
- @staticmethod
34
- def register_subcommand(parser: _SubParsersAction):
35
- subparser = parser.add_parser("upload-large-folder", help="Upload a large folder to a repo on the Hub")
36
- subparser.add_argument(
37
- "repo_id", type=str, help="The ID of the repo to upload to (e.g. `username/repo-name`)."
38
- )
39
- subparser.add_argument("local_path", type=str, help="Local path to the file or folder to upload.")
40
- subparser.add_argument(
41
- "--repo-type",
42
- choices=["model", "dataset", "space"],
43
- help="Type of the repo to upload to (e.g. `dataset`).",
44
- )
45
- subparser.add_argument(
46
- "--revision",
47
- type=str,
48
- help=("An optional Git revision to push to. It can be a branch name or a PR reference."),
49
- )
50
- subparser.add_argument(
51
- "--private",
52
- action="store_true",
53
- help=(
54
- "Whether to create a private repo if repo doesn't exist on the Hub. Ignored if the repo already exists."
55
- ),
56
- )
57
- subparser.add_argument("--include", nargs="*", type=str, help="Glob patterns to match files to upload.")
58
- subparser.add_argument("--exclude", nargs="*", type=str, help="Glob patterns to exclude from files to upload.")
59
- subparser.add_argument(
60
- "--token", type=str, help="A User Access Token generated from https://huggingface.co/settings/tokens"
61
- )
62
- subparser.add_argument(
63
- "--num-workers", type=int, help="Number of workers to use to hash, upload and commit files."
64
- )
65
- subparser.add_argument("--no-report", action="store_true", help="Whether to disable regular status report.")
66
- subparser.add_argument("--no-bars", action="store_true", help="Whether to disable progress bars.")
67
- subparser.set_defaults(func=UploadLargeFolderCommand)
68
-
69
- def __init__(self, args: Namespace) -> None:
70
- self.repo_id: str = args.repo_id
71
- self.local_path: str = args.local_path
72
- self.repo_type: str = args.repo_type
73
- self.revision: Optional[str] = args.revision
74
- self.private: bool = args.private
75
-
76
- self.include: Optional[list[str]] = args.include
77
- self.exclude: Optional[list[str]] = args.exclude
78
-
79
- self.api: HfApi = HfApi(token=args.token, library_name="huggingface-cli")
80
-
81
- self.num_workers: Optional[int] = args.num_workers
82
- self.no_report: bool = args.no_report
83
- self.no_bars: bool = args.no_bars
84
-
85
- if not os.path.isdir(self.local_path):
86
- raise ValueError("Large upload is only supported for folders.")
87
-
88
- def run(self) -> None:
89
- show_deprecation_warning("huggingface-cli upload-large-folder", "hf upload-large-folder")
90
-
91
- logging.set_verbosity_info()
92
-
93
- print(
94
- ANSI.yellow(
95
- "You are about to upload a large folder to the Hub using `huggingface-cli upload-large-folder`. "
96
- "This is a new feature so feedback is very welcome!\n"
97
- "\n"
98
- "A few things to keep in mind:\n"
99
- " - Repository limits still apply: https://huggingface.co/docs/hub/repositories-recommendations\n"
100
- " - Do not start several processes in parallel.\n"
101
- " - You can interrupt and resume the process at any time. "
102
- "The script will pick up where it left off except for partially uploaded files that would have to be entirely reuploaded.\n"
103
- " - Do not upload the same folder to several repositories. If you need to do so, you must delete the `./.cache/huggingface/` folder first.\n"
104
- "\n"
105
- f"Some temporary metadata will be stored under `{self.local_path}/.cache/huggingface`.\n"
106
- " - You must not modify those files manually.\n"
107
- " - You must not delete the `./.cache/huggingface/` folder while a process is running.\n"
108
- " - You can delete the `./.cache/huggingface/` folder to reinitialize the upload state when process is not running. Files will have to be hashed and preuploaded again, except for already committed files.\n"
109
- "\n"
110
- "If the process output is too verbose, you can disable the progress bars with `--no-bars`. "
111
- "You can also entirely disable the status report with `--no-report`.\n"
112
- "\n"
113
- "For more details, run `huggingface-cli upload-large-folder --help` or check the documentation at "
114
- "https://huggingface.co/docs/huggingface_hub/guides/upload#upload-a-large-folder."
115
- )
116
- )
117
-
118
- if self.no_bars:
119
- disable_progress_bars()
120
-
121
- self.api.upload_large_folder(
122
- repo_id=self.repo_id,
123
- folder_path=self.local_path,
124
- repo_type=self.repo_type,
125
- revision=self.revision,
126
- private=self.private,
127
- allow_patterns=self.include,
128
- ignore_patterns=self.exclude,
129
- num_workers=self.num_workers,
130
- print_report=not self.no_report,
131
- )
@@ -1,207 +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
- """Contains commands to authenticate to the Hugging Face Hub and interact with your repositories.
15
-
16
- Usage:
17
- # login and save token locally.
18
- huggingface-cli login --token=hf_*** --add-to-git-credential
19
-
20
- # switch between tokens
21
- huggingface-cli auth switch
22
-
23
- # list all tokens
24
- huggingface-cli auth list
25
-
26
- # logout from a specific token, if no token-name is provided, all tokens will be deleted from your machine.
27
- huggingface-cli logout --token-name=your_token_name
28
-
29
- # find out which huggingface.co account you are logged in as
30
- huggingface-cli whoami
31
- """
32
-
33
- from argparse import _SubParsersAction
34
- from typing import Optional
35
-
36
- from huggingface_hub.commands import BaseHuggingfaceCLICommand
37
- from huggingface_hub.constants import ENDPOINT
38
- from huggingface_hub.errors import HfHubHTTPError
39
- from huggingface_hub.hf_api import HfApi
40
-
41
- from .._login import auth_list, auth_switch, login, logout
42
- from ..utils import get_stored_tokens, get_token, logging
43
- from ._cli_utils import ANSI, show_deprecation_warning
44
-
45
-
46
- logger = logging.get_logger(__name__)
47
-
48
- try:
49
- from InquirerPy import inquirer
50
- from InquirerPy.base.control import Choice
51
-
52
- _inquirer_py_available = True
53
- except ImportError:
54
- _inquirer_py_available = False
55
-
56
-
57
- class UserCommands(BaseHuggingfaceCLICommand):
58
- @staticmethod
59
- def register_subcommand(parser: _SubParsersAction):
60
- login_parser = parser.add_parser("login", help="Log in using a token from huggingface.co/settings/tokens")
61
- login_parser.add_argument(
62
- "--token",
63
- type=str,
64
- help="Token generated from https://huggingface.co/settings/tokens",
65
- )
66
- login_parser.add_argument(
67
- "--add-to-git-credential",
68
- action="store_true",
69
- help="Optional: Save token to git credential helper.",
70
- )
71
- login_parser.set_defaults(func=lambda args: LoginCommand(args))
72
- whoami_parser = parser.add_parser("whoami", help="Find out which huggingface.co account you are logged in as.")
73
- whoami_parser.set_defaults(func=lambda args: WhoamiCommand(args))
74
-
75
- logout_parser = parser.add_parser("logout", help="Log out")
76
- logout_parser.add_argument(
77
- "--token-name",
78
- type=str,
79
- help="Optional: Name of the access token to log out from.",
80
- )
81
- logout_parser.set_defaults(func=lambda args: LogoutCommand(args))
82
-
83
- auth_parser = parser.add_parser("auth", help="Other authentication related commands")
84
- auth_subparsers = auth_parser.add_subparsers(help="Authentication subcommands")
85
- auth_switch_parser = auth_subparsers.add_parser("switch", help="Switch between access tokens")
86
- auth_switch_parser.add_argument(
87
- "--token-name",
88
- type=str,
89
- help="Optional: Name of the access token to switch to.",
90
- )
91
- auth_switch_parser.add_argument(
92
- "--add-to-git-credential",
93
- action="store_true",
94
- help="Optional: Save token to git credential helper.",
95
- )
96
- auth_switch_parser.set_defaults(func=lambda args: AuthSwitchCommand(args))
97
- auth_list_parser = auth_subparsers.add_parser("list", help="List all stored access tokens")
98
- auth_list_parser.set_defaults(func=lambda args: AuthListCommand(args))
99
-
100
-
101
- class BaseUserCommand:
102
- def __init__(self, args):
103
- self.args = args
104
- self._api = HfApi()
105
-
106
-
107
- class LoginCommand(BaseUserCommand):
108
- def run(self):
109
- show_deprecation_warning("huggingface-cli login", "hf auth login")
110
-
111
- logging.set_verbosity_info()
112
- login(
113
- token=self.args.token,
114
- add_to_git_credential=self.args.add_to_git_credential,
115
- )
116
-
117
-
118
- class LogoutCommand(BaseUserCommand):
119
- def run(self):
120
- show_deprecation_warning("huggingface-cli logout", "hf auth logout")
121
-
122
- logging.set_verbosity_info()
123
- logout(token_name=self.args.token_name)
124
-
125
-
126
- class AuthSwitchCommand(BaseUserCommand):
127
- def run(self):
128
- show_deprecation_warning("huggingface-cli auth switch", "hf auth switch")
129
-
130
- logging.set_verbosity_info()
131
- token_name = self.args.token_name
132
- if token_name is None:
133
- token_name = self._select_token_name()
134
-
135
- if token_name is None:
136
- print("No token name provided. Aborting.")
137
- exit()
138
- auth_switch(token_name, add_to_git_credential=self.args.add_to_git_credential)
139
-
140
- def _select_token_name(self) -> Optional[str]:
141
- token_names = list(get_stored_tokens().keys())
142
-
143
- if not token_names:
144
- logger.error("No stored tokens found. Please login first.")
145
- return None
146
-
147
- if _inquirer_py_available:
148
- return self._select_token_name_tui(token_names)
149
- # if inquirer is not available, use a simpler terminal UI
150
- print("Available stored tokens:")
151
- for i, token_name in enumerate(token_names, 1):
152
- print(f"{i}. {token_name}")
153
- while True:
154
- try:
155
- choice = input("Enter the number of the token to switch to (or 'q' to quit): ")
156
- if choice.lower() == "q":
157
- return None
158
- index = int(choice) - 1
159
- if 0 <= index < len(token_names):
160
- return token_names[index]
161
- else:
162
- print("Invalid selection. Please try again.")
163
- except ValueError:
164
- print("Invalid input. Please enter a number or 'q' to quit.")
165
-
166
- def _select_token_name_tui(self, token_names: list[str]) -> Optional[str]:
167
- choices = [Choice(token_name, name=token_name) for token_name in token_names]
168
- try:
169
- return inquirer.select(
170
- message="Select a token to switch to:",
171
- choices=choices,
172
- default=None,
173
- ).execute()
174
- except KeyboardInterrupt:
175
- logger.info("Token selection cancelled.")
176
- return None
177
-
178
-
179
- class AuthListCommand(BaseUserCommand):
180
- def run(self):
181
- show_deprecation_warning("huggingface-cli auth list", "hf auth list")
182
-
183
- logging.set_verbosity_info()
184
- auth_list()
185
-
186
-
187
- class WhoamiCommand(BaseUserCommand):
188
- def run(self):
189
- show_deprecation_warning("huggingface-cli whoami", "hf auth whoami")
190
-
191
- token = get_token()
192
- if token is None:
193
- print("Not logged in")
194
- exit()
195
- try:
196
- info = self._api.whoami(token)
197
- print(info["name"])
198
- orgs = [org["name"] for org in info["orgs"]]
199
- if orgs:
200
- print(ANSI.bold("orgs: "), ",".join(orgs))
201
-
202
- if ENDPOINT != "https://huggingface.co":
203
- print(f"Authenticated through private endpoint: {ENDPOINT}")
204
- except HfHubHTTPError as e:
205
- print(e)
206
- print(ANSI.red(e.response.text))
207
- exit(1)
@@ -1,40 +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 version.
15
-
16
- Usage:
17
- huggingface-cli version
18
- """
19
-
20
- from argparse import _SubParsersAction
21
-
22
- from huggingface_hub import __version__
23
-
24
- from . import BaseHuggingfaceCLICommand
25
- from ._cli_utils import show_deprecation_warning
26
-
27
-
28
- class VersionCommand(BaseHuggingfaceCLICommand):
29
- def __init__(self, args):
30
- self.args = args
31
-
32
- @staticmethod
33
- def register_subcommand(parser: _SubParsersAction):
34
- version_parser = parser.add_parser("version", help="Print information about the huggingface-cli version.")
35
- version_parser.set_defaults(func=VersionCommand)
36
-
37
- def run(self) -> None:
38
- show_deprecation_warning("huggingface-cli version", "hf version")
39
-
40
- print(f"huggingface_hub version: {__version__}")