o
    ®©ZhÔ
  ã                   @   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                       sH   e Zd ZdZ	ddeeef dedef‡ fdd„Zde	f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d||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__r   úf/var/www/html/lang_env/lib/python3.10/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 n ty.   tj 	t
| jƒ¡\}}|dk}Y nw |r5tdƒ |rHddlm} |dd| ji| j¤ŽS ddlm} |dd| ji| j¤ŽS )	Nr   )ÚFileTypeÚdetect_filetypez.pptz0.4.11)Úpartition_pptÚfilename)Úpartition_pptxr   )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
    