o �J�h���@s�UddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZmZmZddlmZddlmZmZddlmZddlmZmZddlZddlmZGd d �d �Zzdd l m Z Wn e!y�eZ Ynwgd �Z"e�#d �Z$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,da-ee.e/d<ej0dd��Z1dd�Z2dd�Z3dd�Z4dd �Z5d!d"�Z6d#d$�Z7d%d&�Z8d'd(�Z9 ) *dXd+d,�Z: -dYd.d/�Z;d0d1�Z<d2d3�Z=d4d5�Z>d6d7�Z?d8d9�Z@ * *  )dZd:d;�ZAd[d<d=�ZBd>dd*d)d*d?�d@d-�ZCdAdB�ZD  )d\dCe.dDe.dEee.dFeEdGdf dHdI�ZFdJe.dGeEfdKdL�ZGedMeHdN�dJe.dOe.dPedQeEdGee.eff dRdS��ZI   ) *  *d]dCe.dOee.dPedFeEdTeEdUee.dQeEdGee.effdVdW�ZJdS)^�N)�Path)�Any�Dict�Optional)� deprecated)� HTTPError�URLError)�urlparse)�Request�urlopen)� MAP_LOCATIONc@sFeZdZddd�Zdd�Zdd�Zd d �Zd d �Zd d�Zdd�Z dS)� _FaketqdmNFcOs||_||_d|_dS�Nr)�total�disable�n)�selfrr�unit�args�kwargs�r�GC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\torch\hub.py�__init__s z_Faketqdm.__init__cCsp|jrdS|j|7_|jdurtj�d|jd�d��ntj�dd|jt|j�d�d��tj��dS)N� z.1fz bytes�d�%)rrr�sys�stderr�write�float�flush)rrrrr�update s &z_Faketqdm.updatecOsdS�Nr)rrrrrr�set_description,�z_Faketqdm.set_descriptioncCstj�|�d��dS�N� )rrr)r�srrrr/sz_Faketqdm.writecCs d|_dS�NT)r�rrrr�close2s z_Faketqdm.closecCs|Sr"rr)rrr� __enter__5r$z_Faketqdm.__enter__cCs|jrdStj�d�dSr%)rrrr)r�exc_type�exc_val�exc_tbrrr�__exit__8sz_Faketqdm.__exit__)NFN) �__name__� __module__� __qualname__rr!r#rr*r+r/rrrrr s   r )�tqdm)�download_url_to_file�get_dir�help�list�load�load_state_dict_from_url�set_dirz-([a-f0-9]*)\.)ZfacebookresearchZfacebookincubator�pytorchZ fairinternalZ GITHUB_TOKENZ TORCH_HOMEZXDG_CACHE_HOMEz~/.cache� dependenciesz hubconf.pyi�_hub_dirc cs8�tj�d|�z dVWtj�|�dStj�|�wr)r�path�insert�remove�r>rrr�_add_to_sys_pathas �rBcCsZddl}ddlm}|j�||�}|dusJ�|j�|�}t|j|�s%J�|j�|�|S)Nr)�Loader) �importlib.util� importlib.abcrC�util�spec_from_file_location�module_from_spec� isinstance�loader� exec_module)�namer>� importlibrC�spec�modulerrr�_import_moduleks    rPcCs8tj�|�rtj�|�rt�|�dSt�|�dSdSr")�osr>�exists�isfiler@�shutil�rmtreerArrr�_remove_if_existsws  �rVcCsd|�d|�d|��S)N�https://github.com/�/z /zipball/r)� repo_owner� repo_name�refrrr�_git_archive_linksr\cCs|t|�vrdSt||�Sr")�dir�getattr)rO� func_namerrr�_load_attr_from_module�s  r`c Cs*tj�t�ttj�t�tt�d���}|S)N�torch)rQr>� expanduser�getenv�ENV_TORCH_HOME�join�ENV_XDG_CACHE_HOME�DEFAULT_CACHE_DIR)Z torch_homerrr�_get_torch_home�s��rhc Cs,d|vr |�d�\}}n|d}}|�d�\}}|dur�ztd|�d|�d��� d}Wd�n1s5wYWnUtyV}z|jdkrKd}n�WYd}~n?d}~wty�}z/dD]}tj�t��d|�d |�d |���rw|}nq_|dur�t d t��d ��|�WYd}~nd}~ww|||fS) N�:rXrWz /tree/main/�maini��master)rjrk�_z\It looks like there is no internet connection and the repo could not be found in the cache (�)) �splitr r�coderrQr>rRr5� RuntimeError)�github� repo_infor[rYrZ�eZ possible_refrrr�_parse_repo_info�sH ��  ������� ��� rtcCsBt|��}|���|j�d��Wd�S1swYdS)Nzutf-8)r �read�decode�headers�get_content_charset)�url�rrrr� _read_url�s $�r{c Cs�ddi}tj�t�}|durd|��|d<d|�d|�d�d|�d|�d�fD]7}d } |d 7}|�d |��}t�tt||d ���}|sEn|D]} | d|ksX| dd�|�r\dSqGq,q't d|�d|�d|�d���)N�Acceptzapplication/vnd.github.v3+jsonztoken � Authorizationzhttps://api.github.com/repos/rXz /branchesz/tagsrT�z?per_page=100&page=�rwrL�commit�shaz Cannot find z in https://github.com/zX. If it's a commit from a forked repo, please call hub.load() with forked repo directly.) rQ�environ�get�ENV_GITHUB_TOKEN�json�loadsr{r � startswith� ValueError) rYrZr[rw�token� url_prefix�pagery�response�brrrr�_validate_not_a_forked_repo�s. ����r�TFc Cs�t�}tj|dd�t|�\}}} | �dd�} d�||| g�} tj�|| �} t||| ||d�| o7tj�| �} | rH|rFt j � d| �d��| S|sPt ||| �tj�|| d�}t |�zt||| �}t j � d |�d |�d��t||d d �Wn5ty�}z)|jd kr�t�d| �d��d| ��}t|||d�}t||d d �n�WYd}~nd}~wwt�|��}|��dj}tj�||�}t |�|�|�Wd�n1s�wYt |�t | �t�|| �| S)NT��exist_okrXrl)� trust_repo� calling_fnzUsing cache found in r&z.zip�Downloading: "�" to F��progressi,zThe ref a is ambiguous. Perhaps it is both a tag and a branch in the repo? Torchhub will now assume that it's a branch. You can disambiguate tags and branches by explicitly passing refs/heads/branch_name or refs/tags/tag_name as the ref. That might require using skip_validation=True.z refs/heads/)r[r)r5rQ�makedirsrt�replacerer>�_check_repo_is_trustedrRrrrr�rVr\r4rro�warnings�warn�zipfile�ZipFile�infolist�filename� extractallrT�move)rq� force_reloadr�r��verbose�skip_validation�hub_dirrYrZr[Z normalized_br�owner_name_branch�repo_dir� use_cache� cached_filery�errZdisambiguated_branch_refZcached_zipfileZextraced_repo_nameZextracted_reporrr�_get_cache_or_reload�sd  �,�    � � ���  � r�r8c Csnt�}tj�|d�}tj�|�st|���t|��}tdd�|D��}Wd�n1s.wYt t� |��d} d�||g�} | |vpN|| vpN|t v} |durc| sat � d|�d|�d��dS|d usm|d kr�| s�td | �d ��} | ��d vr�| r�td�n| ��dvr�td��td| �d���| s�t|d��}|�| d�Wd�dS1s�wYdSdS)NZ trusted_listcss�|]}|��VqdSr")�strip)�.0�linerrr� <genexpr>:s�z)_check_repo_is_trusted.<locals>.<genexpr>r~rla)You are about to download and run code from an untrusted repository. In a future release, this won't be allowed. To add the repository to your trusted list, change the command to {calling_fn}(..., trust_repo=False) and a command prompt will appear asking for an explicit confirmation of trust, or zi(..., trust_repo=True), which will assume that the prompt is to be answered with 'yes'. You can also use z�(..., trust_repo='check') which will only prompt for confirmation if the repo is not already trusted. This will eventually be the default behaviourF�checkzThe repository z� does not belong to the list of trusted repositories and as such cannot be downloaded. Do you trust this repository and wish to add it to the trusted list of repositories (y/N)?)�y�yesz"The repository is already trusted.)r�no�zUntrusted repository.zUnrecognized response �.�ar&)r5rQr>rerRr�touch�open�tuple�next�walk�_TRUSTED_REPO_OWNERSr�r��input�lower�print� Exceptionr�r) rYrZr�r�r�r��filepath�fileZ trusted_reposZtrusted_repos_legacyZ owner_nameZ is_trustedr�rrrr�-sP   ������ � �  "��r�cCsddl}|j�|�duSr)rDrF� find_spec)rLrMrrr�_check_module_existsgsr�cCsDt|t�}|durdd�|D�}t|�r tdd�|�����dSdS)NcSsg|]}t|�s|�qSr)r�)r��pkgrrr� <listcomp>qsz'_check_dependencies.<locals>.<listcomp>zMissing dependencies: z, )r`�VAR_DEPENDENCY�lenrpre)�mr<Z missing_depsrrr�_check_dependenciesms �r�cCsHt|t�s td��t|�t||�}|dust|�s"td|�d���|S)Nz8Invalid input: model should be a string of function namezCannot find callable z in hubconf)rI�strr�r�r`�callablerp)r��model�funcrrr�_load_entry_from_hubconfvs  r�cCs0t�d�r t�d�tdurtStj�t�d�S)a� Get the Torch Hub cache directory used for storing downloaded models & weights. If :func:`~torch.hub.set_dir` is not called, default path is ``$TORCH_HOME/hub`` where environment variable ``$TORCH_HOME`` defaults to ``$XDG_CACHE_HOME/torch``. ``$XDG_CACHE_HOME`` follows the X Design Group specification of the Linux filesystem layout, with a default value ``~/.cache`` if the environment variable is not set. Z TORCH_HUBz:TORCH_HUB is deprecated, please use env TORCH_HOME insteadN�hub)rQrcr�r�r=r>rerhrrrrr5�s r5cCstj�|�adS)z� Optionally set the Torch Hub directory used to save downloaded models & weights. Args: d (str): path to a local folder to save downloaded models & weights. N)rQr>rbr=)�drrrr:�sr:csnt|||d||d�}t|��tj�|t�}tt|��Wd�n1s%wY�fdd�t��D�}|S)a* List all callable entrypoints available in the repo specified by ``github``. Args: github (str): a string with format "repo_owner/repo_name[:ref]" with an optional ref (tag or branch). If ``ref`` is not specified, the default branch is assumed to be ``main`` if it exists, and otherwise ``master``. Example: 'pytorch/vision:0.10' force_reload (bool, optional): whether to discard the existing cache and force a fresh download. Default is ``False``. skip_validation (bool, optional): if ``False``, torchhub will check that the branch or commit specified by the ``github`` argument properly belongs to the repo owner. This will make requests to the GitHub API; you can specify a non-default GitHub token by setting the ``GITHUB_TOKEN`` environment variable. Default is ``False``. trust_repo (bool, str or None): ``"check"``, ``True``, ``False`` or ``None``. This parameter was introduced in v1.12 and helps ensuring that users only run code from repos that they trust. - If ``False``, a prompt will ask the user whether the repo should be trusted. - If ``True``, the repo will be added to the trusted list and loaded without requiring explicit confirmation. - If ``"check"``, the repo will be checked against the list of trusted repos in the cache. If it is not present in that list, the behaviour will fall back onto the ``trust_repo=False`` option. - If ``None``: this will raise a warning, inviting the user to set ``trust_repo`` to either ``False``, ``True`` or ``"check"``. This is only present for backward compatibility and will be removed in v2.0. Default is ``None`` and will eventually change to ``"check"`` in v2.0. verbose (bool, optional): If ``False``, mute messages about hitting local caches. Note that the message about first download cannot be muted. Default is ``True``. Returns: list: The available callables entrypoint Example: >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB) >>> entrypoints = torch.hub.list("pytorch/vision", force_reload=True) r7�r�r�Ncs(g|]}tt�|��r|�d�s|�qS)rl)r�r^r�)r��f�� hub_modulerrr��s ���zlist.<locals>.<listcomp>)r�rBrQr>re�MODULE_HUBCONFrPr])rqr�r�r�r�r�� hubconf_pathZ entrypointsrr�rr7�s 1�  � �r7c Csdt|||dd|d�}t|��tj�|t�}tt|�}Wd�n1s%wYt||�}|jS)aT Show the docstring of entrypoint ``model``. Args: github (str): a string with format <repo_owner/repo_name[:ref]> with an optional ref (a tag or a branch). If ``ref`` is not specified, the default branch is assumed to be ``main`` if it exists, and otherwise ``master``. Example: 'pytorch/vision:0.10' model (str): a string of entrypoint name defined in repo's ``hubconf.py`` force_reload (bool, optional): whether to discard the existing cache and force a fresh download. Default is ``False``. skip_validation (bool, optional): if ``False``, torchhub will check that the ref specified by the ``github`` argument properly belongs to the repo owner. This will make requests to the GitHub API; you can specify a non-default GitHub token by setting the ``GITHUB_TOKEN`` environment variable. Default is ``False``. trust_repo (bool, str or None): ``"check"``, ``True``, ``False`` or ``None``. This parameter was introduced in v1.12 and helps ensuring that users only run code from repos that they trust. - If ``False``, a prompt will ask the user whether the repo should be trusted. - If ``True``, the repo will be added to the trusted list and loaded without requiring explicit confirmation. - If ``"check"``, the repo will be checked against the list of trusted repos in the cache. If it is not present in that list, the behaviour will fall back onto the ``trust_repo=False`` option. - If ``None``: this will raise a warning, inviting the user to set ``trust_repo`` to either ``False``, ``True`` or ``"check"``. This is only present for backward compatibility and will be removed in v2.0. Default is ``None`` and will eventually change to ``"check"`` in v2.0. Example: >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB) >>> print(torch.hub.help("pytorch/vision", "resnet18", force_reload=True)) r6Tr�N) r�rBrQr>rer�rPr��__doc__) rqr�r�r�r�r�r�r��entryrrrr6�s%�  � r6rq)�sourcer�r�r�r�c OsX|��}|dvrtd|�d���|dkrt|||d||d�}t||g|�Ri|��}|S)a� Load a model from a github repo or a local directory. Note: Loading a model is the typical use case, but this can also be used to for loading other objects such as tokenizers, loss functions, etc. If ``source`` is 'github', ``repo_or_dir`` is expected to be of the form ``repo_owner/repo_name[:ref]`` with an optional ref (a tag or a branch). If ``source`` is 'local', ``repo_or_dir`` is expected to be a path to a local directory. Args: repo_or_dir (str): If ``source`` is 'github', this should correspond to a github repo with format ``repo_owner/repo_name[:ref]`` with an optional ref (tag or branch), for example 'pytorch/vision:0.10'. If ``ref`` is not specified, the default branch is assumed to be ``main`` if it exists, and otherwise ``master``. If ``source`` is 'local' then it should be a path to a local directory. model (str): the name of a callable (entrypoint) defined in the repo/dir's ``hubconf.py``. *args (optional): the corresponding args for callable ``model``. source (str, optional): 'github' or 'local'. Specifies how ``repo_or_dir`` is to be interpreted. Default is 'github'. trust_repo (bool, str or None): ``"check"``, ``True``, ``False`` or ``None``. This parameter was introduced in v1.12 and helps ensuring that users only run code from repos that they trust. - If ``False``, a prompt will ask the user whether the repo should be trusted. - If ``True``, the repo will be added to the trusted list and loaded without requiring explicit confirmation. - If ``"check"``, the repo will be checked against the list of trusted repos in the cache. If it is not present in that list, the behaviour will fall back onto the ``trust_repo=False`` option. - If ``None``: this will raise a warning, inviting the user to set ``trust_repo`` to either ``False``, ``True`` or ``"check"``. This is only present for backward compatibility and will be removed in v2.0. Default is ``None`` and will eventually change to ``"check"`` in v2.0. force_reload (bool, optional): whether to force a fresh download of the github repo unconditionally. Does not have any effect if ``source = 'local'``. Default is ``False``. verbose (bool, optional): If ``False``, mute messages about hitting local caches. Note that the message about first download cannot be muted. Does not have any effect if ``source = 'local'``. Default is ``True``. skip_validation (bool, optional): if ``False``, torchhub will check that the branch or commit specified by the ``github`` argument properly belongs to the repo owner. This will make requests to the GitHub API; you can specify a non-default GitHub token by setting the ``GITHUB_TOKEN`` environment variable. Default is ``False``. **kwargs (optional): the corresponding kwargs for callable ``model``. Returns: The output of the ``model`` callable when called with the given ``*args`` and ``**kwargs``. Example: >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB) >>> # from a github repo >>> repo = "pytorch/vision" >>> model = torch.hub.load( ... repo, "resnet50", weights="ResNet50_Weights.IMAGENET1K_V1" ... ) >>> # from a local directory >>> path = "/some/local/path/pytorch/vision" >>> # xdoctest: +SKIP >>> model = torch.hub.load(path, "resnet50", weights="ResNet50_Weights.DEFAULT") )rq�localzUnknown source: "z&". Allowed values: "github" | "local".rqr8r�)r�r�r�� _load_local) Z repo_or_dirr�r�r�r�r�r�rrrrrr8%s Q �� cOs^t|��!tj�|t�}tt|�}t||�}||i|��}Wd�|S1s(wY|S)a� Load a model from a local directory with a ``hubconf.py``. Args: hubconf_dir (str): path to a local directory that contains a ``hubconf.py``. model (str): name of an entrypoint defined in the directory's ``hubconf.py``. *args (optional): the corresponding args for callable ``model``. **kwargs (optional): the corresponding kwargs for callable ``model``. Returns: a single model with corresponding pretrained weights. Example: >>> # xdoctest: +SKIP("stub local path") >>> path = "/some/local/path/pytorch/vision" >>> model = _load_local(path, "resnet50", weights="ResNet50_Weights.IMAGENET1K_V1") N)rBrQr>rer�rPr�)Z hubconf_dirr�rrr�r�r�rrrr��s    ��r�ry�dst� hash_prefixr��returnc Cs�d}t|ddid�}t|�}|��}t|d�r|�d�}n|�d�}|dur2t|�dkr2t|d�}tj � |�}t t j �D]} |dt��jd } zt| d �} Wn tyZYq=wnttjd ��z�|durlt��} t|| d d dd��+} |�t�}t|�dkr�n| �|�|dur�| �|�| �t|��qxWd�n1s�wY| ��|dur�| ��}|dt|��|kr�td|�d|�d���t� | j!|�W| ��tj �"| j!�r�t�#| j!�dSdS| ��tj �"| j!�r�t�#| j!�ww)a�Download object at the given URL to a local path. Args: url (str): URL of the object to download dst (str): Full path where object will be saved, e.g. ``/tmp/temporary_file`` hash_prefix (str, optional): If not None, the SHA256 downloaded file should start with ``hash_prefix``. Default: None progress (bool, optional): whether or not to display a progress bar to stderr Default: True Example: >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB) >>> # xdoctest: +REQUIRES(POSIX) >>> torch.hub.download_url_to_file( ... "https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth", ... "/tmp/temporary_file", ... ) Nz User-Agentz torch.hubr� getheaderszContent-Lengthrr�z.partialzw+bz#No usable temporary file name found�BTi)rrr� unit_scale� unit_divisorzinvalid hash value (expected "z", got "z"))$r r �info�hasattrr��get_allr��intrQr>rb�range�tempfile�TMP_MAX�uuid�uuid4�hexr��FileExistsError�errno�EEXIST�hashlib�sha256r3ru�READ_DATA_CHUNKrr!r*� hexdigestrprTr�rLrRr@)ryr�r�r�� file_size�req�u�meta�content_length�seqZtmp_dstr�r��pbar�buffer�digestrrrr4�sr      � �    ������r4r�cCs6t�|�rt�|���}t|�dko|d�� SdS)Nr~rF)r�� is_zipfiler�r�r��is_dir)r�r�rrr�_is_legacy_zip_formats rz�Falling back to the old format < 1.6. This support will be deprecated in favor of default zipfile format introduced in 1.6. Please redo torch.save() to save it in the new zipfile format.)�category� model_dir� map_location� weights_onlycCsxt�|��'}|��}t|�dkrtd��|�|�|dj}tj� ||�}Wd�n1s/wYt j |||d�S)Nr~z0Only one file(not dir) is allowed in the zipfiler�rr) r�r�r�r�rpr�r�rQr>rerar8)r�rrrr��membersZ extraced_nameZextracted_filerrr�_legacy_zip_loads    ��r� check_hash� file_namec Cs�t�d�r t�d�|durt�}tj�|d�}tj|dd�t|�}tj� |j�} |dur0|} tj�|| �} tj� | �sdt j � d|�d| �d ��d} |r\t�| �} | rZ| �d �nd} t|| | |d �t| �rot| |||�Stj| ||d �S) aqLoads the Torch serialized object at the given URL. If downloaded file is a zip file, it will be automatically decompressed. If the object is already present in `model_dir`, it's deserialized and returned. The default value of ``model_dir`` is ``<hub_dir>/checkpoints`` where ``hub_dir`` is the directory returned by :func:`~torch.hub.get_dir`. Args: url (str): URL of the object to download model_dir (str, optional): directory in which to save the object map_location (optional): a function or a dict specifying how to remap storage locations (see torch.load) progress (bool, optional): whether or not to display a progress bar to stderr. Default: True check_hash(bool, optional): If True, the filename part of the URL should follow the naming convention ``filename-<sha256>.ext`` where ``<sha256>`` is the first eight or more digits of the SHA256 hash of the contents of the file. The hash is used to ensure unique names and to verify the contents of the file. Default: False file_name (str, optional): name for the downloaded file. Filename from ``url`` will be used if not set. weights_only(bool, optional): If True, only weights will be loaded and no complex pickled objects. Recommended for untrusted sources. See :func:`~torch.load` for more details. Example: >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB) >>> state_dict = torch.hub.load_state_dict_from_url( ... "https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth" ... ) ZTORCH_MODEL_ZOOz@TORCH_MODEL_ZOO is deprecated, please use env TORCH_HOME insteadNZ checkpointsTr�r�r�r&r~r�r)rQrcr�r�r5r>rer�r �basenamerRrrr� HASH_REGEX�search�groupr4rrrar8) ryrrr�rr rr��partsr�r�r�rzrrrr9#s. *�  r9)TF)r8)FFNT)FFNr()NNTFNF)K� contextlibr�r�r�rQ�rerTrr�r�r�r��pathlibr�typingrrr�typing_extensionsr� urllib.errorrr� urllib.parser �urllib.requestr r ra�torch.serializationr r r3� ImportError�__all__�compiler r�r�rdrfrgr�r�r�r=r��__annotations__�contextmanagerrBrPrVr\r`rhrtr{r�r�r�r�r�r�r5r:r7r6r8r��boolr4r� FutureWarningrr9rrrr�<module>s�     & �     #! �Y �:   � H; �f!����� �X�����  ��������� �
Memory