o
    2h
                     @   sp   d dl Z d dlZd dlZd dlmZ d dlmZ zd dlZW n e	y)   dZY nw edG dd deZ
dS )    N)keras_export)Callbackzkeras.callbacks.RemoteMonitorc                       s6   e Zd ZdZ					d fdd	Zdd	d
Z  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                    s,   t    || _|| _|| _|| _|| _d S N)super__init__rootpathfieldheaderssend_as_json)selfr   r   r   r   r   	__class__ ]/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/callbacks/remote_monitor.pyr
   &   s   

zRemoteMonitor.__init__c                 C   s   t d u rtd|pi }i }||d< | D ]\}}t|tjtjfr*| ||< q|||< qz)| jrCt j	| j
| j || jd W d S t j	| j
| j | jt|i| jd W d S  t jjyo   tjd| j
 dd Y d S 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vr   r   r   on_epoch_end6   s2   


zRemoteMonitor.on_epoch_end)r   r   r   NFr   )__name__
__module____qualname____doc__r
   r+   __classcell__r   r   r   r   r      s    r   )r   r%   numpyr   keras.src.api_exportr   keras.src.callbacks.callbackr   r   r   r   r   r   r   r   <module>   s    