Ë
    (täid  ã                   ón  — d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZmZmZmZmZmZmZmZ d dlmZmZ d dlmZ d dlmZmZmZmZmZmZ d dlm Z  d	d
l!m"Z" ddl#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2  e2e3«      Z4 ee5«      jl                  dz  Z7 e	«       jp                  Z9d:de:e;z  dz  de;fd„Z<	 	 	 	 	 	 	 	 	 	 	 	 d;de;de;dz  de=de=de;dz  de;de;dz  de;dz  de>e:   dz  de=dz  de=de=defd „Z?d:d!ed"e;e>e;   z  dz  defd#„Z@d:d$e;dz  d%e;dz  fd&„ZAd:d'e;d(e;dz  de;fd)„ZBeddddddddddd*œ
d+e;ez  d'e;d,e;dz  d-e;dz  d.e=d/e:dz  d0e=de;dz  de:e;z  dz  d1e;dz  d%e;dz  d2e:e;ef   dz  fd3„«       ZC	 	 	 	 	 	 	 	 d<d2e:e;ef   dz  fd4„ZDd=d5e;d6e>e;   d(e;fd7„ZE G d8„ d9«      ZFy)>é    N)ÚPath)Úuuid4)Ú	DDUFEntryÚ	ModelCardÚModelCardDataÚcreate_repoÚhf_hub_downloadÚ
model_infoÚsnapshot_downloadÚupload_folder)ÚHF_HUB_DISABLE_TELEMETRYÚHF_HUB_OFFLINE)ÚREGEX_COMMIT_HASH)ÚEntryNotFoundErrorÚHfHubHTTPErrorÚRepositoryNotFoundErrorÚRevisionNotFoundErrorÚis_jinja_availableÚvalidate_hf_hub_args)Úversioné   )Ú__version__é   )ÚDEPRECATED_REVISION_ARGSÚ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)Ú
get_loggerzmodel_card_template.mdÚ
user_agentÚreturnc                 óF  — dt         › dt        j                  j                  «       d   › dt        › �}t
        st        r|dz   S t        «       r|dt        › �z  }t        «       r|dt        › �z  }|dt        › �z  }t        «       r|d	t        › �z  }t        j                  j!                  d
d«      j#                  «       t$        v r|dz  }t'        | t(        «      r.|ddj+                  d„ | j-                  «       D «       «      z   z  }|S t'        | t.        «      r|d| z   z  }|S )zF
    Formats a user-agent string with basic info about a request.
    z
diffusers/z	; python/r   z; session_id/z; telemetry/offz; torch/z; jax/z; flax/z; onnxruntime/ÚDIFFUSERS_IS_CIÚ z; is_ci/truez; c              3   ó0   K  — | ]  \  }}|› d |› �–— Œ y­w)Ú/N© )Ú.0ÚkÚvs      úh/Volumes/fast/ai/experiments/MLX_z-image/.venv/lib/python3.12/site-packages/diffusers/utils/hub_utils.pyÚ	<genexpr>z"http_user_agent.<locals>.<genexpr>\   s!   è ø€ ÐIÑ6H©d¨a° !  A a SœzÑ6Hùs   ‚)r   Úsysr   ÚsplitÚ
SESSION_IDr   r   r%   r"   r#   r    r   r$   r!   ÚosÚenvironÚgetÚupperr   Ú
isinstanceÚdictÚjoinÚitemsÚstr)r'   Úuas     r2   Úhttp_user_agentrA   J   s  € ð ”k�] )¬C¯K©K×,=Ñ,=Ó,?ÀÑ,BÐ+CÀ=ÔQ[ÐP\Ð	]€BÝ¥>ØÐ%Ñ%Ð%ÜÔØ
�œÐ(Ð)Ñ)ˆÜÔØ
�”|�nÐ%Ñ%ˆØ
�œ�Ð'Ñ'ˆÜÔØ
�Ô3Ð4Ð5Ñ5ˆä	‡z�z‡~�~Ð'¨Ó,×2Ñ2Ó4Ô8LÑLØ
ˆnÑˆÜ�*œdÔ#Ø
ˆd�T—Y‘YÑI°j×6FÑ6FÔ6HÓIÓIÑIÑIˆð €Iô 
�J¤Ô	$Ø
ˆd�ZÑÑˆØ€Ió    FÚrepo_id_or_pathÚtokenÚis_pipelineÚfrom_trainingÚmodel_descriptionÚ
base_modelÚpromptÚlicenseÚwidgetÚ	inferenceÚ
is_modularÚupdate_model_cardc                 óâ  — t        «       st        d«      ‚|r|
st        d«      ‚	 t        j                  | |¬«      }|r"|
r |�|j                  }t        |«      }||_        |S # t
        t        f$ r| |r.t        j                  t        |d|	|||¬«      t        |¬«      }Y |S t        «       }|
