Ë
    Q^(hvL  ã            "       óò  — d dl m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 d dlmZmZmZmZmZ d dlmZmZ d dlmZmZ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" ddl#m$Z$  e!jJ                  e&«      Z'dZ( e«       r	 d dl)Z(de$de$fd„Z-d/d„Z.d„ Z/d„ Z0	 	 d0de	de1dee2   fd„Z3e-	 	 	 	 d1dee4e	f   deee4ef      de1de1deee5e4f      f
d„«       Z6d2d„Z7e"e-dd ddddddddddddd!œd"e4dee2   d#e4d$ee1   d%ee4   d&ee4   d'ee4   d(ee1   d)eeee4   e4f      d*eeee4   e4f      d+eeee4   e4f      d,ee4   de1deee5e4f      de1fd-„«       «       Z8 G d.„ de«      Z9y# e*$ r d dl+Z,e,jP                  Z(Y Œðw xY w)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                 ó.   ‡ — t        ‰ «      ˆ fd„«       }|S )Nc                 óf   •— t        | d«      st        d‰j                  › d�«      ‚ ‰| g|¢­i |¤ŽS )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      €úY/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/huggingface_hub/keras_mixin.pyÚ_innerz'_requires_keras_2_model.<locals>._inner+   sH   ø€ ä�u˜iÔ(Ü%Ø˜rŸ{™{˜mð ,rð róð ñ �%Ð)˜$Ò) &Ñ)Ð)ó    r   )r   r&   s   ` r%   Ú_requires_keras_2_modelr(   )   s    ø€ ä
ˆ2ƒYó*ó ð*ð €Mr'   c                 ó  — g }| j                  «       D ]g  \  }}|r|› d|› �n|}t        |t        j                  «      r*|j	                  t        ||«      j                  «       «       ŒU|j                  ||f«       Œi t        |«      S )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%   r0   r0   7   s‹   € ð €EØ ×&Ñ&Ó(ò 
+‰
ˆˆUÙ+5�Z�L  # Ñ'¸3ˆÜ�eœ[×7Ñ7Ô8Ø�L‰LÜØØó÷ ‘%“'õ	ð �L‰L˜' 5Ð)Õ*ð
+ô �‹;Ðr'   c                 ó  — d}| j                   �v| j                   j                  «       }t        |«      }t        j                  j                  «       j                  |d<   d}|j                  «       D ]  \  }}|d|› d|› d�z  }Œ |S )z6Parse hyperparameter dictionary into a markdown table.NÚtraining_precisionz*| Hyperparameters | Value |
| :-- | :-- |
z| z | z |
)Ú	optimizerÚ
get_configr0   ÚkerasÚmixed_precisionÚglobal_policyÚnamer+   )r"   ÚtableÚoptimizer_paramsr5   r6   s        r%   Ú_create_hyperparameter_tablerB   T   s�   € à€EØ‡�Ð"Ø Ÿ?™?×5Ñ5Ó7Ðä(Ð)9Ó:ÐÜ16×1FÑ1F×1TÑ1TÓ1V×1[Ñ1[ÐÐ-Ñ.Ø>ˆØ*×0Ñ0Ó2ò 	.‰JˆC�Ø�r˜#˜˜c % ¨Ð-Ñ-‰Eð	.à€Lr'   c                 óZ   — t         j                  j                  | |› d�ddddddd ¬«	       y )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_networkrR   b   s<   € Ü	‡K�K×ÑØØ!Ð" *Ð-ØØØØØØØð õ 
r'   TÚrepo_dirrP   Úmetadatac                 óÆ  — |dz  }|j                  «       ryt        | «      }|r t        «       rt        «       rt	        | |«       |€i }d|d<   d}|t        |d¬«      z  }|dz  }|dz  }|d	z  }|d
z  }|�|dz  }|dz  }|dz  }||z  }|dz  }|rAt        j                  j                  |› d�«      r|dz  }|dz  }|dz  }d}|d|› d�z  }|dz  }|j                  |«       y)zd
    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:

ú
rD   z
 ## Model Plot
z

