from langchain.documentloaders import DirectoryLoader from…
- User
from langchain.document_loaders import DirectoryLoader from langchain_community.document_loaders import UnstructuredFileLoader
dir_loader = DirectoryLoader('/home/ritik1s/Downloads/conv_ai/multi_doc', loader_cls=UnstructuredImageLoader)
data = dir_loader.load()
- Assistant
It seems like you have a mistake in your code snippet. You reference
UnstructuredImageLoader, but based on the rest of your code and the imports (DirectoryLoaderfromlangchain.document_loadersandUnstructuredFileLoaderfromlangchain_community.document_loaders), it looks like you're working with document loaders rather than image loaders.Given what you've imported, if you're intending to load unstructured text files from a directory, you should be using
UnstructuredFileLoaderinstead ofUnstructuredImageLoader. Here's how you can correct your code:pythonfrom langchain.document_loaders import DirectoryLoader from langchain_community.document_loaders import UnstructuredFileLoader # Ensure you are using the correct class for loading unstructured files dir_loader = DirectoryLoader('/home/ritik1s/Downloads/conv_ai/multi_doc', loader_cls=UnstructuredFileLoader) data = dir_loader.load() - User
from langchain.document_loaders import DirectoryLoader from langchain.document_loaders.image import UnstructuredImageLoader
dir_loader = DirectoryLoader('/home/ritik1s/Downloads/conv_ai/multi_doc', loader_cls=UnstructuredImageLoader)
data = dir_loader.load()
- Assistant
Given the corrected import for
UnstructuredImageLoaderfrom thelangchain.document_loaders.imagemodule, your code snippet seems to be intended for loading images from a directory in an unstructured manner using LangChain's document loading framework. This setup is appropriate if you're working with a collection of image files and you want to apply some processing or analysis to them. - User
I am getting this error in the above code --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) /tmp/ipykernel_41768/2896354985.py in 4 dir_loader = DirectoryLoader('/home/ritik1s/Downloads/conv_ai/multi_doc', loader_cls=UnstructuredFileLoader) 5 ----> 6 data = dir_loader.load()
~/.local/lib/python3.10/site-packages/langchain_community/document_loaders/directory.py in load(self) 155 else: 156 for i in items: --> 157 self.load_file(i, p, docs, pbar) 158 159 if pbar:
~/.local/lib/python3.10/site-packages/langchain_community/document_loaders/directory.py in load_file(self, item, path, docs, pbar) 104 logger.warning(f"Error loading file {str(item)}: {e}") 105 else: --> 106 raise e 107 finally: 108 if pbar:
~/.local/lib/python3.10/site-packages/langchain_community/document_loaders/directory.py in load_file(self, item, path, docs, pbar) 98 try: 99 logger.debug(f"Processing file: {str(item)}") --> 100 sub_docs = self.loader_cls(str(item), **self.loader_kwargs).load() ... ---> 11 from cv2.typing import MatLike 12 from huggingface_hub import hf_hub_download 13 from PIL.Image import Image
- Assistant
The error message you're encountering,
ModuleNotFoundError: No module named 'cv2.typing', suggests that the Python environment you're running your code in either does not haveOpenCV(referred to ascv2in Python) installed or you have an outdated version ofOpenCVthat does not include thecv2.typingmodule.The
cv2.typingmodule was introduced in newer versions of OpenCV to assist with type hints and static analysis, which means you'll need to ensure you have a recent version of OpenCV installed in your environment.