r|�t        |«      }||_        Y |S |rdnd}|€d	|› d
�}t        j                  ||¬«      }Y |S w xY w)aˆ  
    Loads or creates a model card.

    Args:
        repo_id_or_path (`str`):
            The repo id (e.g., "stable-diffusion-v1-5/stable-diffusion-v1-5") or local path where to look for the model
            card.
        token (`str`, *optional*):
            Authentication token. Will default to the stored token. See https://huggingface.co/settings/token for more
            details.
        is_pipeline (`bool`):
            Boolean to indicate if we're adding tag to a [`DiffusionPipeline`].
        from_training: (`bool`): Boolean flag to denote if the model card is being created from a training script.
        model_description (`str`, *optional*): Model description to add to the model card. Helpful when using
            `load_or_create_model_card` from a training script.
        base_model (`str`): Base model identifier (e.g., "stabilityai/stable-diffusion-xl-base-1.0"). Useful
            for DreamBooth-like training.
        prompt (`str`, *optional*): Prompt used for training. Useful for DreamBooth-like training.
        license: (`str`, *optional*): License of the output artifact. Helpful when using
            `load_or_create_model_card` from a training script.
        widget (`list[dict]`, *optional*): Widget to accompany a gallery template.
        inference: (`bool`, optional): Whether to turn on inference widget. Helpful when using
            `load_or_create_model_card` from a training script.
        is_modular: (`bool`, optional): Boolean flag to denote if the model card is for a modular pipeline.
            When True, uses model_description as-is without additional template formatting.
        update_model_card: (`bool`, optional): When True, regenerates the model card content even if one
            already exists on the remote repo. Existing card metadata (tags, license, etc.) is preserved. Only
            supported for modular pipelines (i.e., `is_modular=True`).
    zµModelcard rendering is based on Jinja templates. Please make sure to have `jinja` installed before using `load_or_create_model_card`. To install it, please run `pip install Jinja2`.zU`update_model_card=True` is only supported for modular pipelines (`is_modular=True`).©rD   Ú	diffusers)rJ   Úlibrary_namerL   rH   Úinstance_promptrK   )Ú	card_dataÚtemplate_pathrG   ÚpipelineÚmodelu+   This is the model card of a ðŸ§¨ diffusers zS that has been pushed on the Hub. This model card has been automatically generated.)rG   )
