
    i;                        d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	  G d de	      Z
	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Z	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd
ZddZy)    )annotationsN)Path)hf_hub_downloadsnapshot_download)tqdmc                  .     e Zd ZdZ fdZd fdZ xZS )disabled_tqdmz
    Class to override `disable` argument in case progress bars are globally disabled.

    Taken from https://github.com/tqdm/tqdm/issues/619#issuecomment-619639324.
    c                .    d|d<   t        |   |i | y )NTdisable)super__init__)selfargskwargs	__class__s      ^/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/sentence_transformers/util/file_io.pyr   zdisabled_tqdm.__init__   s     y$)&)    c                P    	 t         |   |       y# t        $ r	 |dk7  r Y yw xY w)zBFix for https://github.com/huggingface/huggingface_hub/issues/1603_lockN)r   __delattr__AttributeError)r   attrr   s     r   r   zdisabled_tqdm.__delattr__   s3    	G% 	w 	s    %%)r   strreturnNone)__name__
__module____qualname____doc__r   r   __classcell__)r   s   @r   r	   r	   
   s    * r   r	   c           
     6    t        t        | d||||            S )a}  
    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           
         t        | ||      }|j                         rt        |      S t        ||      }	 t        | |j                  |j
                  j                         |d|||      S # t        $ r Y yw xY w)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(   r,   r-   r"   r#   r$   r%   	file_paths           r   r'   r'   >   s    2 'H=I9~ Y)I^^&&//10"-	
 		
  s   4A+ +	A76A7c           	     .   t        |t              r|j                         }t        | |      }|j                         rt	        |      S | ||dvr| dndd|||t
        d}	 t        di |}t        ||      S # t        $ r d|d<   t        di |}Y 'w xY w)	af  
    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/**Nr+   )repo_idr$   allow_patternsr.   r"   r/   r%   
tqdm_classTr%    )
isinstancer   r3   r0   r   r	   r   r4   )	r(   r-   r"   r#   r$   r%   dir_pathdownload_kwargs	repo_paths	            r   load_dir_pathrA   l   s    , )T"&&(	 &	2H8} &/8	/IYKs+t/!,#	O9%88	
 	9%%	  9.2*+%88	9s   !A8 8BBc                   	 ddl }t        j                  j	                  |      dk7  r4t        j
                  t        j                  j	                  |      d       |dz   }|j                  d| d	      5 }|j                          |j                  j                  d
      }|t        |      nd}t        d|dddt        j                  j                  |             }	 t        |d      5 }|j                  d      D ]0  }	|	s|j                  t!        |	             |j#                  |	       2 	 ddd       t        j$                  ||       	 |j-                          	 ddd       y# t        $ r t        d      w xY w# 1 sw Y   RxY w# t&        $ r6 t        j                  j)                  |      rt        j*                  |        w xY w# |j-                          w xY w# 1 sw Y   yxY w)a  Download a URL to a local file with a progress bar.

    The content is streamed in chunks and first written to a temporary
    ``"<path>_part"`` file, which is atomically moved to ``path`` once the
    download has completed successfully. Parent directories of ``path`` are
    created automatically if they do not exist.

    Args:
        url (str): The HTTP(S) URL to download.
        path (str): Destination file path on the local filesystem.

    Raises:
        ImportError: If the optional ``httpx`` dependency is not installed.
        httpx.HTTPStatusError: If the HTTP request returns a non-success status code.
        OSError: If the file cannot be written to ``path``.

    Returns:
        None
    r   NzRhttpx is required to use this function. Please install it via `pip install httpx`.r7   T)exist_ok_partGET)follow_redirectszContent-LengthBFzDownloading )unittotal
unit_scaleleavedescwbi   )
chunk_size)httpxImportErrorospathdirnamemakedirsstreamraise_for_statusheadersgetintr   basenameopen
iter_bytesupdatelenwritereplacer4   r0   removeclose)
urlrR   rO   download_filepathresponsecontent_lengthrI   progressfile_binarychunks
             r   http_getrj      s   (p 
wwt"
BGGOOD)D9w	eS4	8 H!!#!))--.>?'5'AN#tEd%UWU\U\UeUefjUkTlFm
	'. 1+%00D0A 1E E
3#))%011
 JJ($/ NN)   pnoop 1 1  	ww~~/0		+,	
 NN) sZ   E- 5A+G(!F-F-F4FG(-FF	
F?GGG%%G((G1)NNNF)r(   r   r"   bool | str | Noner#   
str | Noner$   rl   r%   r&   r   r&   )r7   NNNF)r(   r   r,   z
str | Pathr-   r   r"   rk   r#   rl   r$   rl   r%   r&   r   rl   )r(   r   r-   r   r"   rk   r#   rl   r$   rl   r%   r&   r   rl   )rc   r   rR   r   r   r   )
__future__r   rQ   pathlibr   huggingface_hubr   r   tqdm.autonotebookr   r	   r)   r'   rA   rj   r<   r   r   <module>rq      s*   " 	  > "D ,  $#"  	
  
F ##"+++ + 	+
 + + + +b  $#"/&/&/& /& 	/&
 /& /& /&d1r   