o
    2h                     @   sp   d Z ddlmZ ddlmZ ddlmZ ddlm	Z	 e	dg dG dd	 d	Z
e	d
g ddede
fddZdS )z{Methods for SavedModel fingerprinting.

This module contains classes and functions for reading the SavedModel
fingerprint.
    )Any)fingerprint_pb2)fingerprinting)	tf_exportz$saved_model.experimental.Fingerprint)v1c                   @   s   e Zd ZdZ						ddedededededefd	d
Zedejdd fddZ	de
defddZdefddZdefddZdejfddZdS )Fingerprintay  The SavedModel fingerprint.

  Each attribute of this class is named after a field name in the
  FingerprintDef proto and contains the value of the respective field in the
  protobuf.

  Attributes:
    saved_model_checksum: A uint64 containing the `saved_model_checksum`.
    graph_def_program_hash: A uint64 containing `graph_def_program_hash`.
    signature_def_hash: A uint64 containing the `signature_def_hash`.
    saved_object_graph_hash: A uint64 containing the `saved_object_graph_hash`.
    checkpoint_hash: A uint64 containing the`checkpoint_hash`.
    version: An int32 containing the producer field of the VersionDef.
  Nsaved_model_checksumgraph_def_program_hashsignature_def_hashsaved_object_graph_hashcheckpoint_hashversionc                 C   s(   || _ || _|| _|| _|| _|| _dS )a  Initializes the instance based on values in the SavedModel fingerprint.

    Args:
      saved_model_checksum: Value of the`saved_model_checksum`.
      graph_def_program_hash: Value of the `graph_def_program_hash`.
      signature_def_hash: Value of the `signature_def_hash`.
      saved_object_graph_hash: Value of the `saved_object_graph_hash`.
      checkpoint_hash: Value of the `checkpoint_hash`.
      version: Value of the producer field of the VersionDef.
    N)r   r	   r
   r   r   r   )selfr   r	   r
   r   r   r    r   g/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorflow/python/saved_model/fingerprinting.py__init__-   s   
zFingerprint.__init__protoreturnc              
   C   s`   t |trtj|}zt|j|j|j|j	|j
|jW S  ty/ } ztd| dd}~ww )z;Constructs Fingerprint object from protocol buffer message.z5Given proto could not be deserialized as fingerprint.N)
isinstancebytesr   FingerprintDef
FromStringr   r   r	   r
   r   r   r   AttributeError
ValueError)clsr   er   r   r   
from_protoG   s*   
zFingerprint.from_protootherc                 C   sn   t |tst |tjr5z| j|jko)| j|jko)| j|jko)| j|jko)| j|jkW S  t	y4   Y dS w dS )NF)
r   r   r   r   r   r	   r
   r   r   r   )r   r   r   r   r   __eq__Y   s$   





zFingerprint.__eq__c              	   C   s>   d dd| j d| j d| j d| j d| j gS )N
zSavedModel Fingerprintz  saved_model_checksum: z  graph_def_program_hash: z  signature_def_hash: z  saved_object_graph_hash: z  checkpoint_hash: )joinr   r	   r
   r   r   r   r   r   r   __str__g   s   




zFingerprint.__str__c                 C   s.   d| j  d| j d| j d| j d| j dS )NzFingerprint(z, ))r   r	   r
   r   r   r!   r   r   r   __repr__q   s   
zFingerprint.__repr__c                 C   sh   zt | j| j| j| jW S  tt jfy3 } ztd| j d| j d| j d| j | 	dd}~ww )a  Canonical fingerprinting ID for a SavedModel.

    Uniquely identifies a SavedModel based on the regularized fingerprint
    attributes. (saved_model_checksum is sensitive to immaterial changes and
    thus non-deterministic.)

    Returns:
      The string concatenation of `graph_def_program_hash`,
      `signature_def_hash`, `saved_object_graph_hash`, and `checkpoint_hash`
      fingerprint attributes (separated by '/').

    Raises:
      ValueError: If the fingerprint fields cannot be used to construct the
      singleprint.
    z[Encounted invalid fingerprint values when constructing singleprint.graph_def_program_hash: zsignature_def_hash: zsaved_object_graph_hash: zcheckpoint_hash: N)	fingerprinting_pywrapSingleprintr	   r
   r   r   	TypeErrorFingerprintExceptionr   )r   r   r   r   r   singleprintx   s0   zFingerprint.singleprint)NNNNNN)__name__
__module____qualname____doc__intr   classmethodr   r   r   r   boolr   strr"   r$   r%   r&   r)   r   r   r   r   r      s6    

r   z)saved_model.experimental.read_fingerprint
export_dirr   c              
   C   sv   zt | }W n) t jy } ztd| dd}~w t jy0 } ztd| dd}~ww tt	 
|S )a9  Reads the fingerprint of a SavedModel in `export_dir`.

  Returns a `tf.saved_model.experimental.Fingerprint` object that contains
  the values of the SavedModel fingerprint, which is persisted on disk in the
  `fingerprint.pb` file in the `export_dir`.

  Read more about fingerprints in the SavedModel guide at
  https://www.tensorflow.org/guide/saved_model.

  Args:
    export_dir: The directory that contains the SavedModel.

  Returns:
    A `tf.saved_model.experimental.Fingerprint`.

  Raises:
    FileNotFoundError: If no or an invalid fingerprint is found.
  zSavedModel Fingerprint Error: N)r%   ReadSavedModelFingerprintFileNotFoundExceptionFileNotFoundErrorr(   RuntimeErrorr   r   r   r   r   )r2   fingerprintr   r   r   r   read_fingerprint   s   r8   N)r-   typingr   tensorflow.core.protobufr   0tensorflow.python.saved_model.pywrap_saved_modelr   r%    tensorflow.python.util.tf_exportr   r   r1   r8   r   r   r   r   <module>   s   

z