
    
3jd                        S SK r S SKrS SKrS SKrS SKrS SKrS SKJr  S SKJ	r	  S SK
JrJrJrJrJrJrJrJr  S SKJrJr  S SKJr  S SKJrJrJrJrJrJr  S SKJ r   S	S
K!J"r"  SSK#J$r$J%r%J&r&J'r'  SSK(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0  SSK1J2r2  \2" \35      r4\" \55      Rl                  S-  r7\	" 5       Rp                  r9S:S\:\;-  S-  S\;4S jjr<            S;S\;S\;S-  S\=S\=S\;S-  S\;S\;S-  S\;S-  S\>\:   S-  S\=S-  S\=S\=S\4S  jjr?S:S!\S"\;\>\;   -  S-  S\4S# jjr@S:S$\;S-  S%\;S-  4S& jjrAS:S'\;S(\;S-  S\;4S) jjrB\SSSSSSSSSSS*.
S+\;\-  S'\;S,\;S-  S-\;S-  S.\=S/\:S-  S0\=S\;S-  S\:\;-  S-  S1\;S-  S%\;S-  S2\:\;\4   S-  4S3 jj5       rC        S<S2\:\;\4   S-  4S4 jjrDS=S5\;S6\>\;   S(\;4S7 jjrE " S8 S95      rFg)>    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                    S[          S[        R                  R                  5       S    S[         3n[
        (       d  [        (       a  US-   $ [        5       (       a  US[         3-  n[        5       (       a  US[         3-  nUS[         3-  n[        5       (       a  US	[         3-  n[        R                  R!                  S
S5      R#                  5       [$        ;   a  US-  n['        U [(        5      (       a.  USSR+                  S U R-                  5        5       5      -   -  nU$ ['        U [.        5      (       a  USU -   -  nU$ )z>
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   4   #    U  H  u  pU S U 3v   M     g7f)/N ).0kvs      S/home/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/utils/hub_utils.py	<genexpr>"http_user_agent.<locals>.<genexpr>\   s     I6Hda!AaSz6Hs   )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_agentrB   J   s3    k])CKK,=,=,?,B+C=Q[P\	]B>>%%%
())
|n%%
''
3455	zz~~',2248LL
n*d##
dTYYIj6F6F6HIIII I 
J	$	$
dZI    Frepo_id_or_pathtokenis_pipelinefrom_trainingmodel_description
base_modelpromptlicensewidget	inference
is_modularupdate_model_cardc                     [        5       (       d  [        S5      eU(       a  U
(       d  [        S5      e [        R                  " XS9nU(       a'  U
(       a   Ub  UR                  n[        U5      nXl        U$ ! [
        [        4 a    U(       a)  [        R                  " [        USU	UUUS9[        US9n U$ [        5       nU
(       a  Ub  [        U5      nXl         U$ U(       a  SOSnUc  S	U S
3n[        R                  " XS9n U$ f = f)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`).
zModelcard 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`).rE   	diffusers)rK   library_namerM   rI   instance_promptrL   )	card_datatemplate_pathrH   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.)rH   )
r   
ValueErrorr   loaddatar   r   from_templater   MODEL_CARD_TEMPLATE_PATH)rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   
model_cardexisting_datarU   	components                   r2   load_or_create_model_cardra   b   s3   V ?
 	
 pqq e^^OA
0A0M&OOM"#45J+O6 5  78 e"00'#!,')$*! 7"3J.  &I/;&'89
"+  +6J7	$,*UV_U`  at  )u%&44Yd
5es   AA9 9=D9%D!(DDr^   tagsc                 8   U R                   R                  c  SU R                   l        Ubn  [        U[        5      (       a  U/nU R                   R                  c  / U R                   l        U H(  nU R                   R                  R                  U5        M*     U $ )z?Populates the `model_card` with library name and optional tags.rR   )r[   rS   r<   r@   rb   append)r^   rb   tags      r2   populate_model_cardrf      s~    ##+'2
$dC  6D??'#%JOO COO  '',  rC   resolved_filecommit_hashc                     U b  Ub  U$ [        [        U 5      R                  5       5      n [        R                  " SU 5      nUc  gUR                  5       S   n[        R                  " U5      (       a  U$ S$ )zH
Extracts the commit hash from a resolved filename toward a cache file.
Nzsnapshots/([^/]+)/r   )r@   r   as_posixresearchgroupsr   match)rg   rh   rl   s      r2   extract_commit_hashro      sq      7]+4467MYY,m<F~--/!$K+11+>>;HDHrC   weights_namevariantc                 n    Ub1  U R                  S5      nUS S U/-   USS  -   nSR                  U5      n U $ )N.)r6   r>   )rp   rq   splitss      r2   _add_variantrv      sI    ##C(y(6"#;6xx'rC   )
	subfolder	cache_dirforce_downloadproxieslocal_files_onlyrE   r'   revisionrh   dduf_entriespretrained_model_name_or_pathrw   rx   ry   rz   r{   r|   r}   c                   [        U 5      n U(       aO  Ub  [        S5      eU S:X  a  UOSR                  X/5      nX;   a  U$ [        SU SUR	                  5        S35      e[
        R                  R                  U 5      (       a  U $ [
        R                  R                  U 5      (       a  [
        R                  R                  [
        R                  R                  X5      5      (       a!  [
        R                  R                  X5      nU$ Ubd  [
        R                  R                  [
        R                  R                  XU5      5      (       a"  [
        R                  R                  XU5      nU$ [        SU SU  S35      eU	[        ;   a  U[        :X  d
  U[        :X  a  [        R                  " [        R                  " [        5      R                  5      [        R                  " S5      :  aU   [!        U [#        X5      UUUUUUUU	=(       d    U
S	9
n[$        R&                  " S
U	 SU  SU	 SU	 SU	 SU	 S3[(        5        U$  [!        U UUUUUUUUU	=(       d    U
S	9
nU$ !   [$        R&                  " SU	 SU  SU	 SU	 SU  S[#        X5       SU  SU  S[#        X5       S3[(        5         Nk= f! [*         a  n[        U  S35      UeS nAf[,         a  n[        U	 SU  S35      UeS nAf[.         a  n[        U  SU S35      UeS nAf[0         a  n[        SU  SU 35      UeS nAf[         a  n[        S[2         S U  S!U S"35      UeS nAf[         a  n[        S#U  S$U  S%U 35      UeS nAff = f)&NzDDUF 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 rs   z found in directory z0.22.0)	filenamerx   ry   rz   r{   rE   r'   rw   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@   rY   r>   EnvironmentErrorkeysr8   pathisfileisdirr   r   r   r   parser   base_versionr	   rv   warningswarnFutureWarningr   r   r   r   r   )r~   rp   rw   rx   ry   rz   r{   rE   r'   r|   rh   r}   
model_filees                 r2   _get_model_filer      s     %((E$F! 2  -2 8GH 	
 %"%9,GYZfZkZkZmYnno#pqq	5	6	6,,	4	5	577>>"'',,'DSTT&CRJ"rww~~GGLL6<P(
 (
 &CP\]J"&|n4HIfHgghi  00-AY1YgmmK8EEF'--X`Jaa,1),A'#1#%5)'%4
 *8*F;X:YYijris  t{  |D  {E  En  ow  nx  xq  rz  q{  {F  G! "!2	(-%#-!1%#!0[J '28*FC`Baaqrzq{  |Z  [c  Zd  dI  Jg  Ih  hC  DP  Q]  Dh  Ci  iG  He  Gf  fC	  D	a	  C	b	  b	n	  o	{	  |	H
  o	S
  n	T
  T
D  E!( ' 	"01 2d d 	
 % 	"* ++H*IIce 	
 " 	"011WXdWeefg  	"LMjLkknopnqr  	"*+J*K L::W9X Y66B^ Dff    	",-J,K L))F(G H++7.:
 	sb   6AI( J8 (AJ58
M<KM<K00M<=LM<L..M<;MM<"M77M<c
                   ^ U	(       a  X;  a  [        SU SU  S35      eO6[        R                  R                  U5      (       d  [        SU SU  S35      eU	(       a'  [        R
                  " X   R                  5       5      n
O9[        US5       n[        R
                  " UR                  5       5      n
SSS5        [        [        W
S   R                  5       5      5      nU
S   n[        U
S   R                  5       5      US'   U
S   R                  5       US'   [        R                  R                  X5      n[        R                  R!                  U 5      (       d  U	(       a  U Vs/ s H"  n[        R                  R                  X5      PM$     nnU HX  mU	(       a  TU	;  a  [#        U S	T S
35      eM#  [        R                  R%                  T5      (       a  MI  [#        U S	T S
35      e   X4$ UnUb0  U Vs/ s H#  n[        R                  R                  UU5      PM%     nnSS/nU(       dJ  ['        XUS9nU H:  m[)        U4S jUR*                   5       5      nU(       a  M+  [-        U S	T S
35      e    [/        U UUUUUUUUS9	nUb   [        R                  R                  UU5      nU Vs/ s H#  n[        R                  R                  UU5      PM%     nnU H8  n[        R                  R                  U5      (       a  M)  [-        U SU S
35      e   UU4$ ! , (       d  f       GNy= fs  snf s  snf ! [0         a  n[-        S[2         SU  S35      UeSnAff = fs  snf )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 rs   rN
weight_mapmetadataall_checkpoint_keysr   z5 which is required according to the checkpoint index.z*.jsonz*.md)r|   rE   c              3   B   >#    U  H  nTUR                   ;   v   M     g 7fN)	rfilename)r/   r0   
shard_files     r2   r3   ._get_checkpoint_shard_files.<locals>.<genexpr>  s     $bHa1Z1;;%>Has   )rx   rz   r{   rE   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 )rY   r8   r   r   jsonloads	read_textopenreadsortedsetvalueslistr   copyr>   r   FileNotFoundErrorexistsr
   anysiblingsr   r   r   r   )r~   index_filenamerx   rz   r{   rE   r'   r|   rw   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   , ->~>NeTqSrrstuu . ww~~n-->~>NeTqSrrstuu

<7AACD.#&!JJqvvx(E '  &c%*=*D*D*F&GHZ(.253F3K3K3M.N*+%*<%8%=%=%?\"'',,<HK 
ww}}233|AYZAYA277<<7AYZ)J\1+&-'Mj\ ZF F  2 ww~~j11+&-'Mj\ ZF F  * 00 .N>LMn"'',,y!4nM(O %&C^cd2J!$$bHXHaHa$b!b%%&"m#I* VB B  3))-)+!

  GGLL	BM AYY@X1]A6@XY'ww~~k**" /!=k]J  A  ( ---Y '& [& NB  &'F&GzRoQp q> >
 	 Zs6   %L(+)L: *L?4M :*M-(
L7
M*M%%M*folder	filenamesc                 ^  ^ U(       a  U (       a  [        S5      eU(       dY  / n[        R                  " U 5       H=  u    p4U H1  nUR                  [        R                  R                  U5      5        M3     M?     Sn[        R                  " SU SU S35      m[        U4S jU 5       5      $ )Nz1Both `filenames` and `folder` cannot be provided.z\d{5}-of-\d{5}z.*-z\.z	\.[a-z]+$c              3   J   >#    U  H  nTR                  U5      S Lv   M     g 7fr   )rn   )r/   r   variant_file_res     r2   r3   8_check_legacy_sharding_variant_format.<locals>.<genexpr>  s!     GY$$Q't3Ys    #)	rY   r8   walkrd   r   basenamerk   compiler   )r   r   rq   _filesfiletransformers_index_formatr   s          @r2   %_check_legacy_sharding_variant_formatr     s    VLMM	776?KAq  !1!1$!78  + !2jjC(A'B"WIY!WXOGYGGGrC   c                       \ rS rSrSr    SS\\R                  -  S\S\S-  S\S-  S\S	\S-  4S
 jjr	       SS\S\S-  S\S-  S\S-  S\S\S\S-  S	\S-  S\4S jjr
Srg)PushToHubMixini  zJ
A Mixin to push a model, scheduler, or pipeline to the Hugging Face Hub.
Nworking_dirrepo_idrE   commit_message	create_prrw   c           	         UcS  SU R                   R                  ;   a  SnO6SU R                   R                  ;   a  SnOSU R                   R                   3n[        R                  SU SU S35        [	        UUUUUUS	9$ )
z2
Uploads all files in `working_dir` to `repo_id`.
ModelzUpload model	SchedulerzUpload schedulerzUpload zUploading the files of z to rs   )r   folder_pathrE   r   r   path_in_repo)	__class____name__loggerinfor   )selfr   r   rE   r   r   rw   s          r2   _upload_folderPushToHubMixin._upload_folder  s     !$..111!/ 7 77!3#*4>>+B+B*C!D-k]$wiqIJ#)"
 	
rC   privatesafe_serializationrq   r(   c	           
         [        XUSS9R                  nU(       d  [        XS9n	[        U	5      n	SU0n
SU R                  R
                  ;  a  U
R                  SU05        [        R                  " 5        nU R                  " U40 U
D6  U(       d/  W	R                  [        R                  R                  US5      5        U R                  UUUUUUS9sS	S	S	5        $ ! , (       d  f       g	= f)
u  
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   rE   exist_okrQ   r   r   rq   z	README.md)rE   r   r   rw   N)r   r   ra   rf   r   r   updatetempfileTemporaryDirectorysave_pretrainedsaver8   r   r>   r   )r   r   r   r   rE   r   r   rq   rw   r^   save_kwargstmpdirs               r2   push_to_hubPushToHubMixin.push_to_hub  s    ` gedS[[ 27HJ,Z8J ,-?@dnn555	734((*f  7;7 V[ AB&&-## '  +**s   7AC
C,r.   )NNFN)NNNFTNN)r   
__module____qualname____firstlineno____doc__r@   r8   PathLikeboolr   r   __static_attributes__r.   rC   r2   r   r     s    !%) $
2;;&
 
 Tz	

 d

 
 :
B &*# #'" $JJ d
J 	J
 TzJ J !J tJ :J 
J JrC   r   r   )NNFFNNNNNNFF)NNFNNNr+   N)NNN)Gr   r8   rk   r5   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]   hexr7   r=   r@   rB   r   r   ra   rf   ro   rv   r   r   r   r   r.   rC   r2   <module>r      s>  "  	 	 
    	 	 	 O ;    	 	 	   
H	>003KK W[[
s
T 1 S 2  $( $!#WW:W W 	W
 TzW W $JW 4ZW JW d{W W W WtI S49_t5K W`  IsTz Id
 Is S4Z 3  
 !  "$("04@#&:@ @ Tz	@
 Tz@ @ D[@ @ :@ s
T!@ Dj@ t@ sI~&-@ @L 
04l. sI~&-l.^
H# 
Hc 
Hdg 
Hm mrC   