community: fix import exception too constrictive (#30218)

Fix this issue #30097
This commit is contained in:
amuwall 2025-03-18 10:09:02 +08:00 committed by GitHub
parent 7ff7c4f81b
commit f6a17fbc56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,24 +45,24 @@ class BaseImageBlobParser(BaseBlobParser):
""" """
try: try:
from PIL import Image as Img from PIL import Image as Img
with blob.as_bytes_io() as buf:
if blob.mimetype == "application/x-npy":
img = Img.fromarray(numpy.load(buf))
else:
img = Img.open(buf)
content = self._analyze_image(img)
logger.debug("Image text: %s", content.replace("\n", "\\n"))
yield Document(
page_content=content,
metadata={**blob.metadata, **{"source": blob.source}},
)
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"`Pillow` package not found, please install it with " "`Pillow` package not found, please install it with "
"`pip install Pillow`" "`pip install Pillow`"
) )
with blob.as_bytes_io() as buf:
if blob.mimetype == "application/x-npy":
img = Img.fromarray(numpy.load(buf))
else:
img = Img.open(buf)
content = self._analyze_image(img)
logger.debug("Image text: %s", content.replace("\n", "\\n"))
yield Document(
page_content=content,
metadata={**blob.metadata, **{"source": blob.source}},
)
class RapidOCRBlobParser(BaseImageBlobParser): class RapidOCRBlobParser(BaseImageBlobParser):
"""Parser for extracting text from images using the RapidOCR library. """Parser for extracting text from images using the RapidOCR library.