mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-21 03:51:42 +00:00
community: fix import exception too constrictive (#30218)
Fix this issue #30097
This commit is contained in:
parent
7ff7c4f81b
commit
f6a17fbc56
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user