
    
3j^                     $   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	J
r
  SSK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  SSKJr  \R<                  " \5      r Sr!\"" \RF                  " SS5      5      r$\RJ                  " 5       r&S r'S r(S\)\RT                  -  4S jr+S r,S r-S r.S r/S)S jr0S r1\         S*S\)\RT                  -  S\)S\)S-  S\)\RT                  -  S-  S\2S \3\)\)4   S-  S!\2\)-  S-  S"\)S-  S#\2S$\)S-  S%\24S& jj5       r4\          S+S\)\RT                  -  S\)S\)S-  S'\)S-  S\)\RT                  -  S-  S\2S \3\)\)4   S-  S!\2\)-  S-  S"\)S-  S#\2S$\)S-  S%\24S( jj5       r5g),z3Utilities to dynamically load objects from the Hub.    N)Path)
ModuleType)request)hf_hub_download
model_info)RevisionNotFoundErrorvalidate_hf_hub_args)version   )__version__   )DIFFUSERS_DYNAMIC_MODULE_NAMEHF_MODULES_CACHElogging)DIFFUSERS_DISABLE_REMOTE_CODEz$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/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/utils/dynamic_modules_utils.py<lambda>(get_diffusers_versions.<locals>.<lambda>1   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_modulesr2   4   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)	r2   r   r   parentr/   create_dynamic_moduler-   r.   r0   )r3   dynamic_module_pathr1   s      r   r6   r6   C   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_importsrI   R   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   )extendrI   r   r5   strlen)	rE   	no_changefiles_to_checkall_relative_importsnew_importsrF   module_pathmnew_import_filess	            r   get_relative_import_filesrV   d   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	:  a:  [        R                  S
SR!                  U5       SSR!                  U5       S35        [#        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.
r9   r:   r;   Nz^\s*import\s+(\S+)\s*$r=   z^\s*from\s+(\S+)\s+import.r   zaThis modeling file might require the following packages that were not found in your environment: , z. Run `pip install  `)r?   r!   r@   rA   rB   
startswithsplitrC   rD   	importlibimport_moduleImportErrorr,   rN   loggerwarningjoinrI   )filenamerF   rG   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 oyy)*++>sxxHX?Y>ZZ[]	

  ))3 
