§
    ™Štjû'  ã                  óÚ   — d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
mZmZ d dlmZ  ej        e¦  «        Z G d„ de¦  «        Z	 	 	 	 dd d„Z	 	 	 	 	 d!d"d„Z	 	 	 	 dd#d„Zd$d„ZdS )%é    )ÚannotationsN)ÚPath)Úhf_hub_downloadÚsnapshot_download)ÚEntryNotFoundErrorÚHFValidationErrorÚLocalEntryNotFoundError)Ú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|d<    t          ¦   «         j        |i |¤Ž d S )NTÚdisable)ÚsuperÚ__init__)ÚselfÚargsÚkwargsÚ	__class__s      €ú`/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sentence_transformers/util/file_io.pyr   zdisabled_tqdm.__init__   s/   ø€ Ø ˆˆyÑØ�‰ŒÔ˜$Ð) &Ð)Ð)Ð)Ð)Ð)ó    ÚattrÚstrÚreturnÚNonec                ó|   •— 	 t          ¦   «                              |¦  «         dS # t          $ r |dk    r‚ Y dS w xY w)zBFix for https://github.com/huggingface/huggingface_hub/issues/1603Ú_lockN)r   Ú__delattr__ÚAttributeError)r   r   r   s     €r   r   zdisabled_tqdm.__delattr__   sV   ø€ ð	Ý‰GŒG×Ò Ñ%Ô%Ð%Ð%Ð%øÝð 	ð 	ð 	Ø�wŠˆØð ˆˆð	øøøs   ƒ!& ¦;º;)r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__classcell__)r   s   @r   r   r      s`   ø€ € € € € ðð ð*ð *ð *ð *ð *ðð ð ð ð ð ð ð ð ð r   r   FÚmodel_name_or_pathr   Útokenúbool | str | NoneÚcache_folderú
str | NoneÚrevisionÚlocal_files_onlyÚboolr   c           
     óF   — 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.

    Raises:
        Exception: Propagates errors from the Hub that are not "file not found" (e.g.
            authentication, rate-limit, or network errors). The probe deliberately surfaces
            these instead of returning ``False``, so callers don't mistake a flaky Hub for
            "this isn't a SentenceTransformer".

    Returns:
        bool: True if the model is a SentenceTransformer model, False if it exists but
        does not contain a ``modules.json``.
    zmodules.json)r%   r'   r)   r*   )r+   Úload_file_path)r$   r%   r'   r)   r*   s        r   Úis_sentence_transformer_modelr.   "   s:   € õ6 ÝØØØØ%ØØ-ð	
ñ 	
ô 	
ñ	ô 	ð 	r   Ú Úfilenameú
str | PathÚ	subfolderc           
     óÈ  — t          | ||¦  «        }|                     ¦   «         rt          |¦  «        S t          | ¦  «                             ¦   «         rdS t          ||¦  «        }	 t	          | |j        |j                             ¦   «         |d|||¬¦  «        S # t          t          t          f$ r.}t                               d|›d| ›d|› �¦  «         Y d}~dS d}~w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.

    Raises:
        Exception: Errors that are not unambiguously "this file is not on the Hub"
            propagate to the caller (e.g. authentication, rate-limit, network). Only
            ``EntryNotFoundError``, ``HFValidationError``, and ``LocalEntryNotFoundError``
            are converted to a ``None`` return.

    Returns:
        Optional[str]: The path to the loaded file, or ``None`` if the file is not present
        locally and the Hub confirms it is not in the repo (or no valid repo id was given).
    Núsentence-transformers)r0   r2   r)   Úlibrary_namer%   Ú	cache_dirr*   zCould not load ú from ú: )r   Úexistsr   Úis_dirr   ÚnameÚparentÚas_posixr   r   r	   ÚloggerÚdebug)	r$   r0   r2   r%   r'   r)   r*   Ú	file_pathÚexcs	            r   r-   r-   I   s  € õ@ Ð'¨°HÑ=Ô=€IØ×ÒÑÔð Ý�9‰~Œ~Ðõ ÐÑÔ×&Ò&Ñ(Ô(ð Øˆtõ �Y Ñ)Ô)€IðÝØØ”^ØÔ&×/Ò/Ñ1Ô1ØØ0ØØ"Ø-ð	
