
    ChJ                       S SK Jr  S SKrS SKrS SKJr  S SKrS SKJrJ	r	  S SK
Jr   " S S\5      r    S           SS jjr     S               SS	 jjr    S             SS
 jjrSS jrg)    )annotationsN)Path)hf_hub_downloadsnapshot_download)tqdmc                  <   ^  \ rS rSrSrU 4S jrSU 4S jjrSrU =r$ )disabled_tqdm   z
Class to override `disable` argument in case progress bars are globally disabled.

Taken from https://github.com/tqdm/tqdm/issues/619#issuecomment-619639324.
c                0   > SUS'   [         TU ]  " U0 UD6  g )NTdisable)super__init__)selfargskwargs	__class__s      Z/var/www/html/shao/venv/lib/python3.13/site-packages/sentence_transformers/util/file_io.pyr   disabled_tqdm.__init__   s     y$)&)    c                T   >  [         TU ]  U5        g! [         a
    US:w  a  e  gf = f)zBFix for https://github.com/huggingface/huggingface_hub/issues/1603_lockN)r   __delattr__AttributeError)r   attrr   s     r   r   disabled_tqdm.__delattr__   s3    	G% 	w 	s    '' )r   strreturnNone)	__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes____classcell__)r   s   @r   r	   r	      s    * r   r	   c                0    [        [        U SUUUUS95      $ )aU  
Checks if the given model name or path corresponds to a SentenceTransformer model.

Args:
    model_name_or_path (str): The name or path of the model.
    token (Optional[Union[bool, str]]): The token to be used for authentication. Defaults to None.
    cache_folder (Optional[str]): The folder to cache the model files. Defaults to None.
    revision (Optional[str]): The revision of the model. Defaults to None.
    local_files_only (bool): Whether to only use local files for the model. Defaults to False.

Returns:
    bool: True if the model is a SentenceTransformer model, False otherwise.
zmodules.json)tokencache_folderrevisionlocal_files_only)boolload_file_path)model_name_or_pathr(   r)   r*   r+   s        r   is_sentence_transformer_modelr/       s+    ( %-	
	 	r   c                    [        XU5      nUR                  5       (       a  [        U5      $ [        X!5      n [        U UR                  UR
                  R                  5       USUUUS9$ ! [         a     gf = f)a  
Loads a file from a local or remote location.

Args:
    model_name_or_path (str): The model name or path.
    filename (str): The name of the file to load.
    subfolder (str): The subfolder within the model subfolder (if applicable).
    token (Optional[Union[bool, str]]): The token to access the remote file (if applicable).
    cache_folder (Optional[str]): The folder to cache the downloaded file (if applicable).
    revision (Optional[str], optional): The revision of the file (if applicable). Defaults to None.
    local_files_only (bool, optional): Whether to only consider local files. Defaults to False.

Returns:
    Optional[str]: The path to the loaded file, or None if the file could not be found or loaded.
sentence-transformers)filename	subfolderr*   library_namer(   	cache_dirr+   N)r   existsr   r   nameparentas_posix	Exception)r.   r2   r3   r(   r)   r*   r+   	file_paths           r   r-   r-   @   s    2 'H=I9~ Y)I^^&&//10"-	
 		
  s   1A+ +
A87A8c           	     D   [        U[        5      (       a  UR                  5       n[        X5      nUR                  5       (       a  [	        U5      $ U UUS;  a  U S3OSSUUU[
        S.n [        S0 UD6n[        X5      $ ! [         a    SUS'   [        S0 UD6n N'f = f)	a:  
Loads the subfolder path for a given model name or path.

Args:
    model_name_or_path (str): The name or path of the model.
    subfolder (str): The subfolder to load.
    token (Optional[Union[bool, str]]): The token for authentication.
    cache_folder (Optional[str]): The folder to cache the downloaded files.
    revision (Optional[str], optional): The revision of the model. Defaults to None.
    local_files_only (bool, optional): Whether to only use local files. Defaults to False.

Returns:
    Optional[str]: The subfolder path if it exists, otherwise None.
) .z/**Nr1   )repo_idr*   allow_patternsr4   r(   r5   r+   
tqdm_classTr+   r   )
isinstancer   r9   r6   r   r	   r   r:   )	r.   r3   r(   r)   r*   r+   dir_pathdownload_kwargs	repo_paths	            r   load_dir_pathrF   n   s    , )T""&&(	 &2H8} &/8	/IYKs+t/!,#	O9%88	
 	%%	  9.2*+%88	9s   ,B BBc                   [         R                  R                  U5      S:w  a2  [         R                  " [         R                  R                  U5      SS9  [        R
                  " U SS9nUR                  S:w  a9  [        SU  SUR                   3[        R                  S9  UR                  5         g	US
-   n[        US5       nUR                  R                  S5      nUb  [        U5      OS	n[        SUSS9nUR                  SS9 H7  nU(       d  M  UR!                  [#        U5      5        UR%                  U5        M9     S	S	S	5        [         R&                  " X15        WR)                  5         g	! , (       d  f       N5= f)z
Downloads a URL to a given path on disk.

Args:
    url (str): The URL to download.
    path (str): The path to save the downloaded file.

Raises:
    requests.HTTPError: If the HTTP request returns a non-200 status code.

Returns:
    None
r=   T)exist_ok)stream   z"Exception when trying to download z. Response )fileN_partwbzContent-LengthB)unittotal
unit_scalei   )
chunk_size)ospathdirnamemakedirsrequestsgetstatus_codeprintsysstderrraise_for_statusopenheadersintr   iter_contentupdatelenwriterenameclose)	urlrT   reqdownload_filepathfile_binarycontent_lengthrP   progresschunks	            r   http_getrn      s.    
wwt"
BGGOOD)D9
,,s4
(C
#23%{3??BST[^[e[efw		&+)9:'5'AN#tS$?%%%6EuE
+!!%( 7	 
' II&NN 
'	&s   AE5/E55
F)NNNF)r.   r   r(   bool | str | Noner)   
str | Noner*   rp   r+   r,   r   r,   )r=   NNNF)r.   r   r2   z
str | Pathr3   r   r(   ro   r)   rp   r*   rp   r+   r,   r   rp   )r.   r   r3   r   r(   ro   r)   rp   r*   rp   r+   r,   r   rp   )rg   r   rT   r   r   r   )
__future__r   rS   r[   pathlibr   rW   huggingface_hubr   r   tqdm.autonotebookr   r	   r/   r-   rF   rn   r   r   r   <module>ru      s0   " 	 
   > "D ,  $#"  	
  
F ##"+++ + 	+
 + + + +b  $#"/&/&/& /& 	/&
 /& /& /&d"r   