r   Ú
ValueErrorr   ÚloadÚdatar   r   Úfrom_templater   ÚMODEL_CARD_TEMPLATE_PATH)rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   Ú
model_cardÚexisting_datarT   Ú	components                   r2   Úload_or_create_model_cardr`   b   s9  € ôV ÔÜð?ó
ð 	
ñ ¡ÜÐpÓqÐqð eä—^‘^ O¸5ÔAˆ
á¡Ð0AÐ0MØ&ŸO™OˆMÜ"Ð#4Ó5ˆJØ+ˆJŒOð6 Ðøô5 Ô 7Ð8ò eáÜ"×0Ñ0Ü'Ø#Ø!,Ø'Ø)Ø$*Ø!ôô 7Ø"3ô‰Jð. Ðô &›ˆIÙÐ/Ð;Ü&Ð'8Ó9�
Ø"+�
•ð Ðñ +6™J¸7�	Ø$Ð,Ø*UÐV_ÐU`ð  atð  )uÐ%Ü&×4Ñ4°YÐRcÔd‘
àÐð5eús   ¦;A# Á#<C.Â" C.Ã%C.Ã-C.r]   Útagsc                 ó$  — | j                   j                  €d| j                   _        |�ft        |t        «      r|g}| j                   j                  €g | j                   _        |D ]'  }| j                   j                  j                  |«       Œ) | S )z?Populates the `model_card` with library name and optional tags.rQ   )rZ   rR   r;   r?   ra   Úappend)r]   ra   Útags      r2   Úpopulate_model_cardre   ¼   s{   € à‡�×#Ñ#Ð+Ø'2ˆ
�‰Ô$àÐÜ�dœCÔ Ø�6ˆDØ�?‰?×ÑÐ'Ø#%ˆJ�O‰OÔ ÛˆCØ�O‰O× Ñ ×'Ñ'¨Õ,ð ð ÐrB   Úresolved_fileÚcommit_hashc                 óÜ   — | �|�|S t        t        | «      j                  «       «      } t        j                  d| «      }|€y|j                  «       d   }t        j                  |«      r|S dS )zP
    Extracts the commit hash from a resolved filename toward a cache file.
    Nzsnapshots/([^/]+)/r   )r?   r   Úas_posixÚreÚsearchÚgroupsr   Úmatch)rf   rg   rk   s      r2   Úextract_commit_hashrn   Ì   sn   € ð Ð Ð 7ØÐÜœ˜]Ó+×4Ñ4Ó6Ó7€MÜ�Y‰YÐ,¨mÓ<€FØ€~ØØ—-‘-“/ !Ñ$€KÜ+×1Ñ1°+Ô>ˆ;ÐHÀDÐHrB   Úweights_nameÚvariantc                 ól   — |�1| j                  d«      }|d d |gz   |dd  z   }dj                  |«      } | S )NÚ.éÿÿÿÿ)r5   r=   )ro   rp   Úsplitss      r2   Ú_add_variantru   Ú   sI   € ØÐØ×#Ñ# CÓ(ˆØ˜˜� ˜yÑ(¨6°"°#¨;Ñ6ˆØ—x‘x Ó'ˆàÐrB   )
