CoolFace
Apppublic

declare-lab/tango2

sourceHugging Faceupdated 2y agoView on Hugging Face
92likes
hub_utils.cpython-39.pyc81 linesDownload Raw Back to __pycache__
1a

2��'d]=�@s�ddlZddlZddlZddlZddlZddlmZddlmZm	Z	m3Z4ddlmZddl
mZmZmZmZmZddlmZddlmZmZmZmZddlmZdd	lmZd5dlmZdd
l m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.ddl/m0Z0e0e1�Z2ee3�j4dZ5e�j6Z7e�8dd��9�e'vZ:e�8dd��9�e'vZ;e#dZ<d:e6ee=dfe=d�dd�Z>d;e=e	e=e	e=d�dd�Z?dd�Z@d<e	e=e	e=d�dd�ZAejB�Ce�8d ejB�De�8d!d"�d#���ZEejB�DeEd$�ZFd=e	e=e	e=dd%�d&d'�ZGejB�De"d(�ZHejB�IeH��s"dZJn6eKeH��ZLeMeL�N��ZJWd�n1�sN0YeJdk�r�ejB�OeF��o�ePe�QeF��dkZReR�r�e2�Sd)�z7eG�WnZeT�y�ZUz@d*�De�VeUjW��ZXe2�Yd+eX�d*eUjZj1�d,eU�d-��WYdZU[Un8dZU[U00eJdk�rrzHej[e"d.d/�eKeHd0��ZLeL�\d1�Wd�n1�s>0YWn&eT�ype2�Sd2e"�d3��Yn0d>e=e	e=e=d4�d5d6�Z]dd7�d8d9�Z^dS)?�N)�Path)�Dict�Optional�Union)�uuid4)�HfFolder�	ModelCard�
ModelCardData�hf_hub_download�whoami)�REGEX_COMMIT_HASH)�EntryNotFoundError�RepositoryNotFoundError�RevisionNotFoundError�is_jinja_available)�version)�	HTTPError�)�__version__�)�DEPRECATED_REVISION_ARGS�DIFFUSERS_CACHE�HUGGINGFACE_CO_RESOLVE_ENDPOINT�SAFETENSORS_WEIGHTS_NAME�WEIGHTS_NAME)�ENV_VARS_TRUE_VALUES�
_flax_version�_jax_version�_onnxruntime_version�_torch_version�is_flax_available�is_onnx_available�is_torch_available)�9get_loggerzmodel_card_template.md�HF_HUB_OFFLINE��DISABLE_TELEMETRYz/api/telemetry/)�10user_agent�returncCs�dt�dtj��d�dt��}ts(tr0|dSt�rD|dt��7}t	�rf|dt11��7}|dt��7}t�rz|d	t
��7}tj�d12d���tvr�|d7}t|t�r�|d
d
�dd�|��D��7}nt|t�r�|d
|7}|S)zF13    Formats a user-agent string with basic info about a request.14    z15diffusers/z	; python/rz
; session_id/z; telemetry/offz; torch/z; jax/z; flax/z; onnxruntime/ZDIFFUSERS_IS_CIr%z; is_ci/truez; css |]\}}|�d|��VqdS)�/N�)�.0�k�vr*r*�N/home/deep/Projects/audio_diffusion/diffusers/src/diffusers/utils/hub_utils.py�	<genexpr>V�z"http_user_agent.<locals>.<genexpr>)r�sysr�split�16SESSION_IDr&r$r"rr rrr!r�os�environ�get�upperr�17isinstance�dict�join�items�str)r'�uar*r*r.�http_user_agentDs" 18"19r>)�model_id�organization�tokencCsD|durt��}|dur2t|�d}|�d|��S|�d|��SdS)N�namer))r�	get_tokenr)r?r@rA�usernamer*r*r.�get_full_repo_name\srEcCsdt�std��t|d�r&|jdvr&dSt|d�r6|jnd}t||d�}tjtdddg|j	gd	�t20||t|d21�rt|j	nd|j|j|j
t|d�r�|jndt|d�r�|jndt|d
�r�|jndt|d�r�|jndt|d�r�|jndt|d�r�|jndt|d�r�|jndt|d��r|jndt|d��r&|jndt|d��r:|jnd|jd�}tj�|jd�}|�|�dS)Nz�Modelcard rendering is based on Jinja templates. Please make sure to have `jinja` installed before using `create_model_card`. To install it, please run `pip install Jinja2`.�22local_rank)�����r�	hub_token)rA�enz23apache-2.0�	diffusers)�language�license�library_name�tags�datasets�metrics�dataset_name�gradient_accumulation_steps�24adam_beta1�25adam_beta2�adam_weight_decay�adam_epsilon�lr_scheduler�lr_warmup_steps�
ema_inv_gamma�	ema_power�
ema_max_decay)Z	card_dataZ
template_path�26model_name�	repo_namerQ�
learning_rate�train_batch_size�eval_batch_sizerRrSrTrUrVrWrXrYrZr[�mixed_precisionz	README.md)r�27ValueError�hasattrrFrHrErZ
from_templater	rQ�MODEL_CARD_TEMPLATE_PATHr^r_r`rRrSrTrUrVrWrXrYrZr[rar4�pathr:�28output_dir�save)�argsr\rHr]Z29model_cardZ	card_pathr*r*r.�create_model_cardfsL���ri)�
resolved_file�commit_hashcCsZ|dus|dur|Stt|����}t�d|�}|dur<dS|��d}t�|�rV|SdS)zP30    Extracts the commit hash from a resolved filename toward a cache file.31    Nzsnapshots/([^/]+)/r)r<r�as_posix�re�search�groupsr�match)rjrkrnr*r*r.�extract_commit_hash�srqZHF_HOME�XDG_CACHE_HOMEz~/.cache�huggingfacerJ)�
old_cache_dir�
new_cache_dirr(c	Cs�|durt}|durt}t|���}t|���}|�d�D]l}|��r:|��s:||�|�}|jj	ddd�t32�||�zt33�||�Wq:t
y�t�d�Yq:0q:dS)Nz34**/blobs/*T)�parents�exist_okz�Could not create symlink between old cache and new cache. If you use an older version of diffusers again, files will be re-downloaded.)r�old_diffusers_cacher�35expanduser�glob�is_file�36is_symlink�relative_to�parent�mkdirr4�replace�symlink�OSError�logger�warning)rtruZ
old_blob_pathZ
new_blob_pathr*r*r.�37move_cache�s"�r�zversion_diffusers_cache.txtz�The cache for model files in Diffusers v0.14.0 has moved to a new location. Moving your existing cached models. This is a one-time operation, you can interrupt it or run it later by calling `diffusers.utils.hub_utils.move_cache()`.�38z5There was a problem when trying to move your cache:39 40z: z�41 42Please file an issue at https://github.com/huggingface/diffusers/issues/new/choose, copy paste this whole message and we will do our best to help.T)rw�w�1z?There was a problem when trying to write in your cache folder (z=). Please, ensure the directory exists and can be written to.)�weights_name�variantr(cCs>|dur:|�d�}|dd�|g|dd�}d�|�}|S)N�.rG)r2r:)r�r��splitsr*r*r.�_add_variant�s434445r�)rkcCs�t|�}tj�|�r|Stj�|�r�tj�tj�||��rLtj�||�}|S|dur�tj�tj�|||��r�tj�|||�}|Std|�d|�d����n&|46tv�r�|tks�|t	k�r�t47�t48�t�j
�t49�d�k�r�zbt|t||50�|||||||	||51�p�|d�}t�d|52�d|�d|53�d	|54�d55|56�d|57�d�
t�|WSt�d
|58�d|�d|59�d|60�d|�dt||61��d|�d|�dt||62��d�t�Yn0z*t|||||||||	||63�p�|d�}|WSt�y�t|�d���Yn�t�yt|64�d|�d���Yn�t�y,t|�d|�d���Yn�t�yd}
z td|�d|
����WYd}
~
ndd}
~
0t�y�tdt�d|�d|�d���Yn.t�y�td|�d |�d!|����Yn0dS)"NzError no file named z found in directory r�z0.17.0)65�filename�	cache_dir�force_download�proxies�resume_download�local_files_only�use_auth_tokenr'�	subfolder�revisionzLoading the variant z from z via `revision='zG'` is deprecated. Loading instead from `revision='main'` with `variant=z)`. Loading model variants via `revision='z9'` will be removed in diffusers v1. Please use `variant='z'` instead.zYou are loading the variant z^'`. This behavior is deprecated and will be removed in diffusers v1. One should use `variant='z%'` instead. However, it appears that z currently does not have a z file in the 'main' branch of z�. 66 The Diffusers team and community would be very grateful if you could open an issue: https://github.com/huggingface/diffusers/issues/new with the title 'z is missing z0' so that the correct variant file can be added.z� is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'67If this is a private repository, make sure to pass a token having permission to this repo with `use_auth_token` or log in with `huggingface-cli login`.z� is not a valid git identifier (branch name, tag name or commit id) that exists for this model name. Check the model page at 'https://huggingface.co/z' for available revisions.z& does not appear to have a file named z:There was a specific connection error when trying to load z:68zWe couldn't connect to 'zM' to load this model, couldn't find it in the cached files and it looks like z8 is not the path to a directory containing a file named z� or 69Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/diffusers/installation#offline-mode'.zCan't load the model for 'z�'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'z=' is the correct path to a directory containing a file named )r<r4re�isfile�isdirr:�EnvironmentErrorrrrr�parser�base_versionr70r��warnings�warn�
FutureWarningrrr
rrbr)�pretrained_model_name_or_pathr�r�r�r�r�r�r�r�r'r�rkZ71model_file�errr*r*r.�_get_model_file�s��������
(�F�72�
�����������r�)N)NN)N)NN)N)_r4rmr1�	tracebackr��pathlibr�typingrrr�uuidr�huggingface_hubrrr	r73rZhuggingface_hub.file_downloadr�huggingface_hub.utilsr
rrr�	packagingr�requestsrr%r�	constantsrrrrr�import_utilsrrrrrr r!r"�loggingr#�__name__r��__file__r~rd�hexr3�getenvr7r$r&ZHUGGINGFACE_CO_TELEMETRYr<r>rErirqreryr:�
hf_cache_homerxr��cache_version_filer��
cache_version�open�f�int�readr��len�listdirZold_cache_is_not_emptyr��	Exception�e�	format_tb�
__traceback__�trace�error�	__class__�makedirs�writer�r�r*r*r*r.�<module>sz(74751�76,77 �78�79.8081