
     `i1                        d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlmZ ddlmZ ddlmZmZmZ ddlmZ ddlmZ dd	lmZmZmZmZm Z m!Z! dd
l"m#Z#m$Z$  e!j%        e&          Z'de(de(fdZ) ej*                    Z+d Z,dee(ej-        f         ddfdZ.dee(ej-        f         de/e(         fdZ0dee(ej-        f         de/e(         fdZ1dee(ej-        f         de/e(         fdZ2dee(ej-        f         de/e(         fdZ3ddde(dee(ej-        f         de4de5fdZ6	 	 	 	 	 	 	 	 	 d3dee(ej-        f         de(deee(ej-        f                  de4dee4         d ee7e(e(f                  d!eee4e(f                  d"ee(         d#e4d$ee(         d%ee(         de(fd&Z8	 	 	 	 	 	 	 	 	 d3d'e(dee(ej-        f         deee(ej-        f                  de4dee4         d ee7e(e(f                  d!eee4e(f                  d"ee(         d#e4d$ee(         d(ee(         de5fd)Z9d4d*ed+ee(ej-        f         d,ee7         de/e(         fd-Z:d. Z;d/Z<	 d5d0Z=d6d2Z>dS )7z3Utilities to dynamically load objects from the Hub.    N)Path)
ModuleType)AnyOptionalUnion)try_to_load_from_cache)version   )HF_MODULES_CACHE TRANSFORMERS_DYNAMIC_MODULE_NAMEcached_fileextract_commit_hashis_offline_modelogging)VersionComparisonsplit_package_versionnamereturnc                 r   |                      dd                               dd          }|r|d                                         rd| }t          j        |          r"t                              d| d|  d	           n5|                                s!t                              d| d|  d
           |S )a  
    Tries to sanitize a module name so that it can be used as a Python module.

    The following transformations are applied:

    1. Replace `.` in module names with `_dot_`.
    2. Replace `-` in module names with `_hyphen_`.
    3. If the module name starts with a digit, prepend it with `_`.
    4. Warn if the sanitized name is a Python reserved keyword or not a valid identifier.

    If the input name is already a valid identifier, it is returned unchanged.
    ._dot_-_hyphen_r   _zThe module name z (originally z\) is a reserved keyword in Python. Please rename the original module to avoid import issues.z]) is not a valid Python identifier. Please rename the original module to avoid import issues.)replaceisdigitkeyword	iskeywordloggerwarningisidentifier)r   new_names     u/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/transformers/dynamic_module_utils.py_sanitize_module_namer$   3   s   " ||C))11#zBBH "HQK'')) "!x>>"" 	
Hx H Hd H H H	
 	
 	
 	
 ""$$ 
Hx H Hd H H H	
 	
 	
 O    c                  V   t           t          j        v rdS t          j                            t                      t	          j        t           d           t          t                     dz  } |                                 s)|                                  t          j
                     dS dS )z_
    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	importlibinvalidate_caches)	init_paths    r#   init_hf_modulesr4   W   s    
 38##HOO$%%%K 40000%&&6I &#%%%%%& &r%   c                 ~   t                       t          t                    | z                                  }|j                                        st          |j                   t          j        |d           |dz  }|                                s)|	                                 t          j                     dS dS )z
    Creates a dynamic module in the cache directory for modules.

    Args:
        name (`str` or `os.PathLike`):
            The name of the dynamic module to create.
    Tr'   r)   N)r4   r   r   resolveparentr/   create_dynamic_moduler-   r.   r0   r1   r2   )r   dynamic_module_pathr3   s      r#   r8   r8   g   s      011D8AACC%,,.. :18999K#d3333#m3I & 	#%%%%%	& &r%   module_filec                 >   t          | d          5 }|                                }ddd           n# 1 swxY w Y   t          j        d|t          j                  }|t          j        d|t          j                  z  }t          t          |                    S )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.

    Returns:
        `list[str]`: The list of relative imports in the module.
    utf-8encodingNz^\s*import\s+\.(\S+)\s*$)flagsz^\s*from\s+\.(\S+)\s+import)openreadrefindall	MULTILINElistset)r:   fcontentrelative_importss       r#   get_relative_importsrJ   }   s     
kG	,	,	, &&((               z"=wbl[[[
#A7RTR^____$%%&&&s   377c                 "   d}| g}g |sg }|D ]$}|                     t          |                     %t          |           j        fd|D             }fd|D             }t	          |          dk    }                     |           |S )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.

    Returns:
        `list[str]`: The list of all relative imports a given module needs (recursively), which will give us the list
        of module files a given module needs.
    Fc                 :    g | ]}t          |z             d S ).py)str).0mmodule_paths     r#   
<listcomp>z-get_relative_import_files.<locals>.<listcomp>   s.    NNNQs;?33888NNNr%   c                     g | ]}|v|	S  rT   )rO   rG   all_relative_importss     r#   rR   z-get_relative_import_files.<locals>.<listcomp>   s$    WWWBV9V9V!9V9V9Vr%   r   )extendrJ   r   r7   len)r:   	no_changefiles_to_checknew_importsrG   new_import_filesrU   rQ   s         @@r#   get_relative_import_filesr\      s     I!]N  
4 	8 	8A3A667777;''.NNNN+NNNWWWW%5WWW''1,	##N333  
4  r%   filenamec                    t          | d          5 }|                                }ddd           n# 1 swxY w Y   t                      ddlfdt	          j        |          } |           t                    S )a  
    Extracts all the libraries (not relative imports this time) that are imported in a file.

    Args:
        filename (`str` or `os.PathLike`): The module file to inspect.

    Returns:
        `list[str]`: The list of all packages required to use the input module.
    r<   r=   Nr   c                 b   t          | t          j                  rd S t          | t          j                  r| j        }t          j        |          D ]y}t          |t          j                  r]t          |j        dd          }|	                    d          r|
                    d          st          	j        j        |          r d S znt          | t          j                  rB| j        D ]9}|j                            d          d         }|r                    |           :nct          | t          j                  rI| j        dk    r>| j        r7| j                            d          d         }|r                    |           t          j        |           D ]} |           d S )Nid 	availableis_flash_attnr   r   )
isinstanceastTryIftestwalkCallgetattrfuncendswith
startswithhasattrutilsimport_utilsImportnamesr   splitadd
ImportFromlevelmoduleiter_child_nodes)
noderh   condition_nodecheck_functionalias
top_modulechildimported_modulesrecursive_look_for_importstransformerss
          r#   r   z/get_imports.<locals>.recursive_look_for_imports   s   dCG$$ 	5Fcf%% 	59D"%(4.. 
 
nch77 	%,^-@$%K%KN&//<<*55oFF #<#5#BNSS 
 cj)) 	5 5 5"Z--c2215
 5$((4445 cn-- 	5zQ4;![..s33A6
 5$((444 )$// 	. 	.E&&u----	. 	.r%   )r@   rA   rF   transformers.utilsre   parsesorted)r]   rG   rH   treer   r   r   s       @@@r#   get_importsr      s     
h	)	)	) Q&&((              uu. . . . . . .B 9WDt$$$"###s   6::c                    t          |           }g }|D ]v}	 t          j        |           # t          $ rR}t                              d| d|            dt          |          v r|                    |           n Y d}~od}~ww xY wt          |          dk    r<t          dd	                    |           dd		                    |           d
          t          |           S )a.  
    Check if the current Python environment contains all the libraries that are imported in a file. Will raise if a
    library is missing.

    Args:
        filename (`str` or `os.PathLike`): The module file to check.

    Returns:
        `list[str]`: The list of relative imports in the file.
    z&Encountered exception while importing z: zNo module namedNr   z\This modeling file requires the following packages that were not found in your environment: z, z. Run `pip install  `)r   r1   import_moduleImportErrorr   r    rN   r,   rW   joinrJ   )r]   importsmissing_packagesimp	exceptions        r#   check_importsr      s;    (##G  
	#C(((( 	 	 	NNVCVV9VVWWW !C	NN22 '',,,, -,,,,	 q  ]yy)**] ]?BxxHX?Y?Y] ] ]
 
 	

  )))s   ,
BABBFforce_reload
class_namerQ   r   c          
         t           j                            |          }|                    d          }|                    t           j        j        d          }t          t                    |z  }t          5  |r3t          j
                            |d           t          j                     t          j
                            |          }t          j                            ||          }|gt#          t%          t          t'          |                              z   }t)          j        d                    d |D                                                                 }|/t          j                            |          }	|	t          j
        |<   n|}	t3          |	dd          |k    r!|j                            |	           ||	_        t3          |	|           cddd           S # 1 swxY w Y   dS )	a  
    Import a module on the cache directory for modules and extract a class from it.

    Args:
        class_name (`str`): The name of the class to import.
        module_path (`str` or `os.PathLike`): The path to the module to import.
        force_reload (`bool`, *optional*, defaults to `False`):
            Whether to reload the dynamic module from file if it already exists in `sys.modules`.
            Otherwise, the module is only reloaded if the file has changed.

    Returns:
        `typing.Type`: The class looked for.
    rM   r   N)locationr%   c              3   ^   K   | ](}t          |          |                                z   V  )d S N)bytes
read_bytesrO   rG   s     r#   	<genexpr>z&get_class_in_module.<locals>.<genexpr>,  s6      2c2cQR588allnn3L2c2c2c2c2c2cr%   __transformers_module_hash__ra   )r-   r+   normpathremovesuffixr   sepr   r   _HF_REMOTE_CODE_LOCKr*   modulespopr1   r2   getutilspec_from_file_locationr   mapr\   hashlibsha256r   	hexdigestmodule_from_specrk   loaderexec_moduler   )
r   rQ   r   r   r:   cached_modulemodule_specmodule_filesmodule_hashrx   s
             r#   get_class_in_moduler     s   & 7K((DU##D<<S))D-..<K	 + + 	*KOOD$''''))).1kood.C.Cn<<TK<XX %0=6#dD]^iDjDj:k:k3l3l#l">#((2c2cVb2c2c2c*c*cddnnpp  ^44[AAF &CK"F692>>+MM**62222=F/vz**-+ + + + + + + + + + + + + + + + + +s   8E$G))G-0G-pretrained_model_name_or_path	cache_dirforce_downloadresume_downloadproxiestokenrevisionlocal_files_only	repo_type_commit_hashc                 	   |                     dd          }|-t          j        dt                     |t	          d          |}t                      r|st                              d           d}t          |           } t          j
                            |           }|r-t          t          j
                            |                     }n^t          j
        j                            t!          t          |                     d                              }t%          | |||
|	          }g }	 t'          | |||||||||	|
	          }|s||k    r|                    |           n0# t*          $ r# t                              d
| d|  d            w xY wt-          |          }t.          t          j
        j        z   |z   }t1          |           t3          t4                    |z  }|t          t          j
                            |                     k    r.||z                                  r%t9          j        |t          ||z                      sJ||z  j                            dd           tA          j!        |||z             tE          j#                     |D ]}t3          |          j        | dz  }t          j
                            | |          }||z                                  r%t9          j        |t          ||z                      s+tA          j!        |||z             tE          j#                     ntI          ||
          }||z  }|t          j
        j        z   |z   }t          j
                            ||          }t1          t3          |          j                   ||z                                  s+tA          j!        |||z             tE          j#                     |D ]m}||z  j        | dz                                  sItK          | t3          |          j        |z   d||||||||
  
         |                    | d           ntM          |          dk    rR|Pd                    d |D                       }|	dn|	 d}d| |  }t          '                    d| d| d           t          j
                            ||          S )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.
            - 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.
        resume_download:
            Deprecated and ignored. All downloads are now resumed by default when possible.
            Will be removed in v5 of Transformers.
        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 `hf auth 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.
        repo_type (`str`, *optional*):
            Specify the repo type (useful when downloading from a space for instance).

    <Tip>

    Passing `token=True` is required when you want to use a private model.

    </Tip>

    Returns:
        `str`: The path to the module inside the cache.
    use_auth_tokenNrThe `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.V`token` and `use_auth_token` are both specified. Please set only the argument `token`.z+Offline mode: forcing local_files_only=TrueT/)r   r   r   )	r   r   r   r   r   r   r   r   r   zCould not locate the z inside r   )parentsr(   rM   )r   r   r   r   r   r   r   r   r   
c                     g | ]}d | S )z- rT   r   s     r#   rR   z*get_cached_module_file.<locals>.<listcomp>  s    ;;;AxAxx;;;r%   ra   zs/zhttps://huggingface.co/z9A new version of the following files was downloaded from z:
z
. Make sure to double-check they do not contain any added malicious code. To avoid downloading new versions of the code file, you can pin a revision.)(r   warningswarnFutureWarning
ValueErrorr   r   inforN   r-   r+   isdirr$   basenamer   r   r   rt   r   r   r,   OSErrorr   r   r8   r   r   r/   filecmpcmpr7   mkdirshutilcopyr1   r2   r   get_cached_module_filerW   r    )r   r:   r   r   r   r   r   r   r   r   r   deprecated_kwargsr   is_local	submoduler   	new_filesresolved_module_filemodules_neededfull_submodulesubmodule_pathmodule_neededmodule_needed_filecommit_hashfull_submodule_module_file_pathrepo_type_strurls                              r#   r   r   <  s   | '**+;TBBN! A	
 	
 	
 uvvv  !1  ABBB %((E$F$F!w}}:;;H 
)"'*:*:;X*Y*YZZ		GK$$S)>@]@c@cdg@h@h%i%ijj	.);)Vbnw
 
 
 I*))+-% 
  
  
  	*M-AAA[)))   aKaaA^aaabbb
 ##788N 6CiON.)))*++n<N)"'*:*:;X*Y*YZZZZ ,4466 	*gk #n{&B"C"C?
 ?
 	* k)177t7TTTK,n{.JKKK')))+ 	. 	.M --4-7L7L7LLM!#.K]![!["]2::<< .GK"C(F$G$GE E . .0NOOO+---	. **>MM (+5'"'+5C*,',,~{*S*S'd#BCCJKKK,4466 	*K,n{.JKKK')))+ 	8 	8M#k19}<Q<Q<QQYY[[ 8&1K((/-?DDD'#1$3#%%5!,      M!6!6!6777
9~~h.II;;;;;<<	'/	5E5E5EVV7TVVA A APY A A A	
 	
 	
 7<<444s   07E( (-Fclass_referencecode_revisionc                 j   |                     dd          }|-t          j        dt                     |t	          d          |}d| v r|                     d          \  }} n|}|                     d          \  }}|
||k    r|}
t          ||dz   ||||||
||	
  
        }t          |||	          S )
a6  
    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:
        class_reference (`str`):
            The full name of the class to load, including its module and optionally its repo.
        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.
            - a path to a *directory* containing a configuration file saved using the
              [`~PreTrainedTokenizer.save_pretrained`] method, e.g., `./my_model_directory/`.

            This is used when `class_reference` does not specify another repo.
        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.
        resume_download:
            Deprecated and ignored. All downloads are now resumed by default when possible.
            Will be removed in v5 of Transformers.
        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 `hf auth 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.
        repo_type (`str`, *optional*):
            Specify the repo type (useful when downloading from a space for instance).
        code_revision (`str`, *optional*, defaults to `"main"`):
            The specific revision to use for the code on the Hub, if the code leaves in a different repository than the
            rest of the model. 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.

    <Tip>

    Passing `token=True` is required when you want to use a private model.

    </Tip>

    Returns:
        `typing.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("modeling.MyBertModel", "sgugger/my-bert-model")

    # Download module `modeling.py` from a given repo and cache then extract the class `MyBertModel` from this
    # module.
    cls = get_class_from_dynamic_module("sgugger/my-bert-model--modeling.MyBertModel", "sgugger/another-bert-model")
    ```r   Nr   r   z--r   rM   )r   r   r   r   r   r   r   r   r   )r   r   r   r   r   rt   r   r   )r   r   r   r   r   r   r   r   r   r   r   kwargsr   repo_idr:   r   final_modules                    r#   get_class_from_dynamic_moduler     s    t ZZ 0$77N! A	
 	
 	
 uvvv #2#8#8#>#> /-33C88K!>'!I!I )e%')  L z<nUUUUr%   objfolderconfigc                 z     j         dk    r#t                              d  d| d           dS  fd}t          |t          t
          f          r|D ]} ||           n| ||           g }t          j         j                  j        }t          |          t          |          j
        z  }t          j        ||           |                    |           t          |          D ]P}t          |          t          |          j
        z  }t          j        ||           |                    |           Q|S )a  
    Save the modeling files corresponding to a custom model/configuration/tokenizer etc. in a given folder. Optionally
    adds the proper fields in a config.

    Args:
        obj (`Any`): The object for which to save the module files.
        folder (`str` or `os.PathLike`): The folder where to save.
        config (`PretrainedConfig` or dictionary, `optional`):
            A config in which to register the auto_map corresponding to this custom object.

    Returns:
        `list[str]`: The list of files saved.
    __main__z We can't save the code defining z in z as it's been defined in __main__. You should put this code in a separate module so we can include it in the saved folder and make it easier to share via the Hub.Nc                    
