huggingface-hub 0.36.0__py3-none-any.whl → 1.0.0__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 (132) hide show
  1. huggingface_hub/__init__.py +33 -45
  2. huggingface_hub/_commit_api.py +39 -43
  3. huggingface_hub/_commit_scheduler.py +11 -8
  4. huggingface_hub/_inference_endpoints.py +8 -8
  5. huggingface_hub/_jobs_api.py +20 -20
  6. huggingface_hub/_login.py +17 -43
  7. huggingface_hub/_oauth.py +8 -8
  8. huggingface_hub/_snapshot_download.py +135 -50
  9. huggingface_hub/_space_api.py +4 -4
  10. huggingface_hub/_tensorboard_logger.py +5 -5
  11. huggingface_hub/_upload_large_folder.py +18 -32
  12. huggingface_hub/_webhooks_payload.py +3 -3
  13. huggingface_hub/_webhooks_server.py +2 -2
  14. huggingface_hub/cli/__init__.py +0 -14
  15. huggingface_hub/cli/_cli_utils.py +143 -39
  16. huggingface_hub/cli/auth.py +105 -171
  17. huggingface_hub/cli/cache.py +594 -361
  18. huggingface_hub/cli/download.py +120 -112
  19. huggingface_hub/cli/hf.py +38 -41
  20. huggingface_hub/cli/jobs.py +689 -1017
  21. huggingface_hub/cli/lfs.py +120 -143
  22. huggingface_hub/cli/repo.py +282 -216
  23. huggingface_hub/cli/repo_files.py +50 -84
  24. huggingface_hub/cli/system.py +6 -25
  25. huggingface_hub/cli/upload.py +198 -220
  26. huggingface_hub/cli/upload_large_folder.py +91 -106
  27. huggingface_hub/community.py +5 -5
  28. huggingface_hub/constants.py +17 -52
  29. huggingface_hub/dataclasses.py +135 -21
  30. huggingface_hub/errors.py +47 -30
  31. huggingface_hub/fastai_utils.py +8 -9
  32. huggingface_hub/file_download.py +351 -303
  33. huggingface_hub/hf_api.py +398 -570
  34. huggingface_hub/hf_file_system.py +101 -66
  35. huggingface_hub/hub_mixin.py +32 -54
  36. huggingface_hub/inference/_client.py +177 -162
  37. huggingface_hub/inference/_common.py +38 -54
  38. huggingface_hub/inference/_generated/_async_client.py +218 -258
  39. huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +3 -3
  40. huggingface_hub/inference/_generated/types/base.py +10 -7
  41. huggingface_hub/inference/_generated/types/chat_completion.py +16 -16
  42. huggingface_hub/inference/_generated/types/depth_estimation.py +2 -2
  43. huggingface_hub/inference/_generated/types/document_question_answering.py +2 -2
  44. huggingface_hub/inference/_generated/types/feature_extraction.py +2 -2
  45. huggingface_hub/inference/_generated/types/fill_mask.py +2 -2
  46. huggingface_hub/inference/_generated/types/sentence_similarity.py +3 -3
  47. huggingface_hub/inference/_generated/types/summarization.py +2 -2
  48. huggingface_hub/inference/_generated/types/table_question_answering.py +4 -4
  49. huggingface_hub/inference/_generated/types/text2text_generation.py +2 -2
  50. huggingface_hub/inference/_generated/types/text_generation.py +10 -10
  51. huggingface_hub/inference/_generated/types/text_to_video.py +2 -2
  52. huggingface_hub/inference/_generated/types/token_classification.py +2 -2
  53. huggingface_hub/inference/_generated/types/translation.py +2 -2
  54. huggingface_hub/inference/_generated/types/zero_shot_classification.py +2 -2
  55. huggingface_hub/inference/_generated/types/zero_shot_image_classification.py +2 -2
  56. huggingface_hub/inference/_generated/types/zero_shot_object_detection.py +1 -3
  57. huggingface_hub/inference/_mcp/agent.py +3 -3
  58. huggingface_hub/inference/_mcp/constants.py +1 -2
  59. huggingface_hub/inference/_mcp/mcp_client.py +33 -22
  60. huggingface_hub/inference/_mcp/types.py +10 -10
  61. huggingface_hub/inference/_mcp/utils.py +4 -4
  62. huggingface_hub/inference/_providers/__init__.py +12 -4
  63. huggingface_hub/inference/_providers/_common.py +62 -24
  64. huggingface_hub/inference/_providers/black_forest_labs.py +6 -6
  65. huggingface_hub/inference/_providers/cohere.py +3 -3
  66. huggingface_hub/inference/_providers/fal_ai.py +25 -25
  67. huggingface_hub/inference/_providers/featherless_ai.py +4 -4
  68. huggingface_hub/inference/_providers/fireworks_ai.py +3 -3
  69. huggingface_hub/inference/_providers/hf_inference.py +13 -13
  70. huggingface_hub/inference/_providers/hyperbolic.py +4 -4
  71. huggingface_hub/inference/_providers/nebius.py +10 -10
  72. huggingface_hub/inference/_providers/novita.py +5 -5
  73. huggingface_hub/inference/_providers/nscale.py +4 -4
  74. huggingface_hub/inference/_providers/replicate.py +15 -15
  75. huggingface_hub/inference/_providers/sambanova.py +6 -6
  76. huggingface_hub/inference/_providers/together.py +7 -7
  77. huggingface_hub/lfs.py +21 -94
  78. huggingface_hub/repocard.py +15 -16
  79. huggingface_hub/repocard_data.py +57 -57
  80. huggingface_hub/serialization/__init__.py +0 -1
  81. huggingface_hub/serialization/_base.py +9 -9
  82. huggingface_hub/serialization/_dduf.py +7 -7
  83. huggingface_hub/serialization/_torch.py +28 -28
  84. huggingface_hub/utils/__init__.py +11 -6
  85. huggingface_hub/utils/_auth.py +5 -5
  86. huggingface_hub/utils/_cache_manager.py +49 -74
  87. huggingface_hub/utils/_deprecation.py +1 -1
  88. huggingface_hub/utils/_dotenv.py +3 -3
  89. huggingface_hub/utils/_fixes.py +0 -10
  90. huggingface_hub/utils/_git_credential.py +3 -3
  91. huggingface_hub/utils/_headers.py +7 -29
  92. huggingface_hub/utils/_http.py +371 -208
  93. huggingface_hub/utils/_pagination.py +4 -4
  94. huggingface_hub/utils/_parsing.py +98 -0
  95. huggingface_hub/utils/_paths.py +5 -5
  96. huggingface_hub/utils/_runtime.py +59 -23
  97. huggingface_hub/utils/_safetensors.py +21 -21
  98. huggingface_hub/utils/_subprocess.py +9 -9
  99. huggingface_hub/utils/_telemetry.py +3 -3
  100. huggingface_hub/{commands/_cli_utils.py → utils/_terminal.py} +4 -9
  101. huggingface_hub/utils/_typing.py +3 -3
  102. huggingface_hub/utils/_validators.py +53 -72
  103. huggingface_hub/utils/_xet.py +16 -16
  104. huggingface_hub/utils/_xet_progress_reporting.py +1 -1
  105. huggingface_hub/utils/insecure_hashlib.py +3 -9
  106. huggingface_hub/utils/tqdm.py +3 -3
  107. {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/METADATA +16 -35
  108. huggingface_hub-1.0.0.dist-info/RECORD +152 -0
  109. {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/entry_points.txt +0 -1
  110. huggingface_hub/commands/__init__.py +0 -27
  111. huggingface_hub/commands/delete_cache.py +0 -476
  112. huggingface_hub/commands/download.py +0 -204
  113. huggingface_hub/commands/env.py +0 -39
  114. huggingface_hub/commands/huggingface_cli.py +0 -65
  115. huggingface_hub/commands/lfs.py +0 -200
  116. huggingface_hub/commands/repo.py +0 -151
  117. huggingface_hub/commands/repo_files.py +0 -132
  118. huggingface_hub/commands/scan_cache.py +0 -183
  119. huggingface_hub/commands/tag.py +0 -161
  120. huggingface_hub/commands/upload.py +0 -318
  121. huggingface_hub/commands/upload_large_folder.py +0 -131
  122. huggingface_hub/commands/user.py +0 -208
  123. huggingface_hub/commands/version.py +0 -40
  124. huggingface_hub/inference_api.py +0 -217
  125. huggingface_hub/keras_mixin.py +0 -497
  126. huggingface_hub/repository.py +0 -1471
  127. huggingface_hub/serialization/_tensorflow.py +0 -92
  128. huggingface_hub/utils/_hf_folder.py +0 -68
  129. huggingface_hub-0.36.0.dist-info/RECORD +0 -170
  130. {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/LICENSE +0 -0
  131. {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/WHEEL +0 -0
  132. {huggingface_hub-0.36.0.dist-info → huggingface_hub-1.0.0.dist-info}/top_level.txt +0 -0
@@ -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__}")
@@ -1,217 +0,0 @@
1
- import io
2
- from typing import Any, Dict, List, Optional, Union
3
-
4
- from . import constants
5
- from .hf_api import HfApi
6
- from .utils import build_hf_headers, get_session, is_pillow_available, logging, validate_hf_hub_args
7
- from .utils._deprecation import _deprecate_method
8
-
9
-
10
- logger = logging.get_logger(__name__)
11
-
12
-
13
- ALL_TASKS = [
14
- # NLP
15
- "text-classification",
16
- "token-classification",
17
- "table-question-answering",
18
- "question-answering",
19
- "zero-shot-classification",
20
- "translation",
21
- "summarization",
22
- "conversational",
23
- "feature-extraction",
24
- "text-generation",
25
- "text2text-generation",
26
- "fill-mask",
27
- "sentence-similarity",
28
- # Audio
29
- "text-to-speech",
30
- "automatic-speech-recognition",
31
- "audio-to-audio",
32
- "audio-classification",
33
- "voice-activity-detection",
34
- # Computer vision
35
- "image-classification",
36
- "object-detection",
37
- "image-segmentation",
38
- "text-to-image",
39
- "image-to-image",
40
- # Others
41
- "tabular-classification",
42
- "tabular-regression",
43
- ]
44
-
45
-
46
- class InferenceApi:
47
- """Client to configure requests and make calls to the HuggingFace Inference API.
48
-
49
- Example:
50
-
51
- ```python
52
- >>> from huggingface_hub.inference_api import InferenceApi
53
-
54
- >>> # Mask-fill example
55
- >>> inference = InferenceApi("bert-base-uncased")
56
- >>> inference(inputs="The goal of life is [MASK].")
57
- [{'sequence': 'the goal of life is life.', 'score': 0.10933292657136917, 'token': 2166, 'token_str': 'life'}]
58
-
59
- >>> # Question Answering example
60
- >>> inference = InferenceApi("deepset/roberta-base-squad2")
61
- >>> inputs = {
62
- ... "question": "What's my name?",
63
- ... "context": "My name is Clara and I live in Berkeley.",
64
- ... }
65
- >>> inference(inputs)
66
- {'score': 0.9326569437980652, 'start': 11, 'end': 16, 'answer': 'Clara'}
67
-
68
- >>> # Zero-shot example
69
- >>> inference = InferenceApi("typeform/distilbert-base-uncased-mnli")
70
- >>> inputs = "Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!"
71
- >>> params = {"candidate_labels": ["refund", "legal", "faq"]}
72
- >>> inference(inputs, params)
73
- {'sequence': 'Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!', 'labels': ['refund', 'faq', 'legal'], 'scores': [0.9378499388694763, 0.04914155602455139, 0.013008488342165947]}
74
-
75
- >>> # Overriding configured task
76
- >>> inference = InferenceApi("bert-base-uncased", task="feature-extraction")
77
-
78
- >>> # Text-to-image
79
- >>> inference = InferenceApi("stabilityai/stable-diffusion-2-1")
80
- >>> inference("cat")
81
- <PIL.PngImagePlugin.PngImageFile image (...)>
82
-
83
- >>> # Return as raw response to parse the output yourself
84
- >>> inference = InferenceApi("mio/amadeus")
85
- >>> response = inference("hello world", raw_response=True)
86
- >>> response.headers
87
- {"Content-Type": "audio/flac", ...}
88
- >>> response.content # raw bytes from server
89
- b'(...)'
90
- ```
91
- """
92
-
93
- @validate_hf_hub_args
94
- @_deprecate_method(
95
- version="1.0",
96
- message=(
97
- "`InferenceApi` client is deprecated in favor of the more feature-complete `InferenceClient`. Check out"
98
- " this guide to learn how to convert your script to use it:"
99
- " https://huggingface.co/docs/huggingface_hub/guides/inference#legacy-inferenceapi-client."
100
- ),
101
- )
102
- def __init__(
103
- self,
104
- repo_id: str,
105
- task: Optional[str] = None,
106
- token: Optional[str] = None,
107
- gpu: bool = False,
108
- ):
109
- """Inits headers and API call information.
110
-
111
- Args:
112
- repo_id (``str``):
113
- Id of repository (e.g. `user/bert-base-uncased`).
114
- task (``str``, `optional`, defaults ``None``):
115
- Whether to force a task instead of using task specified in the
116
- repository.
117
- token (`str`, `optional`):
118
- The API token to use as HTTP bearer authorization. This is not
119
- the authentication token. You can find the token in
120
- https://huggingface.co/settings/token. Alternatively, you can
121
- find both your organizations and personal API tokens using
122
- `HfApi().whoami(token)`.
123
- gpu (`bool`, `optional`, defaults `False`):
124
- Whether to use GPU instead of CPU for inference(requires Startup
125
- plan at least).
126
- """
127
- self.options = {"wait_for_model": True, "use_gpu": gpu}
128
- self.headers = build_hf_headers(token=token)
129
-
130
- # Configure task
131
- model_info = HfApi(token=token).model_info(repo_id=repo_id)
132
- if not model_info.pipeline_tag and not task:
133
- raise ValueError(
134
- "Task not specified in the repository. Please add it to the model card"
135
- " using pipeline_tag"
136
- " (https://huggingface.co/docs#how-is-a-models-type-of-inference-api-and-widget-determined)"
137
- )
138
-
139
- if task and task != model_info.pipeline_tag:
140
- if task not in ALL_TASKS:
141
- raise ValueError(f"Invalid task {task}. Make sure it's valid.")
142
-
143
- logger.warning(
144
- "You're using a different task than the one specified in the"
145
- " repository. Be sure to know what you're doing :)"
146
- )
147
- self.task = task
148
- else:
149
- assert model_info.pipeline_tag is not None, "Pipeline tag cannot be None"
150
- self.task = model_info.pipeline_tag
151
-
152
- self.api_url = f"{constants.INFERENCE_ENDPOINT}/pipeline/{self.task}/{repo_id}"
153
-
154
- def __repr__(self):
155
- # Do not add headers to repr to avoid leaking token.
156
- return f"InferenceAPI(api_url='{self.api_url}', task='{self.task}', options={self.options})"
157
-
158
- def __call__(
159
- self,
160
- inputs: Optional[Union[str, Dict, List[str], List[List[str]]]] = None,
161
- params: Optional[Dict] = None,
162
- data: Optional[bytes] = None,
163
- raw_response: bool = False,
164
- ) -> Any:
165
- """Make a call to the Inference API.
166
-
167
- Args:
168
- inputs (`str` or `Dict` or `List[str]` or `List[List[str]]`, *optional*):
169
- Inputs for the prediction.
170
- params (`Dict`, *optional*):
171
- Additional parameters for the models. Will be sent as `parameters` in the
172
- payload.
173
- data (`bytes`, *optional*):
174
- Bytes content of the request. In this case, leave `inputs` and `params` empty.
175
- raw_response (`bool`, defaults to `False`):
176
- If `True`, the raw `Response` object is returned. You can parse its content
177
- as preferred. By default, the content is parsed into a more practical format
178
- (json dictionary or PIL Image for example).
179
- """
180
- # Build payload
181
- payload: Dict[str, Any] = {
182
- "options": self.options,
183
- }
184
- if inputs:
185
- payload["inputs"] = inputs
186
- if params:
187
- payload["parameters"] = params
188
-
189
- # Make API call
190
- response = get_session().post(self.api_url, headers=self.headers, json=payload, data=data)
191
-
192
- # Let the user handle the response
193
- if raw_response:
194
- return response
195
-
196
- # By default, parse the response for the user.
197
- content_type = response.headers.get("Content-Type") or ""
198
- if content_type.startswith("image"):
199
- if not is_pillow_available():
200
- raise ImportError(
201
- f"Task '{self.task}' returned as image but Pillow is not installed."
202
- " Please install it (`pip install Pillow`) or pass"
203
- " `raw_response=True` to get the raw `Response` object and parse"
204
- " the image by yourself."
205
- )
206
-
207
- from PIL import Image
208
-
209
- return Image.open(io.BytesIO(response.content))
210
- elif content_type == "application/json":
211
- return response.json()
212
- else:
213
- raise NotImplementedError(
214
- f"{content_type} output type is not implemented yet. You can pass"
215
- " `raw_response=True` to get the raw `Response` object and parse the"
216
- " output by yourself."
217
- )