ñ 	
ô 	
ð 		
øõ Õ 1Õ3JÐKð ð ð õ 	�ŠÐV xÐVÐVÐ9KÐVÐVÐQTÐVÐVÑWÔWÐWØˆtˆtˆtˆtˆtøøøøð	øøøs   Á)2B ÂC!Â3#CÃC!c           	     óx  — t          |t          ¦  «        r|                     ¦   «         }t          | |¦  «        }|                     ¦   «         rt	          |¦  «        S t          | ¦  «                             ¦   «         rdS | ||dvr|› d�ndd|||t          dœ}	 t          di |¤Ž}nx# t          t          f$ r.}	t                               d|›d| ›d|	› �¦  «         Y d}	~	dS d}	~	wt          $ r.}
d	|d
<   	 t          di |¤Ž}n# t          $ r |
d‚w xY wY d}
~
nd}
~
ww xY wt	          t          ||¦  «        ¦  «        S )ar  
    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.

    Raises:
        Exception: Errors that are not unambiguously "this is not on the Hub" propagate
            to the caller. ``HFValidationError`` and ``LocalEntryNotFoundError`` are
            converted to a ``None`` return. Other failures (auth, rate-limit, network)
            trigger a single cache-only retry; if the cache also lacks the file, the
            original exception is re-raised (a cache miss would mask the real cause).

    Returns:
        Optional[str]: The subfolder path, or ``None`` if the parent is a local directory
        without the subfolder, or no valid repo id was given.
    N)r/   ú.z/**r4   )Úrepo_idr)   Úallow_patternsr5   r%   r6   r*   Ú
tqdm_classzCould not load subfolder r7   r8   Tr*   © )Ú
isinstancer   r=   r9   r   r:   r   r   r   r	   r>   r?   Ú	Exception)r$   r2   r%   r'   r)   r*   Údir_pathÚdownload_kwargsÚ	repo_pathrA   Úfirst_errors              r   Úload_dir_pathrN   …   s¹  € õ< �)�TÑ"Ô"ð )Ø×&Ò&Ñ(Ô(ˆ	õ Ð&¨	Ñ2Ô2€HØ‡‚ÑÔð Ý�8‰}Œ}Ðõ ÐÑÔ×&Ò&Ñ(Ô(ð Øˆtð &ØØ/8À	Ð/IÐ/I˜YÐ+Ð+Ð+Ð+ÈtØ/ØØ!Ø,Ý#ð	ð 	€Oð(Ý%Ð8Ð8¨Ð8Ð8ˆ	ˆ	øÝÕ6Ð7ð ð ð å�ŠÐa°ÐaÐaÐDVÐaÐaÐ\_ÐaÐaÑbÔbÐbØˆtˆtˆtˆtˆtøøøøÝð 	(ð 	(ð 	(à.2ˆÐ*Ñ+ð	(Ý)Ð<Ð<¨OÐ<Ð<ˆIˆIøÝ&ð 	(ð 	(ð 	(ð  4Ð'ð		(øøøð ˆIˆIˆIˆIøøøøð		(øøøõ �t�I˜yÑ)Ô)Ñ*Ô*Ð*s<   ÂB' Â'DÂ8#C!Ã!DÃ.DÃ4DÄ DÄDÄDÄDÚurlÚpathr   c                óV  — 	 ddl }n# t          $ r t          d¦  «        ‚w xY wt          j                             |¦  «        dk    r3t          j        t          j                             |¦  «        d¬¦  «         |dz   }|                     d| d¬	¦  «        5 }|                     ¦   «          |j         	                    d
¦  «        }|�t          |¦  «        nd}t          d|dddt          j                             |¦  «        › �¬¦  «        }	 t          |d¦  «        5 }|                     d¬¦  «        D ];}	|	r7|                     t!          |	¦  «        ¦  «         |                     |	¦  «         Œ<	 ddd¦  «         n# 1 swxY w Y   t          j        ||¦  «         nB# t&          $ r5 t          j                             |¦  «        rt          j        |¦  «         ‚ w xY w	 |                     ¦   «          n# |                     ¦   «          w xY w	 ddd¦  «         dS # 1 swxY w Y   dS )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`.r/   T)Úexist_okÚ_partÚGET)Úfollow_redirectszContent-LengthÚBFzDownloading )ÚunitÚtotalÚ
unit_scaleÚleaveÚdescÚwbi   )Ú
chunk_size)ÚhttpxÚImportErrorÚosrP   ÚdirnameÚmakedirsÚstreamÚraise_for_statusÚheadersÚgetÚintr
   ÚbasenameÚopenÚ
iter_bytesÚupdateÚlenÚwriteÚreplacerI   r9   ÚremoveÚclose)
rO   rP   r^   Údownload_filepathÚresponseÚcontent_lengthrX   ÚprogressÚfile_binaryÚchunks
             r   Úhttp_getrw   Í   sÐ  € ð(pØˆˆˆˆøÝð pð pð pÝÐnÑoÔoÐoðpøøøõ 
„w‡‚�tÑÔ Ò"Ð"Ý
Œ•B”G—O’O DÑ)Ô)°DÐ9Ñ9Ô9Ð9à˜w™ÐØ	�Š�e˜S°4ˆÑ	8Ô	8ð ¸HØ×!Ò!Ñ#Ô#Ð#Ø!Ô)×-Ò-Ð.>Ñ?Ô?ˆØ'5Ð'A•�NÑ#Ô#Ð#ÀtˆÝØ˜E¨d¸%ÐFmÕUWÔU\×UeÒUeÐfjÑUkÔUkÐFmÐFmð
ñ 
ô 
ˆð	ÝÐ'¨Ñ.Ô.ð 1°+Ø%×0Ò0¸DÐ0ÑAÔAð 1ð 1�EØð 1Ø Ÿš­¨E©
¬
Ñ3Ô3Ð3Ø#×)Ò)¨%Ñ0Ô0Ð0øð1ð1ð 1ð 1ñ 1ô 1ð 1ð 1ð 1ð 1ð 1ð 1øøøð 1ð 1ð 1ð 1õ
 ŒJÐ(¨$Ñ/Ô/Ð/Ð/øÝð 	ð 	ð 	ÝŒw�~Š~Ð/Ñ0Ô0ð -Ý”	Ð+Ñ,Ô,Ð,Øð	øøøð 0ð �NŠNÑÔÐÐøˆH�NŠNÑÔÐÐøøøÐð)ð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð sj   ‚ ‡!ÂA6HÄFÄAE>Å2FÅ>F	ÆFÆF	ÆFÆG7Æ?GÇG7Ç"HÇ7HÈHÈH"È%H")NNNF)r$   r   r%   r&   r'   r(   r)   r(   r*   r+   r   r+   )r/   NNNF)r$   r   r0   r1   r2   r   r%   r&   r'   r(   r)   r(   r*   r+   r   r(   )r$   r   r2   r   r%   r&   r'   r(   r)   r(   r*   r+   r   r(   )rO   r   rP   r   r   r   )Ú
__future__r   Úloggingr`   Úpathlibr   Úhuggingface_hubr   r   Úhuggingface_hub.utilsr   r   r	   Útqdm.autonotebookr
   Ú	getLoggerr   r>   r   r.   r-   rN   rw   rG   r   r   ú<module>r      s]  ðØ "Ð "Ð "Ð "Ð "Ð "à €€€Ø 	€	€	€	Ø Ð Ð Ð Ð Ð à >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ø `Ð `Ð `Ð `Ð `Ð `Ð `Ð `Ð `Ð `Ø "Ð "Ð "Ð "Ð "Ð "à	ˆÔ	˜8Ñ	$Ô	$€ðð ð ð ð �Dñ ô ð ð,  $Ø#ØØ"ð$ð $ð $ð $ð $ðT Ø#Ø#ØØ"ð9ð 9ð 9ð 9ð 9ð~  $Ø#ØØ"ðE+ð E+ð E+ð E+ð E+ðP1ð 1ð 1ð 1ð 1ð 1r   