diff --git a/server/text_generation_server/models/custom_modeling/idefics_image_processing.py b/server/text_generation_server/models/custom_modeling/idefics_image_processing.py index 6fb00999..061243fb 100644 --- a/server/text_generation_server/models/custom_modeling/idefics_image_processing.py +++ b/server/text_generation_server/models/custom_modeling/idefics_image_processing.py @@ -194,9 +194,14 @@ class IdeficsImageProcessor(BaseImageProcessor): if isinstance(image_url_or_urls, list): return [self.fetch_images(x) for x in image_url_or_urls] elif isinstance(image_url_or_urls, str): - response = requests.get(image_url_or_urls, stream=True, headers=headers) + response = requests.get(image_url_or_urls, stream=True, headers=headers, timeout=(1, 5)) 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)}"