Skip to content

The agent engineering platform.

community: fix import exception too constrictive (#30218)

amuwallf6a17fbc564e
diff --git a/libs/community/langchain_community/document_loaders/parsers/images.py b/libs/community/langchain_community/document_loaders/parsers/images.py
index b053b94d49..eb3da4d2a1 100644
--- a/libs/community/langchain_community/document_loaders/parsers/images.py
+++ b/libs/community/langchain_community/document_loaders/parsers/images.py
@@ -45,24 +45,24 @@ class BaseImageBlobParser(BaseBlobParser):
"""
try:
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:
raise ImportError(
"`Pillow` package not found, please install it with "
"`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):
"""Parser for extracting text from images using the RapidOCR library.