Ú	subfolderÚ	cache_dirÚforce_downloadÚproxiesÚlocal_files_onlyrD   r'   Úrevisionrg   Údduf_entriesÚpretrained_model_name_or_pathrv   rw   rx   ry   rz   r{   r|   c                ó¬  — t        | «      } |rM|�t        d«      ‚| dk(  r|ndj                  | |g«      }||v r|S t        d|› d|j	                  «       › d�«      ‚t
        j                  j                  | «      r| S t
        j                  j                  | «      rÔt
        j                  j                  t
        j                  j                  | |«      «      r"t
        j                  j                  | |«      }|S |�at
        j                  j                  t
        j                  j                  | ||«      «      r#t
        j                  j                  | ||«      }|S t        d|› d| › d�«      ‚|	t        v r±|t        k(  s	|t        k(  rŸt        j                  t        j                  t        «      j                  «      t        j                  d«      k\  rS	 t!        | t#        ||	«      ||||||||	xs |
¬	«
      }t%        j&                  d
|	› d| › d|	› d|	› d|	› d|	› d�t(        «       |S 	 t!        | |||||||||	xs |
¬	«
      }|S #  t%        j&                  d|	› d| › d|	› d|	› d| › dt#        ||	«      › d| › d| › dt#        ||	«      › d�t(        «       Y ŒjxY w# t*        $ r}t        | › d�«      |‚d }~wt,        $ r}t        |	› d| › d�«      |‚d }~wt.        $ r}t        | › d|› d�«      |‚d }~wt0        $ r}t        d| › d|› �«      |‚d }~wt        $ r}t        dt2        › d | › d!|› d"�«      |‚d }~wt        $ r}t        d#| › d$| › d%|› �«      |‚d }~ww xY w)&NzˆDDUF file only allow for 1 level of directory (e.g transformer/model1/model.safetentors is not allowed). Please check the DDUF structurer+   r-   zError no file named z found in archive rr   z found in directory z0.22.0)	Úfilenamerw   rx   ry   rz   rD   r'   rv   r{   zLoading 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.zYou 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œ. 
 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'
If this is a private repository, make sure to pass a token having permission to this repo with `token` or log in with `hf auth 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.ú& does not appear to have a file named z:There was a specific connection error when trying to load z:
úWe 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 
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/diffusers/installation#offline-mode'.zCan'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?   rX   r=   ÚEnvironmentErrorÚkeysr7   ÚpathÚisfileÚisdirr   r   r   r   Úparser   Úbase_versionr	   ru   ÚwarningsÚwarnÚFutureWarningr   r   r   r   r   )r}   ro   rv   rw   rx   ry   rz   rD   r'   r{   rg   r|   Ú
model_fileÚes                 r2   Ú_get_model_filerŽ   ã   sÈ  € ô  %(Ð(EÓ$FÐ!áØÐ Üð2óð ð -°Ò2ñ à—‘Ð8¸,ÐGÓHð 	ð
 ˜Ñ%ØÐä"Ð%9¸,¸ÐGYÐZf×ZkÑZkÓZmÐYnÐnoÐ#pÓqÐqÜ	�‰�‰Ð5Ô	6Ø,Ð,Ü	�‰�‰Ð4Ô	5Ü�7‰7�>‰>œ"Ÿ'™'Ÿ,™,Ð'DÀlÓSÔTäŸ™Ÿ™Ð&CÀ\ÓRˆJØÐØÐ"¤r§w¡w§~¡~Ü�G‰G�L‰LÐ6¸	À<ÓPô(
ô Ÿ™Ÿ™Ð&CÀYÐP\Ó]ˆJØÐä"Ø& | nÐ4HÐIfÐHgÐghÐióð ð Ô0Ñ0Ø¤Ò-°ÔAYÒ1YÜ—‘œgŸm™m¬KÓ8×EÑEÓFÌ'Ï-É-ÐX`ÓJaÒaðÜ,Ø1Ü)¨,¸ÓAØ'Ø#1Ø#Ø%5ØØ)Ø'Ø%Ò4¨ô�
ô —‘Ø*¨8¨*°FÐ;XÐ:YÐYiÐjrÐisð  t{ð  |Dð  {Eð  Enð  owð  nxð  xqð  rzð  q{ð  {Fð  GÜ!ôð "Ð!ð2	ä(Ø-Ø%Ø#Ø-ØØ!1ØØ%Ø#Ø!Ò0 [ôˆJð Ðøð'Ü—‘Ø2°8°*¸FÐC`ÐBaÐaqÐrzÐq{ð  |Zð  [cð  Zdð  dIð  Jgð  Ihð  hCô  DPð  Q]ð  _gó  Dhð  Cið  iGð  Heð  Gfð  fC	ð  D	a	ð  C	b	ð  b	n	ô  o	{	ð  |	H
ð  J
R
ó  o	S
ð  n	T
ð  T
Dð  EÜ!öûô( 'ò 	Ü"Ø0Ð1ð 2dð dóð ð	ûô
 %ò 	Ü"Ø�*ð +à+HÐ*IÐIcðeóð ð	ûô
 "ò 	Ü"Ø0Ð1Ð1WÐXdÐWeÐefÐgóàðûô ò 	Ü"ØLÐMjÐLkÐknÐopÐnqÐróàðûô ò 	Ü"Ø*Ô+JÐ*Kð L:Ø:WÐ9Xð Y6Ø6B°^ð Dfðfóð ðûô  ò 	Ü"Ø,Ð-JÐ,Kð L)à)FÐ(Gð H+Ø+7¨.ð:óð
 ðûð	úsb   ÇAI È)J ÉAJÊ	MÊJ-Ê-MÊ9KËMËK)Ë)MË5LÌMÌL-Ì-MÌ9MÍMc
                 óX  ‡— |	r||	vrCt        d|› d| › d�«      ‚t        j                  j                  |«      st        d|› d| › d�«      ‚|	r't	        j
                  |	|   j                  «       «      }
n8t        |d«      5 }t	        j
                  |j                  «       «      }
