a
    bg
                     @   sL   d dl Z d dlmZ d dlmZmZmZ d dlmZm	Z	 G dd deZ
dS )    N)Path)AnyListUnion)UnstructuredFileLoadervalidate_unstructured_versionc                       sB   e Zd ZdZd	eeef eed fddZe	dddZ
  ZS )
UnstructuredPowerPointLoaderab  Load `Microsoft PowerPoint` files using `Unstructured`.

    Works with both .ppt and .pptx files.
    You can run the loader in one of two modes: "single" and "elements".
    If you use "single" mode, the document will be returned as a single
    langchain Document object. If you use "elements" mode, the unstructured
    library will split the document into elements such as Title and NarrativeText.
    You can pass in additional unstructured kwargs after mode to apply
    different unstructured settings.

    Examples
    --------
    from langchain_community.document_loaders import UnstructuredPowerPointLoader

    loader = UnstructuredPowerPointLoader(
        "example.pptx", mode="elements", strategy="fast",
    )
    docs = loader.load()

    References
    ----------
    https://unstructured-io.github.io/unstructured/bricks.html#partition-pptx
    single)	file_pathmodeunstructured_kwargsc                    s$   t |}t jf ||d| dS )a,  

        Args:
            file_path: The path to the PowerPoint file to load.
            mode: The mode to use when loading the file. Can be one of "single",
                "multi", or "all". Default is "single".
            **unstructured_kwargs: Any kwargs to pass to the unstructured.
        )r
   r   N)strsuper__init__)selfr
   r   r   	__class__ }/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/document_loaders/powerpoint.pyr   $   s    z%UnstructuredPowerPointLoader.__init__)returnc           	      C   s   ddl m}m} zdd l}|| j|jk}W n0 ty\   tj	t
| j\}}|dk}Y n0 |rjtd |rddlm} |f d| ji| jS ddlm} |f d| ji| jS d S )Nr   )FileTypedetect_filetypez.pptz0.4.11)partition_pptfilename)partition_pptx)Z unstructured.file_utils.filetyper   r   magicr
   ZPPTImportErrorospathsplitextr   r   Zunstructured.partition.pptr   r   Zunstructured.partition.pptxr   )	r   r   r   r   Zis_ppt_	extensionr   r   r   r   r   _get_elements5   s    z*UnstructuredPowerPointLoader._get_elements)r	   )__name__
__module____qualname____doc__r   r   r   r   r   r   r"   __classcell__r   r   r   r   r      s    
r   )r   pathlibr   typingr   r   r   Z1langchain_community.document_loaders.unstructuredr   r   r   r   r   r   r   <module>   s   