
    +h_                        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	J
r
Jr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"  S S	K#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/J0r0J1r1J2r2J3r3J4r4J5r5J6r6  SSK7J8r8  \8" \95      r:\" \;5      Rx                  S-  r=\" 5       R|                  r?S:S\\	\@S4   S\@4S jjrA          S;S\@S\\@   S\BS\BS\\@   S\@S\\@   S\\@   S\\
\C      S\\B   S\4S  jjrDS:S!\S"\\@\
\@   4   S\4S# jjrES:S$\\@   S%\\@   4S& jjrFS:S'\@S(\\@   S\@4S) jjrG\"SSSSSSSSSSS*.
S+\\@\4   S'\@S,\\@   S-\\@   S.\BS/\\	   S0\BS\\@   S\\\	\@4      S1\\@   S%\\@   S2\\	\@\4      4S3 jj5       rH        S<S2\\	\@\4      4S4 jjrIS=S5\@S6\
\@   S(\@4S7 jjrJ " S8 S95      rKg)>    N)Path)DictListOptionalUnion)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RepositoryNotFoundErrorRevisionNotFoundErroris_jinja_availablevalidate_hf_hub_args)version)	HTTPError   )__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/james-whalen/.local/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     r6   http_user_agentrF   K   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	inferencec
                 V   [        5       (       d  [        S5      e [        R                  " XS9n
U
$ ! [        [
        4 af    U(       a)  [        R                  " [        USU	UUUS9[        US9n
 U
$ [        5       nU(       a  SOSnUc  SU S	3n[        R                  " XS
9n
 U
$ f = f)a4  
Loads or creates a model card.

Args:
    repo_id_or_path (`str`):
        The repo id (e.g., "runwayml/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.
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`.rI   	diffusers)rO   library_namerQ   rM   instance_promptrP   )	card_datatemplate_pathrL   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.)rL   )	r   
ValueErrorr
   loadr   r   from_templater   MODEL_CARD_TEMPLATE_PATH)rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   
model_cardrW   	components                r6   load_or_create_model_cardra   c   s    F ?
 	
a^^OA
. -  78 a"00'#!,')$*! 7"3J&  &I&1
wI (&QR[Q\  ]p  %q!"00`J-as   2 =B(22B('B(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.rT   )datarU   r@   rD   rb   append)r_   rb   tags      r6   populate_model_cardrg      s~    ##+'2
$dC  6D??'#%JOO COO  '',  rG   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   )rD   r   as_posixresearchgroupsr   match)rh   ri   rm   s      r6   extract_commit_hashrp      sq      7]+4467MYY,m<F~--/!$K+11+>>;HDHrG   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.)r:   rB   )rq   rr   splitss      r6   _add_variantrw      sI    ##C(y(6"#;6xx'rG   )
	subfolder	cache_dirforce_downloadproxieslocal_files_onlyrI   r+   revisionri   dduf_entriespretrained_model_name_or_pathrx   ry   rz   r{   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/   r1   zError no file named z found in archive rt   z found in directory z0.22.0)	filenamery   rz   r{   r|   rI   r+   rx   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 )rD   r[   rB   EnvironmentErrorkeysr<   pathisfileisdirr   r!   r    r   parser   base_versionr   rw   warningswarnFutureWarningr   r   r   r   r   )r   rq   rx   ry   rz   r{   r|   rI   r+   r}   ri   r~   
model_filees                 r6   _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 rt   rN
weight_mapmetadataall_checkpoint_keysr   z5 which is required according to the checkpoint index.z*.jsonz*.md)r}   rI   c              3   B   >#    U  H  nTUR                   ;   v   M     g 7fN)	rfilename)r3   r4   
shard_files     r6   r7   ._get_checkpoint_shard_files.<locals>.<genexpr>  s     $bHa1Z1;;%>Has   )ry   r{   r|   rI   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 )r[   r<   r   r   jsonloads	read_textopenreadsortedsetvalueslistr   copyrB   r   FileNotFoundErrorexistsr   anysiblingsr   r   r   r   )r   index_filenamery   r{   r|   rI   r+   r}   rx   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                            @r6   _get_checkpoint_shard_filesr   T  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   )ro   )r3   r   variant_file_res     r6   r7   8_check_legacy_sharding_variant_format.<locals>.<genexpr>  s!     GY$$Q't3Ys    #)	r[   r<   walkre   r   basenamerl   compiler   )r   r   rr   _filesfiletransformers_index_formatr   s          @r6   %_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GrG   c                       \ rS rSrSr    SS\\\R                  4   S\S\	\   S\	\   S\
S	\	\   4S
 jjr       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_idrI   commit_message	create_prrx   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 rt   )r   folder_pathrI   r   r   path_in_repo)	__class____name__loggerinfor   )selfr   r   rI   r   r   rx   s          r6   _upload_folderPushToHubMixin._upload_folder  s     !$..111!/ 7 77!3#*4>>+B+B*C!D-k]$wiqIJ#)"
 	
rG   privatesafe_serializationrr   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   rI   exist_okrS   r   r   rr   z	README.md)rI   r   r   rx   N)r   r   ra   rg   r   r   updatetempfileTemporaryDirectorysave_pretrainedsaver<   r   rB   r   )r   r   r   r   rI   r   r   rr   rx   r_   save_kwargstmpdirs               r6   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,r2   )NNFN)NNNFTNN)r   
__module____qualname____firstlineno____doc__r   rD   r<   PathLiker   boolr   r   __static_attributes__r2   rG   r6   r   r     s     $(,#'
3+,
 
 }	

 !
 
 C=
B )-"&##'!%#'JJ !J $	J
 }J J !J #J C=J 
J JrG   r   r   )
NNFFNNNNNN)NNFNNNr/   N)NNN)Lr   r<   rl   r9   r   r   pathlibr   typingr   r   r   r   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   	packagingr   requestsr   r/   r   	constantsr   r   r    r!   import_utilsr"   r#   r$   r%   r&   r'   r(   r)   loggingr*   r   r   __file__parentr^   hexr;   rD   rF   r   rA   ra   rg   rp   rw   r   r   r   r   r2   rG   r6   <module>r      s7  "  	 	 
    . . 	 	 	 O ;     	 	 	   
H	>003KK W[[
dCo 6 # 2  '+ !#' $CCC=C C 	C
  }C C SMC c]C T$Z C ~C CLI U3S	>5J V_  Ix} I8C= Is Xc] c  
  $# ""-1"!%37@#(d#3@ @ }	@
 }@ @ d^@ @ C=@ tSy)*@ sm@ #@ 4Y/0@ @L 
37l. 4Y/0l.^
H# 
Hc 
Hdg 
Hm mrG   