o
    2h                     @   sR   d Z ddlZddlZddlZddlmZ dZG dd dejZ	G dd de	Z
dS )	zA LazyLoader class.    N)
tf_logging_tfllc                       sb   e Zd ZdZd fdd	Zdd Zdd Z fd	d
Z fddZdd Z	dd Z
dd Z  ZS )
LazyLoaderzLazily import a module, mainly to avoid pulling in large dependencies.

  `contrib`, and `ffmpeg` are examples of modules that are large and not always
  needed, and this allows them to only be loaded when they are used.
  Nc                    sJ   || _ || _|| _t d|ddd  t dd  t | d S )N
__module__.   r   __wrapped__)_tfll_local_name_tfll_parent_module_globals_tfll_warningsuper__setattr__rsplit__init__)self
local_nameparent_module_globalsnamewarning	__class__ ]/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorflow/python/util/lazy_loader.pyr   "   s   zLazyLoader.__init__c                 C   sB   t | j}|| j| j< | jrt| j d| _| j	|j |S )z8Load the module and insert it into the parent's globals.N)
	importlibimport_module__name__r
   r	   r   loggingr   __dict__updater   moduler   r   r   _load1   s   zLazyLoader._loadc                 C   s   |   }t||S N)r!   getattrr   r   r    r   r   r   __getattr__D   s   
zLazyLoader.__getattr__c                    s   | trt || d S |  }t||| || j|< z|| jvr0|dkr3| j| W d S W d S W d S  t	y?   Y d S w )N__all__)

startswith_TENSORFLOW_LAZY_LOADER_PREFIXr   r   r!   setattrr   r&   appendAttributeError)r   r   valuer    r   r   r   r   H   s   

zLazyLoader.__setattr__c                    sp   | trt | d S |  }t|| | j| z|| jv r+| j	| W d S W d S  t
y7   Y d S w r"   )r'   r(   r   __delattr__r!   delattrr   popr&   remover+   r$   r   r   r   r-   V   s   


zLazyLoader.__delattr__c                 C   s   d| j  d| j dS )Nz<LazyLoader  as >)r   r	   r   r   r   r   __repr__d   s   zLazyLoader.__repr__c                 C   s   |   }t|S r"   )r!   dirr   r   r   r   __dir__i   s   zLazyLoader.__dir__c                 C   s   t j| jffS r"   )r   r   r   r3   r   r   r   
__reduce__m   s   zLazyLoader.__reduce__r"   )r   r   __qualname____doc__r   r!   r%   r   r-   r4   r6   r7   __classcell__r   r   r   r   r      s    r   c                       sL   e Zd ZdZ	dddZ fddZ fdd	Zd
d Z fddZ  Z	S )KerasLazyLoaderz;LazyLoader that handles routing to different Keras version.Nkerasc                 C   s"   || _ || _|| _|| _d| _d S )NF)r
   
_tfll_mode_tfll_submodule
_tfll_name_tfll_initialized)r   r   mode	submoduler   r   r   r   r   t   s
   
zKerasLazyLoader.__init__c                    s   d| _ d}d}tjdddv r1zddl}d}| jdkrd}nd	}W n7 ty0   td
 Y n*w zddl	}|j
drAd}d}nd}| jdkrKd}nd}W n tyY   tdw || _|dury| jdurm|d| j 7 }t | j| j| dS td)z;Resolve the Keras version to use and initialize the loader.TNTF_USE_LEGACY_KERAS)trueTrue1r   tf_kerasv1ztf_keras.api._v1.kerasztf_keras.api._v2.keraszYour environment has TF_USE_LEGACY_KERAS set to True, but you do not have the tf_keras package installed. You must install it in order to use the legacy tf.keras. Install it via: `pip install tf_keras`z3.keras_3zkeras._tf_keras.keraskeras_2zkeras.api._v1.keraszkeras.api._v2.kerasz5Keras cannot be imported. Check that it is installed.r   )r@   osenvirongetrG   r=   ImportErrorr   r   r<   __version__r'   _tfll_keras_versionr>   r   r   r?   r
   )r   package_namekeras_versionrG   r<   r   r   r   _initialize|   sR   



zKerasLazyLoader._initializec                    s   |dv rt tj| |S | js|   | jdkrL| jdkr*| js*|	dr*t
d| jdkr;| js;|	dr;t
d| jrL| j	d	rLt
d
| d|  }t||S )N)r=   r@   r?   rI   rH   z
compat.v1.a  `tf.compat.v1.keras` is not available with Keras 3. Keras 3 has no support for TF 1 APIs. You can install the `tf_keras` package as an alternative, and set the environment variable `TF_USE_LEGACY_KERAS=True` to configure TensorFlow to route `tf.compat.v1.keras` to `tf_keras`.v2z
compat.v2.zT`tf.compat.v2.keras` is not available with Keras 3. Just use `import keras` instead.z__internal__.legacy.`z ` is not available with Keras 3.)r   types
ModuleType__getattribute__r@   rS   rP   r=   r>   r'   r+   r!   r#   )r   itemr    r   r   r   r%      s:   




zKerasLazyLoader.__getattr__c              	   C   s0   | j rd| j d| j d| j d| j d	S dS )Nz<KerasLazyLoader (z) r1   z mode=r2   z<KerasLazyLoader>)r@   rP   r   r	   r=   r3   r   r   r   r4      s   
zKerasLazyLoader.__repr__c                    s   | j s|   t  S r"   )r@   rS   r   r6   r3   r   r   r   r6      s   
zKerasLazyLoader.__dir__)NNr<   )
r   r   r8   r9   r   rS   r%   r4   r6   r:   r   r   r   r   r;   q   s    
5$r;   )r9   r   rK   rV   tensorflow.python.platformr   r   r(   rW   r   r;   r   r   r   r   <module>   s   W