mirror of
https://github.com/huggingface/text-generation-inference.git
synced 2025-09-10 20:04:52 +00:00
raise exception on invalid images
This commit is contained in:
parent
0a63e9ab68
commit
6cb066eb01
@ -183,7 +183,12 @@ class IdeficsImageProcessor(BaseImageProcessor):
|
||||
elif isinstance(image_url_or_urls, str):
|
||||
response = requests.get(image_url_or_urls, stream=True, headers=headers)
|
||||
response.raise_for_status()
|
||||
return Image.open(BytesIO(response.content))
|
||||
try:
|
||||
image = Image.open(BytesIO(response.content))
|
||||
image.verify()
|
||||
except Exception:
|
||||
raise ValueError(f"Could not load image from url {image_url_or_urls}")
|
||||
return image
|
||||
else:
|
||||
raise ValueError(f"only a single or a list of entries is supported but got type={type(image_url_or_urls)}")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user