Skip to content

Commit 8c5770f

Browse files
committed
Release: v0.33.2
1 parent d7407a8 commit 8c5770f

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

src/huggingface_hub/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from typing import TYPE_CHECKING
4747

4848

49-
__version__ = "0.33.1"
49+
__version__ = "0.33.2"
5050

5151
# Alphabetical order of definitions is ensured in tests
5252
# WARNING: any comment added in this dictionary definition will be lost when

src/huggingface_hub/inference/_client.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,8 @@ def document_question_answering(
947947
Answer questions on document images.
948948
949949
Args:
950-
image (`Union[str, Path, bytes, BinaryIO]`):
951-
The input image for the context. It can be raw bytes, an image file, or a URL to an online image.
950+
image (`Union[str, Path, bytes, BinaryIO, PIL.Image.Image]`):
951+
The input image for the context. It can be raw bytes, an image file, a URL to an online image, or a PIL Image.
952952
question (`str`):
953953
Question to be answered.
954954
model (`str`, *optional*):
@@ -1156,8 +1156,8 @@ def image_classification(
11561156
Perform image classification on the given image using the specified model.
11571157
11581158
Args:
1159-
image (`Union[str, Path, bytes, BinaryIO]`):
1160-
The image to classify. It can be raw bytes, an image file, or a URL to an online image.
1159+
image (`Union[str, Path, bytes, BinaryIO, PIL.Image.Image]`):
1160+
The image to classify. It can be raw bytes, an image file, a URL to an online image, or a PIL Image.
11611161
model (`str`, *optional*):
11621162
The model to use for image classification. Can be a model ID hosted on the Hugging Face Hub or a URL to a
11631163
deployed Inference Endpoint. If not provided, the default recommended model for image classification will be used.
@@ -1214,8 +1214,8 @@ def image_segmentation(
12141214
</Tip>
12151215
12161216
Args:
1217-
image (`Union[str, Path, bytes, BinaryIO]`):
1218-
The image to segment. It can be raw bytes, an image file, or a URL to an online image.
1217+
image (`Union[str, Path, bytes, BinaryIO, PIL.Image.Image]`):
1218+
The image to segment. It can be raw bytes, an image file, a URL to an online image, or a PIL Image.
12191219
model (`str`, *optional*):
12201220
The model to use for image segmentation. Can be a model ID hosted on the Hugging Face Hub or a URL to a
12211221
deployed Inference Endpoint. If not provided, the default recommended model for image segmentation will be used.
@@ -1286,8 +1286,8 @@ def image_to_image(
12861286
</Tip>
12871287
12881288
Args:
1289-
image (`Union[str, Path, bytes, BinaryIO]`):
1290-
The input image for translation. It can be raw bytes, an image file, or a URL to an online image.
1289+
image (`Union[str, Path, bytes, BinaryIO, PIL.Image.Image]`):
1290+
The input image for translation. It can be raw bytes, an image file, a URL to an online image, or a PIL Image.
12911291
prompt (`str`, *optional*):
12921292
The text prompt to guide the image generation.
12931293
negative_prompt (`str`, *optional*):
@@ -1348,8 +1348,8 @@ def image_to_text(self, image: ContentT, *, model: Optional[str] = None) -> Imag
13481348
(OCR), Pix2Struct, etc). Please have a look to the model card to learn more about a model's specificities.
13491349
13501350
Args:
1351-
image (`Union[str, Path, bytes, BinaryIO]`):
1352-
The input image to caption. It can be raw bytes, an image file, or a URL to an online image..
1351+
image (`Union[str, Path, bytes, BinaryIO, PIL.Image.Image]`):
1352+
The input image to caption. It can be raw bytes, an image file, a URL to an online image, or a PIL Image.
13531353
model (`str`, *optional*):
13541354
The model to use for inference. Can be a model ID hosted on the Hugging Face Hub or a URL to a deployed
13551355
Inference Endpoint. This parameter overrides the model defined at the instance level. Defaults to None.
@@ -1399,8 +1399,8 @@ def object_detection(
13991399
</Tip>
14001400
14011401
Args:
1402-
image (`Union[str, Path, bytes, BinaryIO]`):
1403-
The image to detect objects on. It can be raw bytes, an image file, or a URL to an online image.
1402+
image (`Union[str, Path, bytes, BinaryIO, PIL.Image.Image]`):
1403+
The image to detect objects on. It can be raw bytes, an image file, a URL to an online image, or a PIL Image.
14041404
model (`str`, *optional*):
14051405
The model to use for object detection. Can be a model ID hosted on the Hugging Face Hub or a URL to a
14061406
deployed Inference Endpoint. If not provided, the default recommended model for object detection (DETR) will be used.
@@ -2974,8 +2974,8 @@ def visual_question_answering(
29742974
Answering open-ended questions based on an image.
29752975
29762976
Args:
2977-
image (`Union[str, Path, bytes, BinaryIO]`):
2978-
The input image for the context. It can be raw bytes, an image file, or a URL to an online image.
2977+
image (`Union[str, Path, bytes, BinaryIO, PIL.Image.Image]`):
2978+
The input image for the context. It can be raw bytes, an image file, a URL to an online image, or a PIL Image.
29792979
question (`str`):
29802980
Question to be answered.
29812981
model (`str`, *optional*):
@@ -3141,8 +3141,8 @@ def zero_shot_image_classification(
31413141
Provide input image and text labels to predict text labels for the image.
31423142
31433143
Args:
3144-
image (`Union[str, Path, bytes, BinaryIO]`):
3145-
The input image to caption. It can be raw bytes, an image file, or a URL to an online image.
3144+
image (`Union[str, Path, bytes, BinaryIO, PIL.Image.Image]`):
3145+
The input image to caption. It can be raw bytes, an image file, a URL to an online image, or a PIL Image.
31463146
candidate_labels (`List[str]`):
31473147
The candidate labels for this image
31483148
labels (`List[str]`, *optional*):

src/huggingface_hub/inference/_common.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
UrlT = str
6262
PathT = Union[str, Path]
6363
BinaryT = Union[bytes, BinaryIO]
64-
ContentT = Union[BinaryT, PathT, UrlT]
64+
ContentT = Union[BinaryT, PathT, UrlT, "Image"]
6565

6666
# Use to set a Accept: image/png header
6767
TASKS_EXPECTING_IMAGES = {"text-to-image", "image-to-image"}
@@ -164,7 +164,6 @@ def _open_as_binary(content: Optional[ContentT]) -> Generator[Optional[BinaryT],
164164
165165
Do nothing if `content` is None,
166166
167-
TODO: handle a PIL.Image as input
168167
TODO: handle base64 as input
169168
"""
170169
# If content is a string => must be either a URL or a path
@@ -185,6 +184,12 @@ def _open_as_binary(content: Optional[ContentT]) -> Generator[Optional[BinaryT],
185184
logger.debug(f"Opening content from {content}")
186185
with content.open("rb") as f:
187186
yield f
187+
elif hasattr(content, "save"): # PIL Image
188+
logger.debug("Converting PIL Image to bytes")
189+
buffer = io.BytesIO()
190+
content.save(buffer, format="PNG")
191+
buffer.seek(0)
192+
yield buffer
188193
else:
189194
# Otherwise: already a file-like object or None
190195
yield content

0 commit comments

Comments
 (0)