ddd«       t        t        
d   j                  «       «      «      }|
d   }t        |
d   j                  «       «      |d<   |
d   j                  «       |d<   t        j                  j                  | |«      }t        j                  j!                  | «      s|	r€|D �cg c]"  }t        j                  j                  ||«      ‘Œ$ }}|D ]J  Š|	r‰|	vsŒ
t#        |› d	‰› d
�«      ‚t        j                  j%                  ‰«      rŒ;t#        |› d	‰› d
�«      ‚ ||fS |}|�-|D �cg c]"  }t        j                  j                  ||«      ‘Œ$ }}ddg}|sFt'        | ||¬«      }|D ]3  Št)        ˆfd„|j*                  D «       «      }|rŒ$t-        |› d	‰› d
�«      ‚ 	 t/        | ||||||||¬«	      }|� t        j                  j                  ||«      }|D �cg c]"  }t        j                  j                  ||«      ‘Œ$ }}|D ]2  }t        j                  j                  |«      rŒ#t-        |› d|› d
�«      ‚ ||fS # 1 sw Y   �ŒFxY wc c}w c c}w # t0        $ r}t-        dt2        › d| › d�«      |‚d}~ww xY wc c}w )aÃ  
    For a given model:

    - download and cache all the shards of a sharded checkpoint if `pretrained_model_name_or_path` is a model ID on the
      Hub
    - returns the list of paths to all the shards, as well as some metadata.

    For the description of each arg, see [`PreTrainedModel.from_pretrained`]. `index_filename` is the full path to the
    index (downloaded and cached if `pretrained_model_name_or_path` is a model ID on the Hub).
    zCan't find a checkpoint index (z) in rr   ÚrNÚ
weight_mapÚmetadataÚall_checkpoint_keysr€   z5 which is required according to the checkpoint index.z*.jsonz*.md)r{   rD   c              3   ó:   •K  — | ]  }‰|j                   v –— Œ y ­w©N)Ú	rfilename)r/   r0   Ú
shard_files     €r2   r3   z._get_checkpoint_shard_files.<locals>.<genexpr>­  s   øè ø€ Ð$bÑHaÀ1 Z°1·;±;Ô%>ÑHaùs   ƒ)rw   ry   rz   rD   r{   Úallow_patternsÚignore_patternsr'   r�   z
' to load z?. You should try again after checking your internet connection.z does not have a file named )rX   r7   r„   r…   ÚjsonÚloadsÚ	read_textÚopenÚreadÚsortedÚsetÚvaluesÚlistrƒ   Úcopyr=   r†   ÚFileNotFoundErrorÚexistsr
   ÚanyÚsiblingsr‚   r   r   r   )r}   Úindex_filenamerw   ry   rz   rD   r'   r{   rv   r|   ÚindexÚfÚoriginal_shard_filenamesÚsharded_metadataÚshards_pathÚshard_filenamesr˜   Úpr™   Úmodel_files_infoÚshard_file_presentÚcached_folderr�   Úcached_filenamesÚcached_filer—   s                            @r2   Ú_get_checkpoint_shard_filesrµ   g  s…  ø€ ñ, Ø Ñ-ÜÐ>¸~Ð>NÈeÐTqÐSrÐrsÐtÓuÐuä�w‰w�~‰~˜nÔ-ÜÐ>¸~Ð>NÈeÐTqÐSrÐrsÐtÓuÐuáÜ—
