
    HThvL              "          S SK J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  S SKJrJr  S SKJrJrJr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$  \!RJ                  " \&5      r'Sr(\" 5       (       a   S SK)r(S\$S\$4S jr-S/S jr.S r/S r0  S0S\	S\1S\\2   4S jjr3\-    S1S\\4\	4   S\\\4\4      S\1S\1S\\\5\44      4
S jj5       r6S2S jr7\"\-SS SSSSSSSSSSSSS!.S"\4S\\2   S#\4S$\\1   S%\\4   S&\\4   S'\\4   S(\\1   S)\\\\4   \44      S*\\\\4   \44      S+\\\\4   \44      S,\\4   S\1S\\\5\44      S\14S- jj5       5       r8 " S. S\5      r9g! \* a    S SK+r,\,RP                  r( Nf = f)3    Nwraps)Path)copytree)AnyDictListOptionalUnion)ModelHubMixinsnapshot_download)get_tf_versionis_graphviz_availableis_pydot_availableis_tf_available	yaml_dump   )	constants)HfApi)SoftTemporaryDirectoryloggingvalidate_hf_hub_args)	CallableTfnreturnc                 0   ^  [        T 5      U 4S j5       nU$ )Nc                 p   > [        U S5      (       d  [        STR                   S35      eT" U /UQ70 UD6$ )NhistoryzCannot use 'z}': Keras 3.x is not supported. Please save models manually and upload them using `upload_folder` or `huggingface-cli upload`.)hasattrNotImplementedError__name__)modelargskwargsr   s      S/var/www/auris/envauris/lib/python3.13/site-packages/huggingface_hub/keras_mixin.py_inner'_requires_keras_2_model.<locals>._inner+   sK    ui((%r{{m ,r r  %)$)&))    r   )r   r&   s   ` r%   _requires_keras_2_modelr)   )   s     
2Y* * Mr(   c                 &   / nU R                  5        Hq  u  p4U(       a  U SU 3OUn[        U[        R                  5      (       a+  UR	                  [        UU5      R                  5       5        M_  UR                  XT45        Ms     [        U5      $ )a\  Flatten a nested dictionary.
Reference: https://stackoverflow.com/a/6027615/10319735

Args:
    dictionary (`dict`):
        The nested dictionary to be flattened.
    parent_key (`str`):
        The parent key to be prefixed to the children keys.
        Necessary for recursing over the nested dictionary.

Returns:
    The flattened dictionary.
.)items
isinstancecollectionsMutableMappingextend_flatten_dictappenddict)
dictionary
parent_keyr,   keyvaluenew_keys         r%   r1   r1   7   s     E &&(
+5ZL#'3e[7788LL %'	 LL')* ) ;r(   c                    SnU R                   bw  U R                   R                  5       n[        U5      n[        R                  R                  5       R                  US'   SnUR                  5        H  u  p4USU SU S3-  nM     U$ )z6Parse hyperparameter dictionary into a markdown table.Ntraining_precisionz*| Hyperparameters | Value |
| :-- | :-- |
z| z | z |
)	optimizer
get_configr1   kerasmixed_precisionglobal_policynamer,   )r"   tableoptimizer_paramsr6   r7   s        r%   _create_hyperparameter_tablerC   T   s    E" ??557()9:161F1F1T1T1V1[1[-.>*002JCr#c%--E 3Lr(   c                 T    [         R                  R                  U U S3SSSSSSS S9	  g )N
/model.pngFTTB`   )to_fileshow_shapes
show_dtypeshow_layer_namesrankdirexpand_nesteddpilayer_range)r=   utils
plot_model)r"   save_directorys     r%   _plot_networkrS   b   s<    	KK!"*-  
r(   Trepo_dirrQ   metadatac                    US-  nUR                  5       (       a  g[        U 5      nU(       a)  [        5       (       a  [        5       (       a  [	        X5        Uc  0 nSUS'   SnU[        USS9-  nUS-  nUS-  nUS	-  nUS
-  nUb  US-  nUS-  nUS-  nXe-  nUS-  nU(       aF  [        R                  R                  U S35      (       a  US-  nUS-  nUS-  nSnUSU S3-  nUS-  nUR                  U5        g)zX
Creates a model card for the repository.

Do not overwrite an existing README.md file.
z	README.mdNr=   library_namez---
F)default_flow_stylez/
## Model description

More information needed
z9
## Intended uses & limitations

More information needed
z:
## Training and evaluation data

More information needed
z
## Training procedure
z
### Training hyperparameters
z;
The following hyperparameters were used during training:


rE   z
 ## Model Plot
z

<details>z$
<summary>View Model Plot</summary>
z./model.pngz
![Model Image](z)
z
</details>)	existsrC   r   r   rS   r   ospath
write_text)r"   rT   rQ   rU   readme_pathhyperparameters
model_cardpath_to_plots           r%   _create_model_cardrb   p   sC    [(K259O+--2D2F2Fe&&H^J)H??J'JGGJQQJRRJ"11
88
VV
%
d
bggnnz%<==**
m#
>>
$),s;;
n$
:&r(   FrR   configinclude_optimizertagsc                 t   [         c  [        S5      eU R                  (       d  [        S5      e[	        U5      nUR                  SSS9  U(       an  [        U[        5      (       d  [        S[        U5       S35      eU[        R                  -  R                  S5       n[        R                  " X'5        SSS5        0 n[        U[        5      (       a  XXS	'   O[        U[         5      (       a  U/US	'   UR#                  S
S5      n	U	b<  [$        R&                  " S[(        5        S	U;   a  US	   R+                  U	5        OU	/US	'   U R,                  b  U R,                  R,                  0 :w  ay  US-  n
U
R/                  5       (       a  [$        R&                  " S[0        5        U
R                  SSS9 n[        R                  " U R,                  R,                  USSS9  SSS5        [3        XXH5        [         R4                  R6                  " X4SU0UD6  g! , (       d  f       GNg= f! , (       d  f       NP= f)a  
Saves a Keras model to save_directory in SavedModel format. Use this if
you're using the Functional or Sequential APIs.

Args:
    model (`Keras.Model`):
        The [Keras
        model](https://www.tensorflow.org/api_docs/python/tf/keras/Model)
        you'd like to save. The model must be compiled and built.
    save_directory (`str` or `Path`):
        Specify directory in which you want to save the Keras model.
    config (`dict`, *optional*):
        Configuration object to be saved alongside the model weights.
    include_optimizer(`bool`, *optional*, defaults to `False`):
        Whether or not to include optimizer in serialization.
    plot_model (`bool`, *optional*, defaults to `True`):
        Setting this to `True` will plot the model and put it in the model
        card. Requires graphviz and pydot to be installed.
    tags (Union[`str`,`list`], *optional*):
        List of tags that are related to model or string of a single tag. See example tags
        [here](https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1).
    model_save_kwargs(`dict`, *optional*):
        model_save_kwargs will be passed to
        [`tf.keras.models.save_model()`](https://www.tensorflow.org/api_docs/python/tf/keras/models/save_model).
Nz>Called a Tensorflow-specific function but could not import it.z+Model should be built before trying to saveT)parentsexist_okzAProvided config to save_pretrained_keras should be a dict. Got: ''wre   	task_namez>`task_name` input argument is deprecated. Pass `tags` instead.zhistory.jsonzZ`history.json` file already exists, it will be overwritten by the history of this version.zutf-8)encoding   )indent	sort_keysrd   )r=   ImportErrorbuilt
ValueErrorr   mkdirr-   r3   RuntimeErrortyper   CONFIG_NAMEopenjsondumpliststrpopwarningswarnFutureWarningr2   r   rZ   UserWarningrb   models
save_model)r"   rR   rc   rd   rQ   re   model_save_kwargsfrU   rk   r\   s              r%   save_pretrained_kerasr      s   F }Z[[;;FGG.)N5 &$''!bcghncobppqrssy444::3?1IIf  @ H$	D#		 6!%%k48IL	
 XV##I. ){HV}} ==  B&!N2D{{}}p 31Q		%--//1M 2 ujC	LLElEVlZklA @?8 21s    H3,H)
H&)
H7KerasModelHubMixinc                  .    [         R                  " U 0 UD6$ )a
  
Instantiate a pretrained Keras model from a pre-trained model from the Hub.
The model is expected to be in `SavedModel` format.

Args:
    pretrained_model_name_or_path (`str` or `os.PathLike`):
        Can be either:
            - A string, the `model id` of a pretrained model 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`.
            - You can add `revision` by appending `@` at the end of model_id
              simply like this: `dbmdz/bert-base-german-cased@main` Revision
              is 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.
            - A path to a `directory` containing model weights saved using
              [`~transformers.PreTrainedModel.save_pretrained`], e.g.,
              `./my_model_directory/`.
            - `None` if you are both providing the configuration and state
              dictionary (resp. with keyword arguments `config` and
              `state_dict`).
    force_download (`bool`, *optional*, defaults to `False`):
        Whether to force the (re-)download of the model weights and
        configuration files, overriding 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`).
    cache_dir (`Union[str, 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.
    local_files_only(`bool`, *optional*, defaults to `False`):
        Whether to only look at local files (i.e., do not try to download
        the model).
    model_kwargs (`Dict`, *optional*):
        model_kwargs will be passed to the model during initialization

<Tip>

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

</Tip>
)r   from_pretrained)r#   r$   s     r%   from_pretrained_kerasr      s    j --t>v>>r(   z'Push Keras model using huggingface_hub.)rc   commit_messageprivateapi_endpointtokenbranch	create_prallow_patternsignore_patternsdelete_patternslog_dirrd   re   rQ   repo_idr   r   r   r   r   r   r   r   r   r   c                   [        US9nUR                  XUSS9R                  n[        5        n[	        U5      U-  n[        U U4UUUUS.UD6  Ub?  Uc  / O[        U[        5      (       a  U/OUnUR                  S5        [        UUS-  5        UR                  SUUUUUUU	U
US	9
sSSS5        $ ! , (       d  f       g= f)
a  
Upload model checkpoint to the Hub.

Use `allow_patterns` and `ignore_patterns` to precisely filter which files should be pushed to the hub. Use
`delete_patterns` to delete existing remote files in the same commit. See [`upload_folder`] reference for more
details.

Args:
    model (`Keras.Model`):
        The [Keras model](`https://www.tensorflow.org/api_docs/python/tf/keras/Model`) you'd like to push to the
        Hub. The model must be compiled and built.
    repo_id (`str`):
            ID of the repository to push to (example: `"username/my-model"`).
    commit_message (`str`, *optional*, defaults to "Add Keras model"):
        Message to commit while pushing.
    private (`bool`, *optional*):
        Whether the repository created should be private.
        If `None` (default), the repo will be public unless the organization's default is private.
    api_endpoint (`str`, *optional*):
        The API endpoint to use when pushing the model to the hub.
    token (`str`, *optional*):
        The token to use as HTTP bearer authorization for remote files. If
        not set, will use the token set when logging in with
        `huggingface-cli login` (stored in `~/.huggingface`).
    branch (`str`, *optional*):
        The git branch on which to push the model. This defaults to
        the default branch as specified in your repository, which
        defaults to `"main"`.
    create_pr (`boolean`, *optional*):
        Whether or not to create a Pull Request from `branch` with that commit.
        Defaults to `False`.
    config (`dict`, *optional*):
        Configuration object to be saved alongside the model weights.
    allow_patterns (`List[str]` or `str`, *optional*):
        If provided, only files matching at least one pattern are pushed.
    ignore_patterns (`List[str]` or `str`, *optional*):
        If provided, files matching any of the patterns are not pushed.
    delete_patterns (`List[str]` or `str`, *optional*):
        If provided, remote files matching any of the patterns will be deleted from the repo.
    log_dir (`str`, *optional*):
        TensorBoard logging directory to be pushed. The Hub automatically
        hosts and displays a TensorBoard instance if log files are included
        in the repository.
    include_optimizer (`bool`, *optional*, defaults to `False`):
        Whether or not to include optimizer during serialization.
    tags (Union[`list`, `str`], *optional*):
        List of tags that are related to model or string of a single tag. See example tags
        [here](https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1).
    plot_model (`bool`, *optional*, defaults to `True`):
        Setting this to `True` will plot the model and put it in the model
        card. Requires graphviz and pydot to be installed.
    model_save_kwargs(`dict`, *optional*):
        model_save_kwargs will be passed to
        [`tf.keras.models.save_model()`](https://www.tensorflow.org/api_docs/python/tf/keras/models/save_model).

Returns:
    The url of the commit of your model in the given repository.
)endpointT)r   r   r   rh   )rc   rd   re   rQ   Nzlogs/*logsr"   )
	repo_typer   folder_pathr   r   revisionr   r   r   r   )r   create_repor   r   r   r   r-   r{   r2   r   upload_folder)r"   r   rc   r   r   r   r   r   r   r   r   r   r   rd   re   rQ   r   apitmp
saved_paths                       r%   push_to_hub_kerasr   (  s    ` 
&CoogGVZo[ccG 
 	!S#Y(
	
 /!	
  	
  #*  "/377 %%(  ""8,Wj612  "))++ ! 
5 
"	!	!s   A:B33
Cc                   L    \ rS rSrSrS r\ SS\\\	\
4      4S jj5       rSrg)	r   i  a  
Implementation of [`ModelHubMixin`] to provide model Hub upload/download
capabilities to Keras models.


```python
>>> import tensorflow as tf
>>> from huggingface_hub import KerasModelHubMixin


>>> class MyModel(tf.keras.Model, KerasModelHubMixin):
...     def __init__(self, **kwargs):
...         super().__init__()
...         self.config = kwargs.pop("config", None)
...         self.dummy_inputs = ...
...         self.layer = ...

...     def call(self, *args):
...         return ...


>>> # Initialize and compile the model as you normally would
>>> model = MyModel()
>>> model.compile(...)
>>> # Build the graph by training it or passing dummy inputs
>>> _ = model(model.dummy_inputs)
>>> # Save model weights to local directory
>>> model.save_pretrained("my-awesome-model")
>>> # Push model weights to the Hub
>>> model.push_to_hub("my-awesome-model")
>>> # Download and initialize weights from the Hub
>>> model = MyModel.from_pretrained("username/super-cool-model")
```
c                     [        X5        g N)r   )selfrR   s     r%   _save_pretrained#KerasModelHubMixin._save_pretrained  s
    d3r(   Nrc   c
                     [         c  [        S5      e[        R                  R	                  U5      (       d  [        UUUS[        5       S9nOUn[         R                  R                  U5      nXl	        U$ )zHere we just call [`from_pretrained_keras`] function so both the mixin and
functional APIs stay in sync.

        TODO - Some args above aren't used since we are calling
        snapshot_download instead of hf_hub_download.
z>Called a TensorFlow-specific function but could not import it.r=   )r   r   	cache_dirrW   library_version)
r=   rp   r[   r\   isdirr   r   r   
load_modelrc   )clsmodel_idr   r   force_downloadproxiesresume_downloadlocal_files_onlyr   rc   model_kwargsstorage_folderr"   s                r%   _from_pretrained#KerasModelHubMixin._from_pretrained  so    ( =^__ ww}}X&&. !#$ . 0N &N ''7 r(    r   )r!   
__module____qualname____firstlineno____doc__r   classmethodr
   r   r{   r   r   __static_attributes__r   r(   r%   r   r     s=    !F4  ,0( c3h(( (r(   ) )TN)NFTN)r   r   ):collections.abcabcr.   rx   r[   r}   	functoolsr   pathlibr   shutilr   typingr   r   r	   r
   r   huggingface_hubr   r   huggingface_hub.utilsr   r   r   r   r   r   r   hf_apir   rP   r   r   r   utils._typingr   
get_loggerr!   loggerr=   tf_kerasrp   
tensorflowtfr)   r1   rC   rS   boolr3   rb   r{   rz   r   r   r   r   r   r(   r%   <module>r      s   %  	     3 3 <    H H $ 
		H	%
 	 i :" #	)')' )' tn	)'X  (,#'+Pm#t)$Pm T#s(^$Pm 	Pm
 Pm 5s#
$Pm Pmf5?p 
 "C""&  $6:7;7;!#'+#w
w
 TN	w

 w
 d^w
 3-w
 C=w
 SMw
 ~w
 U49c>23w
 eDIsN34w
 eDIsN34w
 c]w
 w
  5s#
$!w
" #w
  w
tP PC  s   E, ,FF