huggingface-hub 1.0.0rc0__py3-none-any.whl → 1.0.0rc2__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 (48) hide show
  1. huggingface_hub/__init__.py +4 -4
  2. huggingface_hub/_commit_api.py +126 -66
  3. huggingface_hub/_commit_scheduler.py +4 -7
  4. huggingface_hub/_login.py +9 -15
  5. huggingface_hub/_tensorboard_logger.py +2 -5
  6. huggingface_hub/_webhooks_server.py +8 -20
  7. huggingface_hub/cli/__init__.py +0 -14
  8. huggingface_hub/cli/_cli_utils.py +79 -2
  9. huggingface_hub/cli/auth.py +104 -149
  10. huggingface_hub/cli/cache.py +97 -121
  11. huggingface_hub/cli/download.py +93 -110
  12. huggingface_hub/cli/hf.py +37 -41
  13. huggingface_hub/cli/jobs.py +687 -1014
  14. huggingface_hub/cli/lfs.py +116 -139
  15. huggingface_hub/cli/repo.py +290 -214
  16. huggingface_hub/cli/repo_files.py +50 -84
  17. huggingface_hub/cli/system.py +6 -25
  18. huggingface_hub/cli/upload.py +198 -212
  19. huggingface_hub/cli/upload_large_folder.py +90 -105
  20. huggingface_hub/dataclasses.py +3 -12
  21. huggingface_hub/errors.py +1 -1
  22. huggingface_hub/fastai_utils.py +22 -32
  23. huggingface_hub/file_download.py +18 -21
  24. huggingface_hub/hf_api.py +258 -410
  25. huggingface_hub/hf_file_system.py +17 -44
  26. huggingface_hub/inference/_client.py +25 -47
  27. huggingface_hub/inference/_generated/_async_client.py +25 -47
  28. huggingface_hub/inference/_mcp/agent.py +2 -5
  29. huggingface_hub/inference/_mcp/mcp_client.py +2 -5
  30. huggingface_hub/inference/_providers/__init__.py +11 -0
  31. huggingface_hub/inference/_providers/_common.py +1 -0
  32. huggingface_hub/inference/_providers/publicai.py +6 -0
  33. huggingface_hub/inference/_providers/scaleway.py +28 -0
  34. huggingface_hub/lfs.py +14 -8
  35. huggingface_hub/repocard.py +12 -16
  36. huggingface_hub/serialization/_base.py +3 -6
  37. huggingface_hub/serialization/_torch.py +16 -34
  38. huggingface_hub/utils/__init__.py +1 -1
  39. huggingface_hub/utils/_cache_manager.py +41 -71
  40. huggingface_hub/utils/_chunk_utils.py +2 -3
  41. huggingface_hub/utils/_http.py +32 -35
  42. huggingface_hub/utils/logging.py +8 -11
  43. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/METADATA +7 -2
  44. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/RECORD +48 -46
  45. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/LICENSE +0 -0
  46. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/WHEEL +0 -0
  47. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/entry_points.txt +0 -0
  48. {huggingface_hub-1.0.0rc0.dist-info → huggingface_hub-1.0.0rc2.dist-info}/top_level.txt +0 -0