<details>z$
<summary>View Model Plot</summary>
z./model.pngz
![Model Image](z)
z
</details>)	ÚexistsrB   r   r   rR   r   ÚosÚpathÚ
write_text)r"   rS   rP   rT   Úreadme_pathÚhyperparametersÚ
model_cardÚpath_to_plots           r%   Ú_create_model_cardra   p   s;  € ð ˜[Ñ(€KØ×ÑÔØä2°5Ó9€OÙÔ+Ô-Ô2DÔ2FÜ�e˜XÔ&ØÐØˆØ&€Hˆ^ÑØ€JØ”)˜H¸Ô?Ñ?€JØ�'Ñ€JØÐGÑG€JØÐQÑQ€JØÐRÑR€JØÐ"ØÐ1Ñ1ˆ
ØÐ8Ñ8ˆ
ØÐVÑVˆ
Ø�oÑ%ˆ
Ø�dÑˆ
Ù”b—g‘g—n‘n¨ z°Ð%<Ô=ØÐ*Ñ*ˆ
Ø�mÑ#ˆ
ØÐ>Ñ>ˆ
Ø$ˆØÐ)¨,¨°sÐ;Ñ;ˆ
Ø�nÑ$ˆ
à×Ñ˜:Õ&r'   FrQ   ÚconfigÚinclude_optimizerÚtagsc                 ó*  — t         €t        d«      ‚| j                  st        d«      ‚t	        |«      }|j                  dd¬«       |rit        |t        «      st        dt        |«      › d�«      ‚|t        j                  z  j                  d«      5 }t        j                  ||«       ddd«       i }t        |t        «      r||d	<   nt        |t         «      r|g|d	<   |j#                  d
d«      }	|	�9t%        j&                  dt(        «       d	|v r|d	   j+                  |	«       n|	g|d	<   | j,                  �‘| j,                  j,                  i k7  rx|dz  }
|
j/                  «       rt%        j&                  dt0        «       |
j                  dd¬«      5 }t        j                  | j,                  j,                  |dd¬«       ddd«       t3        | |||«       t        j4                  j6                  | |fd|i|¤Ž y# 1 sw Y   �ŒTxY w# 1 sw Y   ŒHxY w)aL  
    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: 'ú'Úwrd   Ú	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_keysrc   )r<   ÚImportErrorÚbuiltÚ
