
    +h2Z                        S r 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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  SSKJr  SSKJrJr  SSKJrJr  SS	KJr  S
SKJr  SSKJrJrJ r   \ RB                  " \"5      r#Sr$\%" \RL                  " SS5      5      r'\	RP                  " 5       r)S r*S r+S\\,\RZ                  4   4S jr.S r/S r0S r1S r2S r3S'S jr4S r5\      S(S\\,\RZ                  4   S\,S\\\,\RZ                  4      S\6S \\\,\,4      S!\\\6\,4      S"\\,   S#\64S$ jj5       r7\       S)S\\,\RZ                  4   S\,S%\\,   S\\\,\RZ                  4      S\6S \\\,\,4      S!\\\6\,4      S"\\,   S#\64S& jj5       r8g)*z3Utilities to dynamically load objects from the Hub.    N)Path)
ModuleType)DictOptionalUnion)request)hf_hub_download
model_info)RevisionNotFoundErrorvalidate_hf_hub_args)version   )__version__   )DIFFUSERS_DYNAMIC_MODULE_NAMEHF_MODULES_CACHEloggingz$diffusers/community-pipelines-mirrorDIFFUSERS_TIMEOUT_REMOTE_CODE   c                      Sn [         R                  " [        R                  " U 5      R	                  5       5      S   R                  5       n[        US S9$ )Nz$https://pypi.org/pypi/diffusers/jsonreleasesc                 .    [         R                  " U 5      $ )N)r   Version)xs    _/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/utils/dynamic_modules_utils.py<lambda>(get_diffusers_versions.<locals>.<lambda>2   s    '//!*<    )key)jsonloadsr   urlopenreadkeyssorted)urlr   s     r   get_diffusers_versionsr'   /   sC    
0Czz'//#.3356zBGGIH( <==r   c                     [         [        R                  ;   a  g[        R                  R                  [         5        [        R
                  " [         SS9  [        [         5      S-  n U R                  5       (       d  U R                  5         gg)zW
Creates the cache directory for modules with an init, and adds it to the Python path.
NTexist_ok__init__.py)	r   syspathappendosmakedirsr   existstouch)	init_paths    r   init_hf_modulesr4   5   sa    
 388#HHOO$%KK 40%&6I r   namec                 $   [        5         [        [        5      U -  nUR                  R	                  5       (       d  [        UR                  5        [        R                  " USS9  US-  nUR	                  5       (       d  UR                  5         gg)z>
Creates a dynamic module in the cache directory for modules.
Tr)   r+   N)	r4   r   r   parentr1   create_dynamic_moduler/   r0   r2   )r5   dynamic_module_pathr3   s      r   r8   r8   D   sv     /047%%,,..1889KK#d3#m3I r   c                 *   [        U SSS9 nUR                  5       nSSS5        [        R                  " SW[        R                  S9nU[        R                  " SU[        R                  S9-  n[        [        U5      5      $ ! , (       d  f       Nm= f)z
Get the list of modules that are relatively imported in a module file.

Args:
    module_file (`str` or `os.PathLike`): The module file to inspect.
