
    h                         d dl Z d dlZd dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ  edd	d
       G d de             Zy)    N)CallableListOptional)
deprecated)Document)
BaseLoaderUnstructuredFileLoader)get_client_infoz0.0.32z1.0z(langchain_google_community.GCSFileLoader)sinceremovalalternative_importc                   P    e Zd ZdZ	 d
dedededeeegef      fdZde	e
   fd	Zy)GCSFileLoaderzLoad from GCS file.Nproject_namebucketblobloader_funcc                 p    || _         || _        || _        dt        dt        fd}|r|| _        y|| _        y)a9  Initialize with bucket and key name.

        Args:
            project_name: The name of the project to load
            bucket: The name of the GCS bucket.
            blob: The name of the GCS blob to load.
            loader_func: A loader function that instantiates a loader based on a
                file_path argument. If nothing is provided, the
                UnstructuredFileLoader is used.

        Examples:
            To use an alternative PDF loader:
            >> from from langchain_community.document_loaders import PyPDFLoader
            >> loader = GCSFileLoader(..., loader_func=PyPDFLoader)

            To use UnstructuredFileLoader with additional arguments:
            >> loader = GCSFileLoader(...,
            >>      loader_func=lambda x: UnstructuredFileLoader(x, mode="elements"))

        	file_pathreturnc                     t        |       S Nr	   )r   s    k/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/langchain_community/document_loaders/gcs_file.pydefault_loader_funcz3GCSFileLoader.__init__.<locals>.default_loader_func4   s    ))44    N)r   r   r   strr   _loader_func)selfr   r   r   r   r   s         r   __init__zGCSFileLoader.__init__   sA    6 	(	53 	5: 	5 ,7K<Or   r   c                 @   	 ddl m} |j                  | j                  t        d            }|j                  | j                        }|j                  | j                        }|j                  | j                        j                  }t        j                         5 }| d| j                   }t        j                  t        j                  j!                  |      d       |j#                  |       | j%                  |      }|j'                         }	|	D ]W  }
d	|
j                  v r)d
| j                   d| j                   |
j                  d	<   |s=|
j                  j)                  |       Y |	cddd       S # t        $ r t        d      w xY w# 1 sw Y   yxY w)zLoad documents.r   )storagezpCould not import google-cloud-storage python package. Please install it with `pip install google-cloud-storage`.zgoogle-cloud-storage)client_info/T)exist_oksourcezgs://N)google.cloudr"   ImportErrorClientr   r   
get_bucketr   r   get_blobmetadatatempfileTemporaryDirectoryosmakedirspathdirnamedownload_to_filenamer   loadupdate)r   r"   storage_clientr   r   r,   temp_dirr   loaderdocsdocs              r   r4   zGCSFileLoader.load9   sl   	, !?;Q+R ( 
  **4;;7{{499%??499-66((* 	h#*Adii[1IKK	2TB%%i0&&y1F;;=D 2s||+/4T[[M499+-NCLL*LL''1	2
 	 	!  	M 	 	 	s   E< B6FF<FFr   )__name__
__module____qualname____doc__r   r   r   r   r    r   r   r4    r   r   r   r      s_      >B"P"P "P 	"P
 huj'89:"PH d8n  r   r   )r/   r-   typingr   r   r   langchain_core._api.deprecationr   langchain_core.documentsr   )langchain_community.document_loaders.baser   1langchain_community.document_loaders.unstructuredr
   &langchain_community.utilities.vertexair   r   r?   r   r   <module>rF      sL    	  + + 6 - @ T B 
A
GJ G
Gr   