j         j        }|                    d          d         }| d
j         j         }d|v rd }d }
j         j                            d          ra| d
j         j         }t          
dd           >t          
d          }|j        }|                    d          d         }| d|j         }n| d
j         j         }||f}t          | t                    r'|                     di           }	||	
j	        <   |	| d<   d S t          | dd           || j
        
j	        <   d S 
j	        |i| _
        d S )Nr   	TokenizerFastslow_tokenizer_classauto_map)	__class__
__module__rt   __name__rm   rk   rd   dictr   _auto_classr   )_configmodule_namelast_module	full_namer   fast_tokenizer_classslow_tokenizerslow_tok_module_namelast_slow_tok_moduler   r   s             r#   _set_auto_map_in_configz3custom_object_save.<locals>._set_auto_map_in_config  s   m.!'',,R0"==S]%;==	)###' #' }%..v66 
Q*5'P'P8N'P'P$3 6==I%,S2H%I%IN+9+D(+?+E+Ec+J+J2+N(.B+^+^^E\+^+^( +6'P'P8N'P'P$-/CDIgt$$ 	<{{:r22H(1HS_%"*GJWj$//;09GS_--- #;Gr%   )r   r   r    rd   rE   tupler*   r   __file__r   r   r   r   r,   r\   )	r   r   r   r  cfgresultobject_file	dest_fileneeded_files	   `        r#   custom_object_saver	  k  sw    ~##s     	
 	
 	

 	< < < < <@ &4-(( ( 	) 	)C##C((((	)		'''F+cn-6KV[ 1 1 67I
KY'''
MM) 1== ! !LLD$5$5$:;	K+++i    Mr%   c                      t          d          )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.)r   )signumframes     r#   _raise_timeout_errorr    s    
	c  r%      c                    |^|d| d| d| d}nOt           j                            |          r'd| dt           j                            |           d}n	d| d| d}| [|rd} nU|r@t          d	k    r4d}	 t          j        t
          j        t                    }t          j        t                     | Ht          | d
| d          }|
                                dv rd} n|
                                dv rd} | Ht          j        d	           n## t          $ r t          | d
| d          w xY w	 |3t          j        t
          j        |           t          j        d	           nM# |4t          j        t
          j        |           t          j        d	           w w xY w|rt          dd           |r|s| st          | d
| d          | S )a  
    Resolves the `trust_remote_code` argument. If there is remote code to be loaded, the user must opt-in to loading
    it.

    Args:
        trust_remote_code (`bool` or `None`):
            User-defined `trust_remote_code` value.
        model_name (`str`):
            The name of the model repository in huggingface.co.
        has_local_code (`bool`):
            Whether the model has local code.
        has_remote_code (`bool`):
            Whether the model has remote code.
        error_message (`str`, *optional*):
            Custom error message to display if there is remote code to load and the user didn't opt-in. If unset, the error
            message will be regarding loading a model with custom code.

    Returns:
        The resolved `trust_remote_code` value.
    NzThe repository z% references custom code contained in zm which must be executed to correctly load the model. You can inspect the repository content at https://hf.co/z .
zt contains custom code which must be executed to correctly load the model. You can inspect the repository content at z contains custom code which must be executed to correctly load the model. You can inspect the repository content at https://hf.co/Fr   z9 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0ra   zS.
Please pass the argument `trust_remote_code=True` to allow custom code to be run.)r-   r+   r   abspathTIME_OUT_REMOTE_CODEsignalSIGALRMr  alarminputlower	Exceptionr   )trust_remote_code
model_namehas_local_codehas_remote_codeerror_messageupstream_repoprev_sig_handleranswers           r#   resolve_trust_remote_coder&    s   . $@* @ @S` @ @,9@ @ @ M
 W]]:&& 	@* @ @ gooj99@ @ @ M=* = =,6= = =    	- % 	-!5!9!9#$#)=AU#V#V 1222'/"( F Fcm F F F F
 ||~~):::,0))+???,1) (/ Q    $ i i_i i i i     $/M&.2BCCCLOOO $/M&.2BCCCLOOOO 0  	- t,,, 
~ 
6G 
 a aWa a a a
 
 	

 s   <BD E2  D88E2 28F*requirements.txtc                 J   g }	 t          d| |d|}t          |d          5 }|                                }ddd           n# 1 swxY w Y   |D ]}|                                }|r|                    d          r/	 t          |          \  }}}	n# t          $ r
 |}d\  }}	Y nw xY w	 t          j        	                    |          }
n2# t          j        j
        $ r |                    | d           Y w xY w|E|	C t          j        |          t          j        |
          t          j        |	                    }nd}|s|                    | d|
 d	           n# t          $ r Y nw xY w|r)t!          d
|  dd                    |          z             dS )a  
    Tries to locate `requirements_file` in a local folder or repo, and confirms that the environment has all the
    python dependencies installed.

    Args:
        path_or_repo_id (`str` or `os.PathLike`):
            This can be either:
            - a string, the *model id* of a model repo on huggingface.co.
            - a path to a *directory* potentially containing the file.
        kwargs (`dict[str, Any]`, *optional*):
            Additional arguments to pass to `cached_file`.
    )path_or_repo_idr]   rN#NNz (installed: None)Tz (installed: )z4Missing requirements in your local environment for `z`:
r   rT   )r   r@   	readlinesstriprn   r   r   r1   metadatar	   PackageNotFoundErrorr,   r   from_stringr   r   r   r   )r)  requirements_filer   failedrequirementsrG   requirementpackage_name	delimiterversion_numberlocal_package_versionis_satisfieds               r#   check_python_requirementsr<    ss    F""i?M^iibhii,$$ 	);;==L	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) ( 	U 	UK%++--K +"8"8"="= 7:OP[:\:\7i 7 7 7*,6)	>>>7(1(:(B(B<(P(P%%%:   @@@AAA $)CG0<YGGM"788'-:W:W     $ USS;PSSSTTT5	U8      
X?XXX[_[d[dek[l[ll
 
 	

 
s|   E( AE( AE( A4E( BE( B)&E( (B))E( -CE( ,C<9E( ;C<<A+E( (
E54E5)	NFNNNNFNNr   r,  )r'  )?__doc__re   r   r   r1   importlib.metadataimportlib.utilr   r-   rB   r   r  r*   	threadingr   pathlibr   typesr   typingr   r   r   huggingface_hubr   	packagingr	   rp   r   r   r   r   r   r   utils.import_utilsr   r   
get_loggerr   r   rN   r$   Lockr   r4   PathLiker8   rE   rJ   r\   r   r   booltyper   r   r   r   r	  r  r  r&  r<  rT   r%   r#   <module>rL     s   : 9 



                				 				   



                  ' ' ' ' ' ' ' ' ' ' 2 2 2 2 2 2                      I H H H H H H H 
	H	%	%     B &y~'' & & & &c2;&6 7 &D & & & &,'eC,<&= '$s) ' ' ' '* 5bk1A+B  tCy        @4$%R[ 01 4$d3i 4$ 4$ 4$ 4$n *E#r{"23  *S	  *  *  *  *N 	-+ -+ -+-+sBK'(-+ 	-+
 
-+ -+ -+ -+f 48 &*(,(,""#"&o5 o5#(bk)9#:o5o5 c2;./0o5 	o5
 d^o5 d38n%o5 E$)$%o5 smo5 o5 }o5 3-o5 	o5 o5 o5 o5j 48 &*(,(,""##'zV zVzV#(bk)9#:zV c2;./0zV 	zV
 d^zV d38n%zV E$)$%zV smzV zV }zV C=zV 
zV zV zV zVzI IC IsBK/?)@ I(SW. Idhildm I I I IX     gkR R R Rj5
 5
 5
 5
 5
 5
r%   