huggingface-hub 0.25.2__py3-none-any.whl → 0.26.1__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 +45 -11
- huggingface_hub/_login.py +172 -33
- huggingface_hub/commands/user.py +125 -9
- huggingface_hub/constants.py +1 -1
- huggingface_hub/errors.py +6 -9
- huggingface_hub/file_download.py +2 -372
- huggingface_hub/hf_api.py +170 -13
- huggingface_hub/hf_file_system.py +3 -3
- huggingface_hub/hub_mixin.py +2 -1
- huggingface_hub/inference/_client.py +500 -145
- huggingface_hub/inference/_common.py +42 -4
- huggingface_hub/inference/_generated/_async_client.py +499 -144
- huggingface_hub/inference/_generated/types/__init__.py +37 -7
- huggingface_hub/inference/_generated/types/audio_classification.py +8 -5
- huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +9 -7
- huggingface_hub/inference/_generated/types/chat_completion.py +23 -4
- huggingface_hub/inference/_generated/types/image_classification.py +8 -5
- huggingface_hub/inference/_generated/types/image_segmentation.py +9 -7
- huggingface_hub/inference/_generated/types/image_to_image.py +7 -5
- huggingface_hub/inference/_generated/types/image_to_text.py +4 -4
- huggingface_hub/inference/_generated/types/object_detection.py +11 -5
- huggingface_hub/inference/_generated/types/summarization.py +11 -13
- huggingface_hub/inference/_generated/types/text_classification.py +10 -5
- huggingface_hub/inference/_generated/types/text_generation.py +1 -0
- huggingface_hub/inference/_generated/types/text_to_audio.py +2 -2
- huggingface_hub/inference/_generated/types/text_to_image.py +9 -7
- huggingface_hub/inference/_generated/types/text_to_speech.py +107 -0
- huggingface_hub/inference/_generated/types/translation.py +17 -11
- huggingface_hub/inference/_generated/types/video_classification.py +2 -2
- huggingface_hub/repocard.py +2 -1
- huggingface_hub/repocard_data.py +10 -2
- huggingface_hub/serialization/_torch.py +7 -4
- huggingface_hub/utils/__init__.py +4 -20
- huggingface_hub/utils/{_token.py → _auth.py} +86 -3
- huggingface_hub/utils/_headers.py +1 -1
- huggingface_hub/utils/_hf_folder.py +1 -1
- huggingface_hub/utils/_http.py +10 -4
- huggingface_hub/utils/_runtime.py +1 -10
- {huggingface_hub-0.25.2.dist-info → huggingface_hub-0.26.1.dist-info}/METADATA +12 -12
- {huggingface_hub-0.25.2.dist-info → huggingface_hub-0.26.1.dist-info}/RECORD +44 -44
- huggingface_hub/inference/_templating.py +0 -102
- {huggingface_hub-0.25.2.dist-info → huggingface_hub-0.26.1.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.25.2.dist-info → huggingface_hub-0.26.1.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.25.2.dist-info → huggingface_hub-0.26.1.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.25.2.dist-info → huggingface_hub-0.26.1.dist-info}/top_level.txt +0 -0
|
@@ -58,10 +58,7 @@ from ..utils import (
|
|
|
58
58
|
is_numpy_available,
|
|
59
59
|
is_pillow_available,
|
|
60
60
|
)
|
|
61
|
-
from ._generated.types import
|
|
62
|
-
ChatCompletionStreamOutput,
|
|
63
|
-
TextGenerationStreamOutput,
|
|
64
|
-
)
|
|
61
|
+
from ._generated.types import ChatCompletionStreamOutput, TextGenerationStreamOutput
|
|
65
62
|
|
|
66
63
|
|
|
67
64
|
if TYPE_CHECKING:
|
|
@@ -259,6 +256,47 @@ def _bytes_to_image(content: bytes) -> "Image":
|
|
|
259
256
|
return Image.open(io.BytesIO(content))
|
|
260
257
|
|
|
261
258
|
|
|
259
|
+
## PAYLOAD UTILS
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def _prepare_payload(
|
|
263
|
+
inputs: Union[str, Dict[str, Any], ContentT],
|
|
264
|
+
parameters: Optional[Dict[str, Any]],
|
|
265
|
+
expect_binary: bool = False,
|
|
266
|
+
) -> Dict[str, Any]:
|
|
267
|
+
"""
|
|
268
|
+
Used in `InferenceClient` and `AsyncInferenceClient` to prepare the payload for an API request, handling various input types and parameters.
|
|
269
|
+
`expect_binary` is set to `True` when the inputs are a binary object or a local path or URL. This is the case for image and audio inputs.
|
|
270
|
+
"""
|
|
271
|
+
if parameters is None:
|
|
272
|
+
parameters = {}
|
|
273
|
+
parameters = {k: v for k, v in parameters.items() if v is not None}
|
|
274
|
+
has_parameters = len(parameters) > 0
|
|
275
|
+
|
|
276
|
+
is_binary = isinstance(inputs, (bytes, Path))
|
|
277
|
+
# If expect_binary is True, inputs must be a binary object or a local path or a URL.
|
|
278
|
+
if expect_binary and not is_binary and not isinstance(inputs, str):
|
|
279
|
+
raise ValueError(f"Expected binary inputs or a local path or a URL. Got {inputs}") # type: ignore
|
|
280
|
+
# Send inputs as raw content when no parameters are provided
|
|
281
|
+
if expect_binary and not has_parameters:
|
|
282
|
+
return {"data": inputs}
|
|
283
|
+
# If expect_binary is False, inputs must not be a binary object.
|
|
284
|
+
if not expect_binary and is_binary:
|
|
285
|
+
raise ValueError(f"Unexpected binary inputs. Got {inputs}") # type: ignore
|
|
286
|
+
|
|
287
|
+
json: Dict[str, Any] = {}
|
|
288
|
+
# If inputs is a bytes-like object, encode it to base64
|
|
289
|
+
if expect_binary:
|
|
290
|
+
json["inputs"] = _b64_encode(inputs) # type: ignore
|
|
291
|
+
# Otherwise (string, dict, list) send it as is
|
|
292
|
+
else:
|
|
293
|
+
json["inputs"] = inputs
|
|
294
|
+
# Add parameters to the json payload if any
|
|
295
|
+
if has_parameters:
|
|
296
|
+
json["parameters"] = parameters
|
|
297
|
+
return {"json": json}
|
|
298
|
+
|
|
299
|
+
|
|
262
300
|
## STREAMING UTILS
|
|
263
301
|
|
|
264
302
|
|