File size: 460 Bytes
cd0e36b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from __future__ import annotations

from io import BytesIO

from PIL import Image, UnidentifiedImageError

from beeai.core.exceptions import InvalidRequestError


def load_pil_image_from_bytes(content: bytes) -> Image.Image:
    try:
        image = Image.open(BytesIO(content))
        image.load()
    except UnidentifiedImageError as exc:
        raise InvalidRequestError("The uploaded file is not a valid image.") from exc
    return image.convert("RGB")