‘
˜<¨Ñ7×AÑAÓCÓD‰ä�. #Ô&¨!Ü—J‘J˜qŸv™v›xÓ(ˆE÷ 'ô  &¤c¨%°Ñ*=×*DÑ*DÓ*FÓ&GÓHÐØ˜ZÑ(ÐÜ.2°5¸Ñ3F×3KÑ3KÓ3MÓ.NÐÐ*Ñ+Ø%*¨<Ñ%8×%=Ñ%=Ó%?Ð�\Ñ"Ü—'‘'—,‘,Ð<¸iÓH€Kô 
‡w�w‡}�}Ð2Ô3±|ÙAYÓZÑAY¸Aœ2Ÿ7™7Ÿ<™<¨°QÕ7ÐAYˆÐZÛ)ˆJÙØ \Ò1Ü+Ø&˜-Ð'MÈjÈ\ð ZFð Fóð ô
 —w‘w—~‘~ jÕ1Ü+Ø&˜-Ð'MÈjÈ\ð ZFð Fóð ð *ð Ð 0Ð0Ð0ð .€NØÐÙ>LÓM¹n¸œ"Ÿ'™'Ÿ,™, y°!Õ4¸nˆÐMà Ð(€Oñ Ü%Ð&CÈhÐ^cÔdÐÛ2ˆJÜ!$Ó$bÐHX×HaÒHaÓ$bÓ!bÐÚ%Ü&Ø"�mÐ#IÈ*Èð VBð Bóð ð 3ðä)Ø)ØØØ-ØØØ)Ø+Ø!ô

ˆð Ð ÜŸG™GŸL™L¨¸	ÓBˆMñ AYÓYÑ@X¸1œŸ™Ÿ™ ]°AÕ6Ð@XÐÐYÛ'ˆÜ�w‰w�~‰~˜kÕ*Ü"Ø �/Ð!=¸k¸]ÐJð  Aóð ð (ð Ð-Ð-Ð-÷Y 'Ñ&üò [ùò& NøôB ò ÜØ&Ô'FÐ&GÀzÐRoÐQpð q>ð >ó
ð ð	ûðüò Zs6   Â $K(Å'K5Ç'K:É
6K? Ê'L'Ë(K2Ë?	L$ÌLÌL$ÚfolderÚ	filenamesc                 ó4  ‡— |r| rt        d«      ‚|sUg }t        j                  | «      D ];  \  }}}|D ]0  }|j                  t        j                  j                  |«      «       Œ2 Œ= d}t        j                  d|› d|› d�«      Št        ˆfd„|D «       «      S )Nz1Both `filenames` and `folder` cannot be provided.z\d{5}-of-\d{5}z.*-z\.z	\.[a-z]+$c              3   óD   •K  — | ]  }‰j                  |«      d u–— Œ y ­wr•   )rm   )r/   rª   Úvariant_file_res     €r2   r3   z8_check_legacy_sharding_variant_format.<locals>.<genexpr>à  s"   øè ø€ ÐG¹Y¸ˆ×$Ñ$ QÓ'¨tÔ3¹Yùs   ƒ )	rX   r7   Úwalkrc   r„   Úbasenamerj   Úcompiler¦   )r¶   r·   rp   Ú_ÚfilesÚfileÚtransformers_index_formatrº   s          @r2   Ú%_check_legacy_sharding_variant_formatrÂ   Ö  s“   ø€ Ù‘VÜÐLÓMÐMÙØˆ	ÜŸ7™7 6ž?‰KˆAˆq�%Û�Ø× Ñ ¤§¡×!1Ñ!1°$Ó!7Õ8ñ ð +ð !2ÐÜ—j‘j CÐ(AÐ'BÀ"ÀWÀIÈYÐ!WÓX€OÜÓG¹YÓGÓGÐGrB   c                   óÀ   — e Zd ZdZ	 	 	 	 ddeej                  z  dededz  dedz  dededz  fd	„Z	 	 	 	 	 	 	 ddededz  d
edz  dedz  dedededz  dedz  defd„Z	y)ÚPushToHubMixinzR
    A Mixin to push a model, scheduler, or pipeline to the Hugging Face Hub.
    NÚworking_dirÚrepo_idrD   Úcommit_messageÚ	create_prrv   c                 óþ   — |€Od| j                   j                  v rd}n4d| j                   j                  v rd}nd| j                   j                  › �}t        j                  d|› d|› d�«       t	        ||||||¬	«      S )
