o
    2hf                     @   sr   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ d	ZG d
d dejZdS )zzThe TensorBoard Histograms plugin.

See `http_api.md` in this directory for specifications of the routes for
this plugin.
    )wrappers)errors)plugin_util)	http_util)provider)base_plugin)metadatai  c                   @   sl   e Zd ZdZejZdZdd Zdd Z	dd Z
d	d
 Zdd ZdddZejjdd Zejjdd ZdS )HistogramsPlugina  Histograms Plugin for TensorBoard.

    This supports both old-style summaries (created with TensorFlow ops
    that output directly to the `histo` field of the proto) and new-
    style summaries (as created by the
    `tensorboard.plugins.histogram.summary` module).
    3   c                 C   s2   |j pi | jt| _|j| _tjddd| _	dS )zInstantiates HistogramsPlugin via TensorBoard core.

        Args:
          context: A base_plugin.TBContext instance.
        	histogramr   )	data_kindlatest_known_versionN)
sampling_hintsgetplugin_name_DEFAULT_DOWNSAMPLING_downsample_todata_provider_data_providerr   _MetadataVersionChecker_version_checker)selfcontext r   j/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorboard/plugins/histogram/histograms_plugin.py__init__2   s   
zHistogramsPlugin.__init__c                 C   s   | j | jdS )N)z/histogramsz/tags)histograms_route
tags_router   r   r   r   get_plugin_appsA   s   z HistogramsPlugin.get_plugin_appsc                 C   s   dS )NFr   r   r   r   r   	is_activeG   s   zHistogramsPlugin.is_activec                 C   s   | j j||tjd}dd |D }| D ]-\}}| D ]$\}}t|j}	t|j	}
| j
|
j||s7q|j|	d|| |< qq|S )zJReturn {runName: {tagName: {displayName: ..., description:
        ...}}}.)experiment_idr   c                 S   s   i | ]}|i qS r   r   ).0runr   r   r   
<dictcomp>R   s    z/HistogramsPlugin.index_impl.<locals>.<dictcomp>)displayNamedescription)r   list_tensorsr   PLUGIN_NAMEitemsr   markdown_to_safe_htmlr&   parse_plugin_metadataplugin_contentr   okversiondisplay_name)r   ctx
experimentmappingresultr#   tag_to_contenttag	metadatumr&   mdr   r   r   
index_implJ   s&   zHistogramsPlugin.index_implc                 C   s   t jddS )Nztf-histogram-dashboard)element_name)r   FrontendMetadatar   r   r   r   frontend_metadataa   s   z"HistogramsPlugin.frontend_metadataNc           
   	   C   s|   |dur|n| j }| jj||tj|tj|g|gdd}||i |d}|du r3t	d||f dd |D }	|	dfS )a  Result of the form `(body, mime_type)`.

        At most `downsample_to` events will be returned. If this value is
        `None`, then default downsampling will be performed.

        Raises:
          tensorboard.errors.PublicError: On invalid request.
        N)runstags)r!   r   
downsamplerun_tag_filterzNo histogram tag %r for run %rc                 S   s    g | ]}|j |j|j fqS r   )	wall_timestepnumpytolist)r"   er   r   r   
<listcomp>~   s     z4HistogramsPlugin.histograms_impl.<locals>.<listcomp>application/json)
r   r   read_tensorsr   r(   r   RunTagFilterr   r   NotFoundError)
r   r0   r5   r#   r1   downsample_tosample_countall_histograms
histogramseventsr   r   r   histograms_implf   s    

z HistogramsPlugin.histograms_implc                 C   s4   t |j}t |j}| j||d}t||dS )N)r1   rF   )r   r   environr!   r8   r   Respond)r   requestr0   r1   indexr   r   r   r      s   zHistogramsPlugin.tags_routec                 C   sX   t |j}t |j}|jd}|jd}| j||||| jd\}}t	|||S )z=Given a tag and single run, return array of histogram values.r5   r#   )r1   rJ   )
r   r   rP   r!   argsr   rO   SAMPLE_SIZEr   rQ   )r   rR   r0   r1   r5   r#   body	mime_typer   r   r   r      s   
z!HistogramsPlugin.histograms_route)N)__name__
__module____qualname____doc__r   r(   r   rU   r   r   r    r8   r;   rO   r   Requestapplicationr   r   r   r   r   r   r	   #   s    

r	   N)r[   werkzeugr   tensorboardr   r   tensorboard.backendr   tensorboard.datar   tensorboard.pluginsr   tensorboard.plugins.histogramr   r   TBPluginr	   r   r   r   r   <module>   s   