
    RЦiR                        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	  S SK
JrJrJrJrJrJrJr  S SKrS SKJrJrJr   S SKJr   S SKrS	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&  S SK'J(r(J)r)  \" \%S\ S9r%S	r*\RV                  " \,5      r-/ SQr.Sr/Sr0Sr1Sr2SMS\34S jjr4   SNS\\3\\3   \\3\34   4   S\5S\5S\\\3\4      4S jjr6  SOS\\3\\3   \\3\34   4   S\5S\\\3\4      4S jjr7SPS\54S  jjr8S!\34S" jr9S#\\3\4   4S$ jr: SQS%\3S&\3S\\\3\4      4S' jjr;S(\\3\4   S)\\3\4   S*\\\3\4   \3\\3\4   4   4S+ jr< SQS%\3S\\\3\4      4S, jjr=S-\\3\4   4S. jr>\/S
S4S%\3S&\3S/\5S\\\3\4      4S0 jjr?S1r@S2rA SPS3\3S/\54S4 jjrB SQS%\3S&\3S5\R                  R                  S\\\3\4      4S6 jjrE  SRS5\R                  R                  S7\3S8\\F   S9\\F   4S: jjrG   SSS5\R                  R                  S;\3S8\\F   S9\\F   S<\\5\S=   4   4
S> jjrH          STS5\R                  R                  S?\3S@\3SA\\3   SB\\3   SC\5SD\5S8\\F   SE\\F   S9\\F   SF\3S<\\5\S=   4   4SG jjrI SUSE\FSH\3SF\34SI jjrJS&\3S*\\3   4SJ jrKS%\\3   SK\\3   S*\\3   4SL jrLg! \ a
    S SKJr   GNkf = f! \ a    S
r GNsf = f! \ a
    S SKJr   GNf = f! \ a    Sr%S
r* GNgf = f)V    N)partial)Path)TemporaryDirectory)AnyDictIterableListOptionalTupleUnion)
HASH_REGEXdownload_url_to_fileurlparse)get_dir)_get_torch_homeTF)Literal)__version__)filter_pretrained_cfg)HfApihf_hub_download
model_info)EntryNotFoundErrorRepositoryNotFoundErrortimm)library_namelibrary_version)get_cache_dirdownload_cached_file
has_hf_hubhf_splitload_model_config_from_hfload_state_dict_from_hfsave_for_hfpush_to_hf_hubpytorch_model.binmodel.safetensorsopen_clip_pytorch_model.binopen_clip_model.safetensors	child_dirc                     [         R                  " S5      (       a  [        R                  S5        [	        5       nU (       d  SOU 4n [         R
                  R                  " US/U Q76 n[         R                  " USS9  U$ )z^