zB
        Uploads all files in `working_dir` to `repo_id`.
        ÚModelzUpload modelÚ	SchedulerzUpload schedulerzUpload zUploading the files of z to rr   )rÆ   Úfolder_pathrD   rÇ   rÈ   Úpath_in_repo)Ú	__class__Ú__name__ÚloggerÚinfor   )ÚselfrÅ   rÆ   rD   rÇ   rÈ   rv   s          r2   Ú_upload_folderzPushToHubMixin._upload_folderè  sŠ   € ð Ð!Ø˜$Ÿ.™.×1Ñ1Ñ1Ø!/‘Ø §¡× 7Ñ 7Ñ7Ø!3‘à#*¨4¯>©>×+BÑ+BÐ*CÐ!D�ä�‰Ð-¨k¨]¸$¸w¸iÀqÐIÔJÜØØ#ØØ)ØØ"ô
ð 	
rB   ÚprivateÚsafe_serializationrp   r(   c	           	      óÐ  — t        |||d¬«      j                  }|st        ||¬«      }	t        |	«      }	d|i}
d| j                  j
                  vr|
j                  d|i«       t        j                  «       5 } | j                  |fi |
¤Ž |s/	j                  t        j                  j                  |d«      «       | j                  ||||||¬«      cd	d	d	«       S # 1 sw Y   y	xY w)
uy  
        Upload model, scheduler, or pipeline files to the ðŸ¤— Hugging Face Hub.

        Parameters:
            repo_id (`str`):
                The name of the repository you want to push your model, scheduler, or pipeline files to. It should
                contain your organization name when pushing to an organization. `repo_id` can also be a path to a local
                directory.
            commit_message (`str`, *optional*):
                Message to commit while pushing. Default to `"Upload {object}"`.
            private (`bool`, *optional*):
                Whether to make the repo private. If `None` (default), the repo will be public unless the
                organization's default is private. This value is ignored if the repo already exists.
            token (`str`, *optional*):
                The token to use as HTTP bearer authorization for remote files. The token generated when running `hf
                auth login` (stored in `~/.huggingface`).
            create_pr (`bool`, *optional*, defaults to `False`):
                Whether or not to create a PR with the uploaded files or directly commit.
            safe_serialization (`bool`, *optional*, defaults to `True`):
                Whether or not to convert the model weights to the `safetensors` format.
            variant (`str`, *optional*):
                If specified, weights are saved in the format `pytorch_model.<variant>.bin`.

        Examples:

        ```python
        from diffusers import UNet2DConditionModel

        unet = UNet2DConditionModel.from_pretrained("stabilityai/stable-diffusion-2", subfolder="unet")

        # Push the `unet` to your namespace with the name "my-finetuned-unet".
        unet.push_to_hub("my-finetuned-unet")

        # Push the `unet` to an organization with the name "my-finetuned-unet".
        unet.push_to_hub("your-org/my-finetuned-unet")
        ```
        T)rÔ   rD   Úexist_okrP   rÕ   rË   rp   z	README.md)rD   rÇ   rÈ   rv   N)r   rÆ   r`   re   rÎ   rÏ   ÚupdateÚtempfileÚTemporaryDirectoryÚsave_pretrainedÚsaver7   r„   r=   rÓ   )rÒ   rÆ   rÇ   rÔ   rD   rÈ   rÕ   rp   rv   r]   Úsave_kwargsÚtmpdirs               r2   Úpush_to_hubzPushToHubMixin.push_to_hub  sÜ   € ô` ˜g¨w¸eÈdÔS×[Ñ[ˆñ Ü2°7À%ÔHˆJÜ,¨ZÓ8ˆJð ,Ð-?Ð@ˆØ˜dŸn™n×5Ñ5Ñ5Ø×Ñ 	¨7Ð3Ô4ä×(Ñ(Ô*¨fØ ˆD× Ñ  Ñ7¨;Ò7ñ Ø—‘¤§¡§¡¨V°[Ó AÔBà×&Ñ&ØØØØ-Ø#Ø#ð 'ó ÷ +×*Ò*ús   Á7ACÃC%)NNFN)NNNFTNN)
rÏ   Ú
__module__Ú__qualname__Ú__doc__r?   r7   ÚPathLikeÚboolrÓ   rß   r.   rB   r2   rÄ   rÄ   ã  sü   „ ñð !Ø%)ØØ $ñ
à˜2Ÿ;™;Ñ&ð
ð ð
ð �T‰zð	
ð
 ˜d™
ð
ð ð
ð ˜‘:ó
ðB &*Ø#Ø ØØ#'Ø"Ø $ñJàðJð ˜d™
ðJð ˜‘ð	Jð
 �T‰zðJð ðJð !ðJð �t‘ðJð ˜‘:ðJð 
ôJrB   rÄ   r•   )NNFFNNNNNNFF)NNFNNNr+   N)NNN)Grš   r7   rj   r4   rÙ   r‰   Úpathlibr   Úuuidr   Úhuggingface_hubr   r   r   r   r	   r
   r   r   Úhuggingface_hub.constantsr   r   Úhuggingface_hub.file_downloadr   Úhuggingface_hub.utilsr   r   r   r   r   r   Ú	packagingr   r+   r   Ú	constantsr   r   r   r   Úimport_utilsr   r   r    r!   r"   r#   r$   r%   Úloggingr&   rÏ   rÐ   Ú__file__Úparentr\   Úhexr6   r<   r?   rA   rä   r¢   r`   re   rn   ru   rŽ   rµ   rÂ   rÄ   r.   rB   r2   Ú<module>rò      s>  ðó" Û 	Û 	Û 