@@ -37,145 +37,128 @@ Usage:
37
37
  """
38
38
 
39
39
  import warnings
40
- from argparse import Namespace, _SubParsersAction
41
- from typing import Optional
40
+ from typing import Annotated, Optional
41
+
42
+ import typer
42
43
 
43
44
  from huggingface_hub import logging
44
45
  from huggingface_hub._snapshot_download import snapshot_download
45
- from huggingface_hub.commands import BaseHuggingfaceCLICommand
46
46
  from huggingface_hub.file_download import hf_hub_download
47
47
  from huggingface_hub.utils import disable_progress_bars, enable_progress_bars
48
48
 
49
+ from ._cli_utils import RepoIdArg, RepoTypeOpt, RevisionOpt, TokenOpt
50
+
49
51
 
50
52
  logger = logging.get_logger(__name__)
51
53
 
52
54
 
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",
55
+ def download(
56
+ repo_id: RepoIdArg,
57
+ filenames: Annotated[
58
+ Optional[list[str]],
59
+ typer.Argument(
60
+ help="Files to download (e.g. `config.json`, `data/metadata.jsonl`).",
61
+ ),
62
+ ] = None,
63
+ repo_type: RepoTypeOpt = RepoTypeOpt.model,
64
+ revision: RevisionOpt = None,
65
+ include: Annotated[
66
+ Optional[list[str]],
67
+ typer.Option(
68
+ help="Glob patterns to include from files to download. eg: *.json",
69
+ ),
70
+ ] = None,
71
+ exclude: Annotated[
72
+ Optional[list[str]],
73
+ typer.Option(
74
+ help="Glob patterns to exclude from files to download.",
75
+ ),
76
+ ] = None,
77
+ cache_dir: Annotated[
78
+ Optional[str],
79
+ typer.Option(
80
+ help="Directory where to save files.",
81
+ ),
82
+ ] = None,
83
+ local_dir: Annotated[
84
+ Optional[str],
85
+ typer.Option(
86
+ help="If set, the downloaded file will be placed under this directory. Check out https://huggingface.co/docs/huggingface_hub/guides/download#download-files-to-local-folder for more details.",
87
+ ),
88
+ ] = None,
89
+ force_download: Annotated[
90
+ bool,
91
+ typer.Option(
95
92
  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",
93
+ ),
94
+ ] = False,
95
+ token: TokenOpt = None,
96
+ quiet: Annotated[
97
+ bool,
98
+ typer.Option(
103
99
  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,
100
+ ),
101
+ ] = False,
102
+ max_workers: Annotated[
103
+ int,
104
+ typer.Option(
109
105
  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()
106
+ ),
107
+ ] = 8,
108
+ ) -> None:
109
+ """Download files from the Hub."""
138
110
 
139
- def _download(self) -> str:
111
+ def run_download() -> str:
112
+ filenames_list = filenames if filenames is not None else []
140
113
  # Warn user if patterns are ignored
141
- if len(self.filenames) > 0:
142
- if self.include is not None and len(self.include) > 0:
114
+ if len(filenames_list) > 0:
115
+ if include is not None and len(include) > 0:
143
116
  warnings.warn("Ignoring `--include` since filenames have being explicitly set.")
144
- if self.exclude is not None and len(self.exclude) > 0:
117
+ if exclude is not None and len(exclude) > 0:
145
118
  warnings.warn("Ignoring `--exclude` since filenames have being explicitly set.")
146
119
 
147
120
  # Single file to download: use `hf_hub_download`
148
- if len(self.filenames) == 1:
121
+ if len(filenames_list) == 1:
149
122
  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,
123
+ repo_id=repo_id,
124
+ repo_type=repo_type.value,
125
+ revision=revision,
126
+ filename=filenames_list[0],
127
+ cache_dir=cache_dir,
128
+ force_download=force_download,
129
+ token=token,
130
+ local_dir=local_dir,
158
131
  library_name="hf",
159
132
  )
160
133
 
161
134
  # 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
135
+ if len(filenames_list) == 0:
136
+ allow_patterns = include
137
+ ignore_patterns = exclude
165
138
  else:
166
- allow_patterns = self.filenames
139
+ allow_patterns = filenames_list
167
140
  ignore_patterns = None
168
141
 
169
142
  return snapshot_download(
170
- repo_id=self.repo_id,
171
- repo_type=self.repo_type,
172
- revision=self.revision,
143
+ repo_id=repo_id,
144
+ repo_type=repo_type.value,
145
+ revision=revision,
173
146
  allow_patterns=allow_patterns,
174
147
  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,
148
+ force_download=force_download,
149
+ cache_dir=cache_dir,
150
+ token=token,
151
+ local_dir=local_dir,
179
152
  library_name="hf",
180
- max_workers=self.max_workers,
153
+ max_workers=max_workers,
181
154
  )
155
+
156
+ if quiet:
157
+ disable_progress_bars()
158
+ with warnings.catch_warnings():
159
+ warnings.simplefilter("ignore")
160
+ print(run_download())
161
+ enable_progress_bars()
162
+ else:
163
+ print(run_download())
164
+ logging.set_verbosity_warning()
huggingface_hub/cli/hf.py CHANGED
@@ -12,51 +12,47 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from argparse import ArgumentParser
16
15
 
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
16
+ from huggingface_hub.cli._cli_utils import typer_factory
17
+ from huggingface_hub.cli.auth import auth_cli
18
+ from huggingface_hub.cli.cache import cache_cli
19
+ from huggingface_hub.cli.download import download
20
+ from huggingface_hub.cli.jobs import jobs_cli
21
+ from huggingface_hub.cli.lfs import lfs_enable_largefiles, lfs_multipart_upload
22
+ from huggingface_hub.cli.repo import repo_cli
23
+ from huggingface_hub.cli.repo_files import repo_files_cli
24
+ from huggingface_hub.cli.system import env, version
25
+
26
+ # from huggingface_hub.cli.jobs import jobs_app
27
+ from huggingface_hub.cli.upload import upload
28
+ from huggingface_hub.cli.upload_large_folder import upload_large_folder
29
+ from huggingface_hub.utils import logging
30
+
31
+
32
+ app = typer_factory(help="Hugging Face Hub CLI")
33
+
34
+
35
+ # top level single commands (defined in their respective files)
36
+ app.command(help="Download files from the Hub.")(download)
37
+ app.command(help="Upload a file or a folder to the Hub.")(upload)
38
+ app.command(help="Upload a large folder to the Hub. Recommended for resumable uploads.")(upload_large_folder)
39
+ app.command(name="env", help="Print information about the environment.")(env)
40
+ app.command(help="Print information about the hf version.")(version)
41
+ app.command(help="Configure your repository to enable upload of files > 5GB.", hidden=True)(lfs_enable_largefiles)
42
+ app.command(help="Upload large files to the Hub.", hidden=True)(lfs_multipart_upload)
43
+
44
+
45
+ # command groups
46
+ app.add_typer(auth_cli, name="auth")
47
+ app.add_typer(cache_cli, name="cache")
48
+ app.add_typer(repo_cli, name="repo")
49
+ app.add_typer(repo_files_cli, name="repo-files")
50
+ app.add_typer(jobs_cli, name="jobs")
27
51
 
28
52
 
29
53
  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
- # Let's go
51
- args = parser.parse_args()
52
- if not hasattr(args, "func"):
53
- parser.print_help()
54
- exit(1)
55
-
56
- # Run
57
- service = args.func(args)
58
- if service is not None:
59
- service.run()
54
+ logging.set_verbosity_info()
55
+ app()
60
56
 
61
57
 
62
58
  if __name__ == "__main__":