/	. P  	)##C(	)s)   D54EEE5
EE+*E+c                    U =(       a    [         (       + n [         (       a  [        R                  S5        U(       a*  U (       d#  SU S3nU[         (       a  SOS-  n[        U5      eU(       a   U (       a  [        R                  SU S35        U $ )NzDownloading remote code is disabled globally via the DIFFUSERS_DISABLE_REMOTE_CODE environment variable. Ignoring `trust_remote_code`.The repository for z contains custom code. hDownloading remote code is disabled globally via the DIFFUSERS_DISABLE_REMOTE_CODE environment variable.zCPass `trust_remote_code=True` to allow loading remote code modules.z6`trust_remote_code` is enabled. Downloading code from z9. Please ensure you trust the contents of this repository)r   ra   rb   
ValueError)trust_remote_code
model_namehas_remote_code	error_msgs       r   resolve_trust_remote_coderq      s    )O2O.O$$ U	
 0)*5LM	,, wV	
	
 ##	.DZL  QJ  K	
 r   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.
rK   NrX   )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_namerS   force_reloadr3   rE   cached_modulemodule_specmodules           r   get_class_in_moduler      s    77K(D}}UCRy<<S)D-.<K	KKOOD$''')+.;;??4+@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   )DiffusionPipelineNrX   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]   rl   )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_pathrE   	subfolder	cache_dirforce_downloadproxiestokenrevisionlocal_files_only	local_dirrm   c                 
   [        U 5      n [        (       a  [        S5      eUb!  [        R                  R                  XU5      nO[        R                  R                  X5      n[        R                  R                  U5      nU(       + =(       a    U R                  S5      S:H  nU(       a"  UnSnU
(       d  [        SU  SU SU S	35      eGO3U(       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        O:UU;   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U	S9nSnU S-   nOpU
(       d  [        SU  SU SU  SU S	3	5      e [        U UU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  Ga  [0        R2                  " UUU-  5        U H  n[5        UR                  S5      5      S :X  at  SR                  UR                  S5      5      nUR                  S5      S   n[        R                  R7                  UU-  5      (       d  [        R8                  " UU-  5        U S3nUb!  [        R                  R                  XU5      nO [        R                  R                  U U5      n[0        R2                  " UUU-  5        M     GO_[;        XUS!9R<                  nUU-  nU[        R                  R(                  -   U-   n[+        U5        UU-  R7                  5       (       d  [5        UR                  S5      5      S :X  aT  UR                  S5      S   n[        R                  R7                  UU-  5      (       d  [        R8                  " UU-  5        [0        R2                  " UUU-  5        U Hq  n[5        UR                  S5      5      S :X  a   SR                  UR                  S5      5      nUU-  R7                  5       (       a  M[  [?        U U S3UUUUUUUU	U
S"9  Ms     [        R                  R                  UU5      $ ! [         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)#a
  
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.
    trust_remote_code (`bool`, *optional*, defaults to `False`):
        Whether or not to allow for custom pipelines and components defined on the Hub in their own files. This
        option should only be set to `True` for repositories you trust and in which you have read the code, as it
        will execute code present on the Hub on your local machine.

> [!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).

Returns:
    `str`: The path to the module inside the cache.
rk   N/r   localzThe directory z contains custom code in zY which must be executed to correctly load the model. You can inspect the file content at zE.
Pass `trust_remote_code=True` to allow loading remote code modules.vrX      r   mainzDefaulting to latest_version: z`custom_revision`: z3 does not exist. Please make sure to choose one of rY   datasetrK   )repo_id	repo_typerd   r   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 rj   zm which must be executed to correctly load the model. You can inspect the repository content at https://hf.co/z/blob/main/)r   r   r   r   r   r   r   r   z--r   )r   r   	r   r   r   r   r   r   r   r   rm   ) rM   r   rl   r-   r+   rc   isfilecountr%   r   r]   ra   infor   COMMUNITY_PIPELINES_MIRROR_IDr   EnvironmentErrorerrorrh   r   rx   r6   r   r   shutilcopyfilerN   r/   r.   r   shaget_cached_module_file)r   rE   r   r   r   r   r   r   r   r   rm   module_file_or_urlis_local_fileis_community_pipelineresolved_module_file	submoduleavailable_versionslatest_versionemodules_neededfull_submodulesubmodule_pathmodule_neededmodule_foldersource_pathcommit_hashs                             r   r   r      s   x %((E$F!$$v
 	
 WW\\*GT_`WW\\*GUGGNN#56M --_2O2U2UVY2Z^_2_1	  !> ??XYdXe fGGYFZ [VW  ! 
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 !%&C%DD]^i]j k[[xZy  zE  FQ  ER RVW 
	#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$ ggll+HUbc ggll+H-XOOK-)GH , !!>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'&7	 ," 77<<44 % 	"XJ 'P P 	
   	LL0XFcEddefg	2   	LL0XFcEddefg	s%   0!S4 2AT< 4
T9>T+T9<(U$r   c                 >    [        U UUUUUUUU	U
US9n[        X<5      $ )ah  
Extracts a class from a module file, present in the local folder or repository of a model.

> [!WARNING] > 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.

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.
    trust_remote_code (`bool`, *optional*, defaults to `False`):
        Whether or not to allow for custom pipelines and components defined on the Hub in their own files. This
        option should only be set to `True` for repositories you trust and in which you have read the code, as it
        will execute code present on the Hub on your local machine.

> [!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).

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   rE   r   r   r   r   r   r   r   r   r   rm   final_modules                r   get_class_from_dynamic_moduler     s=    P *%%)+L z88r   )F)	NNFNNNFNF)
NNNFNNNFNF)6__doc__r^   r   r   r-   r@   r   r*   	threadingpathlibr   typesr   urllibr   huggingface_hubr   r   huggingface_hub.utilsr   r	   	packagingr
    r   r   r   r   	constantsr   
get_loggerr   ra   r   intgetenvTIME_OUT_REMOTE_CODELockry   r%   r2   rM   PathLiker6   rI   rV   rh   rq   r   r   boolr   r   r    r   r   <module>r      s   :    	 	  
     7 M   F F 4 
		H	% !G 299%DbIJ  ~~' >bkk 1 '$ :*@0'B6  !*. %)#" #R5#&#4R5R5 TzR5 R[[ 4'	R5
 R5 #s(^d"R5 #:R5 DjR5 R5 TzR5 R5 R5j  !!*. %)#" #T9#&#4T9T9 TzT9 d
	T9
 R[[ 4'T9 T9 #s(^d"T9 #:T9 DjT9 T9 TzT9 T9 T9r   