ValueErrorr   Úmkdirr,   r2   ÚRuntimeErrorÚtyper   ÚCONFIG_NAMEÚopenÚjsonÚdumpÚlistÚstrÚpopÚwarningsÚwarnÚFutureWarningr1   r   rY   ÚUserWarningra   ÚmodelsÚ
save_model)r"   rQ   rb   rc   rP   rd   Úmodel_save_kwargsÚfrT   rj   r[   s              r%   Úsave_pretrained_kerasr„   œ   sð  € ôF €}ÜÐZÓ[Ð[à�;Š;ÜÐFÓGÐGä˜.Ó)€NØ×Ñ °ÐÔ5ñ Ü˜&¤$Ô'ÜÐ!bÔcgÐhnÓcoÐbpÐpqÐrÓsÐsàœy×4Ñ4Ñ4×:Ñ:¸3Ó?ð 	!À1Ü�I‰I�f˜aÔ ÷	!ð €HÜ�$œÔØˆ�ÒÜ	�Dœ#Ô	Ø ˜6ˆ�Ñà!×%Ñ% k°4Ó8€IØÐÜ�‰ØLÜô	
ð �XÑØ�VÑ×#Ñ# IÕ.à )˜{ˆH�VÑà‡}�}Ð Ø�=‰=× Ñ  BÒ&Ø! NÑ2ˆDØ�{‰{Œ}Ü—‘ØpÜôð —‘˜3¨�Ó1ð N°QÜ—	‘	˜%Ÿ-™-×/Ñ/°¸1ÈÕM÷Nô �u˜n¨j¸(ÔCÜ	‡L�L×Ñ˜E >ÑlÐEVÐlÐZkÓl÷A	!ñ 	!ú÷8Nð Nús   ÂG<Æ.H	Ç<HÈ	HÚKerasModelHubMixinc                  ó,   — t        j                  | i |¤ŽS )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.)rb   Úcommit_messageÚprivateÚapi_endpointÚtokenÚbranchÚ	create_prÚallow_patternsÚignore_patternsÚdelete_patternsÚlog_dirrc   rd   rP   Úrepo_idr‰   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   c                ó„  — t        |¬«      }|j                  |||d¬«      j                  }t        «       5 }t	        |«      |z  }t        | |f||||dœ|¤Ž |�9|€g nt        |t        «      r|gn|}|j                  d«       t        ||dz  «       |j                  d|||||||	|
|¬	«
      cddd«       S # 1 sw Y   yxY w)
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Š   rg   )rb   rc   rd   rP   Nzlogs/*Úlogsr"   )
Ú	repo_typer“   Úfolder_pathr‰   rŒ   ÚrevisionrŽ   r�   r�   r‘   )r   Úcreate_repor“   r   r   r„   r,   rz   r1   r   Úupload_folder)r"   r“   rb   r‰   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   rc   rd   rP   r‚   ÚapiÚtmpÚ
saved_paths                       r%   Úpush_to_hub_kerasrŸ   (  s  € ô` ˜Ô
&€CØ�o‰o g°UÀGÐVZˆoÓ[×cÑc€Gô 
 Ó	!ð %
 SÜ˜#“Y Ñ(ˆ
ÜØØð	
ð Ø/ØØ!ñ	
ð  ò	
ð Ðð #Ð*ñ ô " /´3Ô7ð %Ñ%à(ð ð ×"Ñ" 8Ô,Ü�W˜j¨6Ñ1Ô2à× Ñ ØØØ"Ø)ØØØØ)Ø+Ø+ð !ó 
÷5%
÷ %
ò %
ús   ¶A6B6Â6B?c                   ó@   — e Zd ZdZd„ Ze	 ddeeee	f      fd„«       Z
y)r…   aA  
    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                 ó   — t        | |«       y ©N)r„   )ÚselfrQ   s     r%   Ú_save_pretrainedz#KerasModelHubMixin._save_pretrainedÈ  s   € Ü˜d NÕ3r'   Nrb   c
                 óè   — t         €t        d«      ‚t        j                  j	                  |«      st        |||dt        «       ¬«      }n|}t         j                  j                  |«      }|	|_	        |S )a   Here 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_dirrV   Úlibrary_version)
r<   ro   rZ   r[   Úisdirr   r   r€   Ú
load_modelrb   )ÚclsÚmodel_idr™   r¦   Úforce_downloadÚproxiesÚresume_downloadÚlocal_files_onlyrŒ   rb   Úmodel_kwargsÚstorage_folderr"   s                r%   Ú_from_pretrainedz#KerasModelHubMixin._from_pretrainedË  sn   € ô( ˆ=ÜÐ^Ó_Ð_ô �w‰w�}‰}˜XÔ&Ü.Ø Ø!Ø#Ø$Ü .Ó 0ô‰Nð &ˆNô —‘×'Ñ'¨Ó7ˆð ˆŒàˆr'   r¢   )r!   Ú
__module__Ú__qualname__Ú__doc__r¤   Úclassmethodr
   r   rz   r   r²   © r'   r%   r…   r…   ¤  s=   „ ñ!òF4ð ð ,0ñ(ð ˜˜c 3˜h™Ñ(ò(ó ñ(r'   )Ú )TN)NFTN)r   r…   ):Úcollections.abcÚabcr-   rw   rZ   r|   Ú	functoolsr   Úpathlibr   Úshutilr   Útypingr   r   r	   r
   r   Úhuggingface_hubr   r   Úhuggingface_hub.utilsr   r   r   r   r   r¸   r   Úhf_apir   rO   r   r   r   Úutils._typingr   Ú
get_loggerr!   Úloggerr<   Útf_kerasro   Ú
tensorflowÚtfr(   r0   rB   rR   Úboolr2   ra   rz   ry   r„   rˆ   rŸ   r…   r·   r'   r%   ú<module>rÉ      sº  ðÝ %Û Û 	Û Ý Ý Ý ß 3Õ 3ç <÷õ õ Ý ß HÑ HÝ $ð 
ˆ×	Ñ	˜HÓ	%€à€ÙÔð
Û ð 	ð ¨ió óò:òð" Ø#ñ	)'àð)'ð ð)'ð �t‰nó	)'ð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
ð �T‰Nð	w
ð
 ðw
ð �d‰^ðw
ð ˜3‘-ðw
ð �C‰=ðw
ð �S‰Mðw
ð ˜‰~ðw
ð ˜U 4¨¡9¨c >Ñ2Ñ3ðw
ð ˜e D¨¡I¨s NÑ3Ñ4ðw
ð ˜e D¨¡I¨s NÑ3Ñ4ðw
ð �c‰]ðw
ð ðw
ð  �5˜˜s˜Ñ#Ñ
$ð!w
ð" ò#w
ó ó ðw
ôtP˜õ PøðC ò Ûà—‘Šðús   ÂE ÅE6Å5E6