
    &Vf
                         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Zn# e	$ r dZY nw xY w ed           G d de                      Z
dS )    N)keras_export)Callbackzkeras.callbacks.RemoteMonitorc                   6     e Zd ZdZ	 	 	 	 	 d	 fd	Zd
dZ xZS )RemoteMonitora  Callback used to stream events to a server.

    Requires the `requests` library.
    Events are sent to `root + '/publish/epoch/end/'` by default. Calls are
    HTTP POST, with a `data` argument which is a
    JSON-encoded dictionary of event data.
    If `send_as_json=True`, the content type of the request will be
    `"application/json"`.
    Otherwise the serialized JSON will be sent within a form.

    Args:
        root: String; root url of the target server.
        path: String; path relative to `root` to which the events will be sent.
        field: String; JSON field under which the data will be stored.
            The field is used only if the payload is sent within a form
            (i.e. when `send_as_json=False`).
        headers: Dictionary; optional custom HTTP headers.
        send_as_json: Boolean; whether the request should be
            sent as `"application/json"`.
    http://localhost:9000/publish/epoch/end/dataNFc                     t                                                       || _        || _        || _        || _        || _        d S N)super__init__rootpathfieldheaderssend_as_json)selfr   r   r   r   r   	__class__s         _/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/callbacks/remote_monitor.pyr   zRemoteMonitor.__init__&   sE     			
(    c                 ^   t           t          d          |pi }i }||d<   |                                D ]H\  }}t          |t          j        t          j        f          r|                                ||<   C|||<   I	 | j        r+t          j	        | j
        | j        z   || j                   d S t          j	        | j
        | j        z   | j        t          j        |          i| j                   d S # t           j        j        $ r" t%          j        d| j
         d           Y d S w xY w)Nz.RemoteMonitor requires the `requests` library.epoch)jsonr   )r   z-Could not reach RemoteMonitor root server at    )
stacklevel)requestsImportErroritems
isinstancenpndarraygenericitemr   postr   r   r   r   r   dumps
exceptionsRequestExceptionwarningswarn)r   r   logssendkvs         r   on_epoch_endzRemoteMonitor.on_epoch_end6   sn   NOOOzrWJJLL 	 	DAq !bj"*566 &&((QQ	  	I	)dl      I	)ZD!1!12 L     
 "3 	 	 	MK	KK      	s    0C6 2AC6 62D,+D,)r   r   r	   NFr   )__name__
__module____qualname____doc__r   r.   __classcell__)r   s   @r   r   r      sl         . %") ) ) ) ) )        r   r   )r   r(   numpyr    keras.src.api_exportr   keras.src.callbacks.callbackr   r   r   r    r   r   <module>r8      s          - - - - - - 1 1 1 1 1 1OOOO   HHH -..C C C C CH C C /.C C Cs    ))