Û Û Ý Ý ÷	÷ 	ó 	÷ OÝ ;÷÷ õ å ÷ó ÷	÷ 	ó 	õ  ñ 
�HÓ	€á ›>×0Ñ0Ð3KÑKÐ Ù‹W�[‰[€
ñ  s¡
¨TÑ 1ð ¸Só ð2  ØØØØ$(ØØØØ $Ø!ØØ#ñWØðWà�‰:ðWð ðWð ð	Wð
 ˜T‘zðWð ðWð �$‰JðWð �4‰ZðWð �‰J˜ÑðWð �d‰{ðWð ðWð ðWð óWñt Ið °S¸4À¹9±_ÀtÑ5Kð ÐW`ó ñ I s¨T¡zð IÀÀdÁ
ó Iñ˜sð ¨S°4©Zð À3ó ð ð
 !Ø Ø ØØ"ØØ$(ØØ"Ø04ò@Ø#&¨¡:ð@ð ð@ð �T‰zð	@ð
 �T‰zð@ð ð@ð �D‰[ð@ð ð@ð �‰:ð@ð �s‘
˜TÑ!ð@ð �D‰jð@ð �t‘ð@ð �s˜I�~Ñ&¨Ñ-ò@ó ð@ðL ØØØ
ØØØØ04ñl.ð �s˜I�~Ñ&¨Ñ-ól.ñ^
H°#ð 
HÈÈcÉð 
HÐdgó 
H÷mò mrB   