rutf-8encodingNz^\s*import\s+\.(\S+)\s*$flagsz^\s*from\s+\.(\S+)\s+import)openr#   refindall	MULTILINElistset)module_filefcontentrelative_importss       r   get_relative_importsrK   S   sv     
k3	1Q&&( 
2 zz"=wbll[

#A7RTR^R^__$%&& 
2	1s   B
Bc                    SnU /n/ nU(       d  / nU H  nUR                  [        U5      5        M     [        U 5      R                  nU Vs/ s H  n[	        Xg-  5      PM     nnU Vs/ s H  oUU;  d  M
  UPM     nnU Vs/ s H  oU S3PM	     nn[        U5      S:H  nUR                  U5        U(       d  M  U$ s  snf s  snf s  snf )a  
Get the list of all files that are needed for a given module. Note that this function recurses through the relative
imports (if a imports b and b imports c, it will return module files for b and c).

Args:
    module_file (`str` or `os.PathLike`): The module file to inspect.
F.pyr   )extendrK   r   r7   strlen)	rG   	no_changefiles_to_checkall_relative_importsnew_importsrH   module_pathmnew_import_filess	            r   get_relative_import_filesrX   e   s     I!]N A3A67   ;'..:EF+QC0+F'7Y'7!DX;XA'7Y-=>-=Cs)-=>()Q.	##N3 i   GY>s   B=*	C7CCc                    [        U SSS9 nUR                  5       nSSS5        [        R                  " SW[        R                  S9nU[        R                  " SU[        R                  S9-  nU Vs/ s H.  oDR                  S5      (       a  M  UR                  S5      S	   PM0     nn[        [        U5      5      n/ nU H  n [        R                  " U5        M     [        U5      S	:  a0  [        S
SR                  U5       SSR                  U5       S35      e[        U 5      $ ! , (       d  f       GN= fs  snf ! [         a    UR                  U5         M  f = f)za
Check if the current Python environment contains all the libraries that are imported in a file.
r;   r<   r=   Nz^\s*import\s+(\S+)\s*$r?   z^\s*from\s+(\S+)\s+import.r   z\This modeling file requires the following packages that were not found in your environment: , z. Run `pip install  `)rA   r#   rB   rC   rD   
startswithsplitrE   rF   	importlibimport_moduleImportErrorr.   rP   joinrK   )filenamerH   rI   importsimpmissing_packagess         r   check_importsrh      s<    
hg	.!&&( 
/ jj2G2<<PGrzz6r||TTG,3OGS>>#;N syy~a GGO 3w< G	)##C(  q jyy)*++>sxxHX?Y>ZZ[]
 	

  ))3 
/	. P  	)##C(	)s)   D+4D=D=E+
D:E! E!c                     [        S5      e)NzLoading this model requires you to execute custom code contained in the model repository on your local machine. Please set the option `trust_remote_code=True` to permit loading of this model.)
ValueError)signumframes     r   _raise_timeout_errorrm      s    
	c r   c                    U Gc  U(       a  [         S:  a  S n [        R                  " [        R                  [        5      n[        R                  " [         5        U cD  [        SU SU S35      nUR                  5       S;   a  Sn OUR                  5       S;   a  Sn U c  MD  [        R                  " S5         Ub;  [        R                  " [        R                  U5        [        R                  " S5        OU(       a  [        S S 5        U(       a  U (       d  [        S
U S35      eU $ ! [         a    [        SU SU S	35      ef = f! Ub<  [        R                  " [        R                  U5        [        R                  " S5        f f = f)Nr   zThe repository for z contains custom code which must be executed to correctly load the model. You can inspect the repository content at https://hf.co/z.
You can avoid this prompt in future by passing the argument `trust_remote_code=True`.

Do you wish to run the custom code? [y/N] )yesy1T)non0 FzS.
Please pass the argument `trust_remote_code=True` to allow custom code to be run.zLoading z requires you to execute the configuration file in that repo on your local machine. Make sure you have read the code there to avoid malicious use, then set the option `trust_remote_code=True` to remove this error.)	TIME_OUT_REMOTE_CODEsignalSIGALRMrm   alarminputlower	Exceptionrj   )trust_remote_code
model_namehas_remote_codeprev_sig_handleranswers        r   resolve_trust_remote_coder      s~    3a7#$#)==AU#V 12'/"-j\ :ccmbn oEFF ||~)::,0)+??,1) (/ Q $/MM&..2BCLLO t,0zl #M M
 	
 -   )* 6__i^j khi  $/MM&..2BCLLO 0s   BD+ #D+ +EE AFc                    [         R                  R                  U5      nUR                  S5      (       a  USS nUR	                  [         R                  R
                  S5      n[        [        5      U-  n[           U(       a5  [        R                  R                  US5        [        R                  " 5         [        R                  R                  U5      n[        R                  R!                  X4S9nUc3  [        R                  R#                  U5      nU[        R                  U'   OUnUR$                  R'                  U5        SSS5        U c  [)        W5      $ [+        WU 5      $ ! , (       d  f       N(= f)zQ
Import a module on the cache directory for modules and extract a class from it.
rM   NrZ   )location)r/   r-   normpathendswithreplacesepr   r   _HF_REMOTE_CODE_LOCKr,   modulespopr`   invalidate_cachesgetutilspec_from_file_locationmodule_from_specloaderexec_modulefind_pipeline_classgetattr)
class_namerU   force_reloadr5   rG   cached_modulemodule_specmodules           r   get_class_in_moduler      s    77K(D}}UCRy<<S)D-.<K	KKOOD$''').1kkood.Cnn<<T<X  ^^44[AF &CKK"F&&v. 
" "6**6:&&) 
	s   =CE++
E9c                    SSK Jn  [        [        R                  " U [        R
                  5      5      nSnUR                  5        H}  u  pEXAR                  :w  d  M  [        XQ5      (       d  M(  UR                  R                  S5      S   S:w  d  ML  Ub,  [        SUR                   SUR                   S	U S
U  S3	5      eUnM     U$ )z
Retrieve pipeline class that inherits from `DiffusionPipeline`. Note that there has to be exactly one class
inheriting from `DiffusionPipeline`.
r   )DiffusionPipelineNrZ   r   	diffusersz#Multiple classes that inherit from z have been found: z, and z). Please make sure to define only one in )	pipelinesr   dictinspect
getmembersisclassitems__name__
issubclass
__module__r_   rj   )loaded_moduler   cls_memberspipeline_classcls_nameclss         r   r   r      s    
 .w))-IJKN$**,222322$$S)!,;) 9:K:T:T9U V&//0xj A%a) 
 !N - r   pretrained_model_name_or_pathrG   	cache_dirforce_downloadproxiestokenrevisionlocal_files_onlyc                 X	   [        U 5      n [        R                  R                  X5      n[        R                  R	                  U5      (       a  Un	Sn
GOU R                  S5      S:X  a  [        5       nSSR                  [        R                  " S5      SS 5      -   nUc'  USS U;   a  UOS	n[        R                  S
U S35        O9Xk;   a  SU 3nO.US	:X  a  UnO%[        SU SSR                  US	/-   5       S35      e [        [        SU SU  S3UUUUS9n	Sn
U S-   nON [        U UUUUUUS9n	[        R                  R                  SSR                  U R                  S5      5      5      n
[#        U	5      n[$        [        R                  R&                  -   U
-   n[)        U5        [+        [,        5      U-  nU
S:X  d  U
S:X  a  [.        R0                  " U	UU-  5        U H  n[3        UR                  S5      5      S:X  at  SR                  UR                  S5      5      nUR                  S5      S   n[        R                  R5                  UU-  5      (       d  [        R6                  " UU-  5        U S3n[.        R0                  " [        R                  R                  U U5      UU-  5        M     GO\[9        XUS9R:                  nUU-  nU[        R                  R&                  -   U-   n[)        U5        UU-  R5                  5       (       d  [3        UR                  S5      5      S:X  aT  UR                  S5      S   n[        R                  R5                  UU-  5      (       d  [        R6                  " UU-  5        [.        R0                  " U	UU-  5        U Hn  n[3        UR                  S5      5      S:X  a   SR                  UR                  S5      5      nUU-  R5                  5       (       a  M[  [=        U U S3UUUUUUS9  Mp     [        R                  R                  X5      $ ! [         a  n[        SU S35      UeSnAf[         a    [        R!                  SU SU  S35        e f = f! [         a    [        R!                  SU SU  S35        e f = f)a3	  
Prepares Downloads a module from a local folder or a distant repo and returns its path inside the cached
Transformers module.

Args:
    pretrained_model_name_or_path (`str` or `os.PathLike`):
        This can be either:

        - a string, the *model id* of a pretrained model configuration hosted inside a model repo on
          huggingface.co. Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced
          under a user or organization name, like `dbmdz/bert-base-german-cased`.
        - a path to a *directory* containing a configuration file saved using the
          [`~PreTrainedTokenizer.save_pretrained`] method, e.g., `./my_model_directory/`.

    module_file (`str`):
        The name of the module file containing the class to look for.
    cache_dir (`str` or `os.PathLike`, *optional*):
        Path to a directory in which a downloaded pretrained model configuration should be cached if the standard
        cache should not be used.
    force_download (`bool`, *optional*, defaults to `False`):
        Whether or not to force to (re-)download the configuration files and override the cached versions if they
        exist.
    proxies (`Dict[str, str]`, *optional*):
        A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
        'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
    token (`str` or *bool*, *optional*):
        The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
        when running `transformers-cli login` (stored in `~/.huggingface`).
    revision (`str`, *optional*, defaults to `"main"`):
        The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
        git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
        identifier allowed by git.
    local_files_only (`bool`, *optional*, defaults to `False`):
        If `True`, will only try to load the tokenizer configuration from local files.

<Tip>

You may pass a token in `token` if you are not logged in (`hf auth login`) and want to use private or [gated
models](https://huggingface.co/docs/hub/models-gated#gated-models).

</Tip>

Returns:
    `str`: The path to the module inside the cache.
local/r   vrZ   N   r   mainzDefaulting to latest_version: z`custom_revision`: z3 does not exist. Please make sure to choose one of r[   datasetrM   )repo_id	repo_typerd   r   r   r   r   gitz
Revision 'a  ' not found in the community pipelines mirror. Check available revisions on https://huggingface.co/datasets/diffusers/community-pipelines-mirror/tree/main. If you don't find the revision you are looking for, please open an issue on https://github.com/huggingface/diffusers/issues.zCould not locate the z inside )r   r   r   r   r   z--r   )r   r   r   r   r   r   r   r   )rO   r/   r-   rc   isfilecountr'   r   r_   loggerinforj   r	   COMMUNITY_PIPELINES_MIRROR_IDr   EnvironmentErrorerrorrh   r   r   r8   r   r   shutilcopyfilerP   r1   r0   r
   shaget_cached_module_file)r   rG   r   r   r   r   r   r   module_file_or_urlresolved_module_file	submoduleavailable_versionslatest_versionemodules_neededfull_submodulesubmodule_pathmodule_neededmodule_foldercommit_hashs                       r   r   r     s   r %((E$F!&CQ	ww~~())1		&	,	,S	1Q	635sxx(9(9#(>r(BCC )7);?Q)Q~W]HKK8
!DE+8*~HH%hZ 0II0F8;<=Q@ 
	#25#$:Q'D&ESI#-!1$  I7%?K	#2-#-!1$  Wdii8U8[8[\_8`.abI ##78N 3RWW[[@9LN.)*+n<NGyE1 	,n{.JK+M=&&s+,1 #)<)<S)A B - 3 3C 8 ;ww~~n}&DEEKK >?,oS1MOOBGGLL)FVXfivXvw , !!>Y^_cc (+5'"''++5Cn-,4466;$$S)*a/ + 1 1# 6q 9ww~~n}&DEEKK >?OO0.;2NO ,M=&&s+,1 #)<)<S)A B"]2::<<&1$oS)'#1#%%5		 , 77<<44_ % 	"XJ 'P P 	
   	LL0XFcEddefg	    	LL0XFcEddefg	s%    P9 %AR 9
Q>Q+Q>(R)r   c	                 8    [        U UUUUUUUS9n
[        X*5      $ )a  
Extracts a class from a module file, present in the local folder or repository of a model.

<Tip warning={true}>

Calling this function will execute the code in the module file found locally or downloaded from the Hub. It should
therefore only be called on trusted repos.

</Tip>

Args:
    pretrained_model_name_or_path (`str` or `os.PathLike`):
        This can be either:

        - a string, the *model id* of a pretrained model configuration hosted inside a model repo on
          huggingface.co. Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced
          under a user or organization name, like `dbmdz/bert-base-german-cased`.
        - a path to a *directory* containing a configuration file saved using the
          [`~PreTrainedTokenizer.save_pretrained`] method, e.g., `./my_model_directory/`.

    module_file (`str`):
        The name of the module file containing the class to look for.
    class_name (`str`):
        The name of the class to import in the module.
    cache_dir (`str` or `os.PathLike`, *optional*):
        Path to a directory in which a downloaded pretrained model configuration should be cached if the standard
        cache should not be used.
    force_download (`bool`, *optional*, defaults to `False`):
        Whether or not to force to (re-)download the configuration files and override the cached versions if they
        exist.
    proxies (`Dict[str, str]`, *optional*):
        A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
        'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
    token (`str` or `bool`, *optional*):
        The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
        when running `transformers-cli login` (stored in `~/.huggingface`).
    revision (`str`, *optional*, defaults to `"main"`):
        The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
        git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
        identifier allowed by git.
    local_files_only (`bool`, *optional*, defaults to `False`):
        If `True`, will only try to load the tokenizer configuration from local files.

<Tip>

You may pass a token in `token` if you are not logged in (`hf auth login`) and want to use private or [gated
models](https://huggingface.co/docs/hub/models-gated#gated-models).

</Tip>

Returns:
    `type`: The class, dynamically imported from the module.

Examples:

```python
# Download module `modeling.py` from huggingface.co and cache then extract the class `MyBertModel` from this
# module.
cls = get_class_from_dynamic_module("sgugger/my-bert-model", "modeling.py", "MyBertModel")
```r   )r   r   )r   rG   r   r   r   r   r   r   r   kwargsfinal_modules              r   get_class_from_dynamic_moduler     s4    T *%%)	L z88r   )F)NFNNNF)NNFNNNF)9__doc__r`   r   r    r/   rB   r   rw   r,   	threadingpathlibr   typesr   typingr   r   r   urllibr   huggingface_hubr	   r
   huggingface_hub.utilsr   r   	packagingr   ru   r   r   r   r   
get_loggerr   r   r   intgetenvrv   Lockr   r'   r4   rO   PathLiker8   rK   rX   rh   rm   r   r   r   boolr   r    r   r   <module>r      s^   :    	 	   
    ( (  7 M   F F 
		H	% !G 299%DbIJ  ~~' >c2;;&6 7 '$ :*@)X'B6  48 (,(,""m5#(bkk)9#:m5m5 c2;;./0m5 	m5
 d38n%m5 E$)$%m5 smm5 m5 m5`  !%37 (,(,""S9#(bkk)9#:S9S9 S9 c2;;./0	S9
 S9 d38n%S9 E$)$%S9 smS9 S9 S9r   