Returns the location of the directory where models are cached (and creates it if necessary).
TORCH_MODEL_ZOOz@TORCH_MODEL_ZOO is deprecated, please use env TORCH_HOME instead checkpointsTexist_ok)osgetenv_loggerwarningr   pathjoinmakedirs)r)   hub_dir	model_dirs      O/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/timm/models/_hub.pyr   r   5   s`    
 
yy"##Z[iG#)IWm@i@IKK	D)    url
check_hashprogress	cache_dirc                 P   [        U [        [        45      (       a  U u  pO4[        U 5      n[        R
                  R                  UR
                  5      nU(       a  [        R                  " USS9  O
[        5       n[        R
                  R                  X45      n[        R
                  R                  U5      (       dg  [        R                  SR                  X5      5        S nU(       a0  [        R                  " U5      nU(       a  UR!                  S5      OS n[#        XXrS9  U$ )NTr.   zDownloading: "{}" to {}
   )r=   )
isinstancelisttupler   r0   r4   basenamer6   r   r5   existsr2   infoformatr   searchgroupr   )	r;   r<   r=   r>   filenamepartscached_filehash_prefixrs	            r9   r   r   D   s     #e}%%X77##EJJ/
I-!O	'',,y3K77>>+&&077IJ!!(+A()!''!*tKS{Nr:   c                    [        U [        [        45      (       a  U u  pO4[        U 5      n[        R
                  R                  UR
                  5      nU(       d
  [        5       n[        R
                  R                  X#5      n[        R
                  R                  U5      (       a  U(       a  [        R                  " U5      nU(       a  UR                  S5      OS nU(       ae  [        US5       n[        R                  " UR!                  5       5      R#                  5       n	U	S [%        U5       U:w  a
   S S S 5        g S S S 5        ggg! , (       d  f       g= f)Nr@   rbFT)rA   rB   rC   r   r0   r4   rD   r   r5   rE   r   rH   rI   openhashlibsha256read	hexdigestlen)
r;   r<   r>   rJ   rK   rL   rN   rM   fhds
             r9   check_cached_filerY   ^   s    
 #e}%%X77##EJJ/!O	'',,y3K	ww~~k""!!(+A()!''!*tK+t, 1;;=B+3{+,;$ -,; -  -, s   3AE
E	necessaryc                 H    [         (       d  U (       a  [        S5      e[         $ )Nz^Hugging Face hub model specified but package not installed. Run `pip install huggingface_hub`.)_has_hf_hubRuntimeError)rZ   s    r9   r   r   x   s!    ;9ln 	nr:   hf_idc                     U R                  S5      nS[        U5      s=:  a  S::  d   S5       e   S5       eUS   n[        U5      S:  a  US   OS nX#4$ )N@r      zChf_hub id should only contain one @ character to identify revision.r@   )splitrV   )r^   	rev_splithf_model_idhf_revisions       r9   r    r       sa    C Is9~""i$ii"i$ii"A,K#&y>A#5)B-4K##r:   	json_filec                     [        U SSS9 nUR                  5       nS S S 5        [        R                  " W5      $ ! , (       d  f       N$= f)NrN   zutf-8)encoding)rQ   rT   jsonloads)rg   readertexts      r9   load_cfg_from_jsonrn      s8    	iw	/6{{} 
0::d 
0	/s	   ;
A	model_idrJ   c                 4    [        U 5      u  p4[        UUUUS9$ )N)revisionr>   )r    r   )ro   rJ   r>   re   rf   s        r9   download_from_hfrr      s*    
  (1K	 r:   cfgextra_fieldsreturnc                 v   SU ;  aA  U nUR                  S5      UR                  SS5      US.n SU;   a  UR                  S5      US'   U S   nUR                  U5        SU ;   a  U S   US'   SU ;   a  U R                  S5      US'   S	U ;   a  U R                  S	5      US	'   U R                  S
0 5      nU S   nX$U4$ ) pretrained_cfgarchitecturenum_featuresN)ry   rz   rx   labelslabel_namesnum_classeslabel_descriptions
model_args)popupdateget)rs   rt   rx   r   
model_names        r9   _parse_model_cfgr      s     s"*..~>*..~tD,

 ~%,:,>,>x,HN=))*N,' (+M(:}%(+(>}%s"/2ww7K/L+,r*J^$Jz11r:   c                 n    [        S5      (       d   e[        U SUS9n[        U5      n[        X0SS.5      $ )u>   Original HF‑Hub loader (unchanged download, shared parsing).Tconfig.json)r>   zhf-hub)	hf_hub_idsource)r   rr   rn   r   )ro   r>   cfg_pathrs   s       r9   r!   r!      s=    
 d-9MH
X
&CC8!LMMr:   
model_pathc                     [        U 5      n U S-  nUR                  5       (       d  [        SU 35      e[        U5      n[	        U 5      SS.n[        X#S9$ )z?Load from ``<model_path>/config.json`` on the local filesystem.r   zConfig file not found: z	local-dir)filer   )rt   )r   is_fileFileNotFoundErrorrn   strr   )r   cfg_filers   rt   s       r9   load_model_config_from_pathr      s]     j!JM)H"9( DEE
X
&C
O{CLC;;r:   weights_onlyc           
         [        S5      (       d   e[        U 5      u  pE[        (       a\  [        U5       HM  n [	        UUUUS9n[
        R                  SU  SU SU S35        [        R                  R                  USS9s  $    [	        UUUUS	9n[
        R                  SU  S
U S35         [        R                  " USUS9n	U	$ ! [         a     M  f = f! [         a    [        R                  " USS9n	 U	$ f = f)NT)repo_idrJ   rq   r>   [z"] Safe alternative available for 'z' (as 'z&'). Loading weights using safetensors.cpu)devicerJ   rq   r>   z"] Safe alternative not found for 'z)'. Loading weights using default pytorch.map_locationr   r   )r   r    _has_safetensors_get_safe_alternativesr   r2   rF   safetensorstorch	load_filer   debugload	TypeError)
ro   rJ   r   r>   re   rf   safe_filenamecached_safe_filerL   
state_dicts
             r9   r"   r"      s8    d'1K 3H=M#2'*('	$  z!CH: N)?*PRS #((223CE2RR >  "	K MMAhZA(KtuvAZZ%l[
  &   AZZ%@
As$   AC0C 
CCC<;C<)r&   r%   zpytorch_model.pthz	model.pthr(   z#open_clip_pytorch_model.safetensorsr'   zopen_clip_pytorch_model.pth).safetensorsz.pthz.pth.tar.binr4   c                 @   S n[          HC  nX-  nUR                  5       (       d  M  [        R                  " SUR                   35        Un  O   [
         Hq  n[        U R                  SU 35      5      nU(       d  M)  [        U5      S:  a4  [        R                  " SU SU  S[         SUS   R                   S	3	5        US   nMs     U(       d  [        S
U  S35      e [        R                  " USUS9nU$ ! [         a    [        R                  " USS9n U$ f = f)NzFound preferred checkpoint: *r@   z	Multiple z checkpoints in : z	. Using 'r   z'.z!No suitable checkpoints found in .r   r   r   )_PREFERRED_FILESrE   loggingrF   name_EXT_PRIORITYsortedglobrV   r3   namesr]   r   r   r   )r4   r   
found_filefnamepextfilesr   s           r9   load_state_dict_from_pathr   
  s"    J!L88::LL7x@AJ " tyy1SE+,55zA~u$4TF"UG D#Ahmm_B0 qJ  >tfAFGG@ZZ
\Z
   @ZZ
?
@s   "C: :DDmodelc                 z    [        S5      (       d   e[        U 5      u  pE[        UUUUS9nUR                  U5      $ )NTr   )r   r    r   load_pretrained)ro   rJ   r   r>   re   rf   rL   s          r9   load_custom_from_hfr   +  sK     d'1K!	K   --r:   config_pathmodel_configr   c                    U=(       d    0 n0 n[        U R                  SSS9nUR                  S5      US'   UR                  SU R                  5      US'   UR                  SU R                  5      US'   UR                  S[        U SS 5      5      n[        U[        5      (       a  U(       a  XdS'   SU;   a6  [        R                  S5        UR                  S	UR                  S5      5        UR                  S	S 5      nU(       a&  [        U[        [        [        45      (       d   eXtS	'   UR                  S
S 5      nU(       a  [        U[        5      (       d   eXS
'   U(       a  X4S'   XTS'   UR                  U5        UR                  S5       n	[         R"                  " XISS9  S S S 5        g ! , (       d  f       g = f)NT)remove_sourceremove_nullry   r}   rz   global_poolr{   z'labels' as a config field for is deprecated. Please use 'label_names' and 'label_descriptions'. Renaming provided 'labels' field to 'label_names'.r|   r~   r   rx   wra   )indent)r   rx   r   r}   rz   getattrrA   r   r2   r3   
setdefaultdictrB   rC   r   rQ   rj   dump)
r   r   r   r   	hf_configrx   global_pool_typer|   r~   rW   s
             r9   save_config_for_hfr   <  s     %2LI*5+?+?taefN . 2 2> BIn+//u?P?PQIm !- 0 0ASAS TIn#''wumUY7Z["C((-=#3-  <B	C 	|/?/?/IJ""=$7K+dE':;;;; $/- %))*>E,d3333*<&'",,"0\"			#	!		)q) 
		s   F11
F?save_directorysafe_serializationbothc                 v   [        S5      (       d   e[        U5      nUR                  SSS9  U R                  5       nUSL d  US:X  a8  [        (       d   S5       e[
        R                  R                  XQ[        -  5        USL d  US:X  a  [        R                  " XQ[        -  5        US-  n[        U UUUS9  g )NT)r/   parentsr   z-`pip install safetensors` to use .safetensorsFr   )r   r   )r   r   mkdirr   r   r   r   	save_fileHF_SAFE_WEIGHTS_NAMEsaveHF_WEIGHTS_NAMEr   )r   r   r   r   r   tensorsr   s          r9   r#   r#   m  s     d.)N$5  GT!%76%AP!PP##G>R-RSU"&8F&B

7_<= =0K!	r:   r   commit_messagetokenrq   private	create_pr
model_card	task_namec           	         [        US[        S9nUR                  XSS9nUR                  nUR	                  USUS9n[        5        n[        U UUU	US9  U(       dI  U=(       d    0 nUR                  S5      S	   n[        U5      S-  n[        UUU
S
9nUR                  U5        UR                  UUUUUS9sSSS5        $ ! , (       d  f       g= f)a  
Arguments:
    (...)
    safe_serialization (`bool` or `"both"`, *optional*, defaults to `False`):
        Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
        Can be set to `"both"` in order to push both safe and unsafe weights.
r   )r   r   r   T)r   r/   z	README.md)r   rJ   rq   )r   r   r   /rb   )r   )r   folder_pathrq   r   r   N)r   r   create_repor   file_existsr   r#   rc   r   generate_readme
write_textupload_folder)r   r   r   r   rq   r   r   r   r   r   r   r   apirepo_url
has_readmetmpdirr   readme_pathreadme_texts                      r9   r$   r$     s    * e&+
NC w$GH G ;QYZJ 
	%!1	
 #)rJ s+B/Jv,4K)*jIVK"";/   ) ! 
' 
		s   A0C
Cr   c                    U R                  SS 5      =(       d    USS/nSnU(       a  US-  nU H  nUSU S3-  nM     USU S3-  nUS	U R                  S
S5       S3-  nUSU R                  SS5       S3-  nSU ;   a  USU R                  S5       S3-  nSU ;   a  USU R                  S5       S3-  nSU ;   a  SU S   ;   a  US-  n[        U S   S   [        [        45      (       a'  U S   S    H  nUSUR	                  5        S3-  nM     OUSU S   S   R	                  5        S3-  nSU S   ;   ae  [        U S   S   [        [        45      (       a'  U S   S    H  nUSUR	                  5        S3-  nM     OUSU S   S   R	                  5        S3-  nUS-  nUSU S3-  nSU ;   a  USU S    S3-  nSU ;   a  US-  nU S   R                  5        H  u  px[        U[        [        45      (       a  USU S3-  nU H  n	USU	 S3-  nM     M=  [        U[        5      (       a0  USU S3-  nUR                  5        H  u  pUSU
 SU	 S3-  nM     M  USU SU S3-  nM     SU ;   a  US-  nX@S   -  nUS-  nS U ;   a  US!-  nX@S    -  nUS-  nS"U ;   aA  US#-  n[        U S"   [        [        45      (       d  U S"   /nOU S"   nU H  nUS$U S%3-  nM     U$ )&Ntagsr   transformersz---
ztags:
z- 
zpipeline_tag: zlibrary_name: r   z	license: licensez
apache-2.0license_namezlicense_name: license_linkzlicense_link: detailsDatasetz
datasets:
zPretrain Datasetz# Model card for descriptionz
## Model Details
z- **z:**
z  - r   z:** usagez
## Model Usage

comparisonz
## Model Comparison
citationz
## Citation
z
```bibtex
z
```
)r   rA   rC   rB   loweritemsr   )r   r   r   r   r   tdkvviki	citationscs                r9   r   r     s   
 >>&$'NIv~+NDKy ARs":%K ^I;b11K^JNN>6$J#K2NNKYz~~iFGrJJK#
~(F'GrJJ#
~(F'GrJJJ9
90E#E}$j+I6FF	*95AGGI;b11 6 R
9 5i @ F F HILLKI!66*Y/0BCeT]SS#I./ABAR	{"#55K C Jy$9:L$M$S$S$U#VVXYY7K&zl"55K
"J}56b99J-.y)//1DA!dE]++aS.BT"R=0K At$$aS.ggiFBT"Rt2#66K ( aSQCr22 2 *+,'**tz!01,//tZ)*Z04-@@#J/0I":.IA[733K r:   c              #      #    U [         :X  a  [        v   U [        :X  a  [        v   U [         [        4;  a"  U R	                  S5      (       a  U SS S-   v   ggg7f)a9  Returns potential safetensors alternatives for a given filename.

Use case:
    When downloading a model from the Huggingface Hub, we first look if a .safetensors file exists and if yes, we use it.
    Main use case is filename "pytorch_model.bin" => check for "model.safetensors" or "pytorch_model.safetensors".
r   Nr   )r   r   HF_OPEN_CLIP_WEIGHTS_NAMEHF_OPEN_CLIP_SAFE_WEIGHTS_NAMEendswith)rJ   s    r9   r   r     s^      ?""",,,,)BCCHYHYZ`HaHasmn,, IbCs   AAr   c                    [        S5      (       d  Sn[        R                  US9  gU (       a  U(       d  gX-   n [        US9nUR                  (       a)  UR                  R                  S
5      R                  5       OSnUS:X  a!  UR                  R                  SS5      nUb  U$ U$ ! [         a    SU S3n[        R                  US9   g[
         a#  nSU S	3n[        R                  US9   SnAgSnAff = f)a  Retrieve license information for a model from Hugging Face Hub.

Fetches the license field from the model card metadata on Hugging Face Hub
for the specified model. Returns None if the model is not found, if
huggingface_hub is not installed, or if the model is marked as "untrained".

Args:
    model_id: The model identifier/name. In the case of None we assume an untrained model.
    hf_hub_id: The Hugging Face Hub organization/user ID. If it is None,
        we will return None as we cannot infer the license terms.

Returns:
    The license string in lowercase if found, None otherwise.

Note:
    Requires huggingface_hub package to be installed. Will log a warning
    and return None if the package is not available.
TzBFor updated license information run `pip install huggingface_hub`.)msgN)r   zRepository z4 was not found. Manual inspection of license needed.z
Error for z&. Manual inspection of license needed.r   otherr   )	r   r2   r3   r   r   	Exception	card_datar   r   )ro   r   r	  r   rF   _r   r   s           r9   _get_license_from_hf_hubr    s    & dRC 'G'* 8<~~dnn  +1134G'~~!!.$7KN% # G9$XYC  7)#IJC s   	B) )#C:	C:C55C:)rw   )TFN)TN)F)N)NN)NNF)
z	Add modelNNFFNNNimage-classificationr   )r  )MrR   rj   r   r0   	functoolsr   pathlibr   tempfiler   typingr   r   r   r	   r
   r   r   r   	torch.hubr   r   r   r   ImportErrorr   safetensors.torchr   r   r   typing_extensionsr   r   timm.models._pretrainedr   huggingface_hubr   r   r   huggingface_hub.utilsr   r   r\   	getLogger__name__r2   __all__r   r   r  r  r   r   boolr   rY   r   r    rn   rr   r   r!   r   r"   r   r   r   nnModuler   r   r   r#   r$   r   r   r  r,   r:   r9   <module>r!     s       	   ' D D D  @ @5!*  9BBQoFT_`OK
 

H
%G &* 9 !> S "  04	3S	5c?23  E#t),-	8  043S	5c?23 E#t),-4$ $C $%T	"2  15 E#t),-2#s(^238n2 4S>3S#X./2D 15NNE#t),-N
<#t)$
< ("04	&&& & E#t),-	&R	  = #J 15	... xx. E#t),-	.( (,%)	.*xx.*.* tn.* TN	.*h (,%);@xx tn TN	
 "$"78> *#"&'+%)%)/;A:
xx:
:
 :
 }	:

 3-:
 :
 :
 tn:
 TN:
 TN:
 :
 "$"78:
@ 0BBB BJ-S -Xc] -2x} 2# 2S[\_S` 2W  5445  
  *))*  OKsH   J& J9 K %K &J65J69KKKK
K)(K)