Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
image.py52 linesDownload Raw Back to document_loaders
1from pathlib import Path2from typing import Any, List, Union3 4from langchain_community.document_loaders.unstructured import UnstructuredFileLoader5 6 7class UnstructuredImageLoader(UnstructuredFileLoader):8    """Load `PNG` and `JPG` files using `Unstructured`.9 10    You can run the loader in one of two modes: "single" and "elements".11    If you use "single" mode, the document will be returned as a single12    langchain Document object. If you use "elements" mode, the unstructured13    library will split the document into elements such as Title and NarrativeText.14    You can pass in additional unstructured kwargs after mode to apply15    different unstructured settings.16 17    Examples18    --------19    from langchain_community.document_loaders import UnstructuredImageLoader20 21    loader = UnstructuredImageLoader(22        "example.png", mode="elements", strategy="fast",23    )24    docs = loader.load()25 26    References27    ----------28    https://unstructured-io.github.io/unstructured/bricks.html#partition-image29    """30 31    def __init__(32        self,33        file_path: Union[str, Path],34        mode: str = "single",35        **unstructured_kwargs: Any,36    ):37        """38 39        Args:40            file_path: The path to the Image file to load.41            mode: The mode to use when loading the file. Can be one of "single",42                "multi", or "all". Default is "single".43            **unstructured_kwargs: Any kwargs to pass to the unstructured.44        """45        file_path = str(file_path)46        super().__init__(file_path=file_path, mode=mode, **unstructured_kwargs)47 48    def _get_elements(self) -> List:49        from unstructured.partition.image import partition_image50 51        return partition_image(filename=self.file_path, **self.unstructured_kwargs)52 
codekingpro/portable-devtools · Team Ai