a
    
d                     @   sn   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 G d	d
 d
ejZdS )zThe TensorBoard Distributions (a.k.a. compressed histograms) plugin.

See `http_api.md` in this directory for specifications of the routes for
this plugin.
    )wrappers)plugin_util)	http_util)base_plugin)
compressor)metadata)histograms_pluginc                   @   sz   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 Zdd Zdd Zejjdd Zejjdd ZdS )DistributionsPlugina  Distributions 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).
    i  c                 C   s   t || _dS )zInstantiates DistributionsPlugin via TensorBoard core.

        Args:
          context: A base_plugin.TBContext instance.
        N)r   ZHistogramsPlugin_histograms_plugin)selfcontext r   ~/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/tensorboard/plugins/distribution/distributions_plugin.py__init__/   s    zDistributionsPlugin.__init__c                 C   s   | j | jdS )N)z/distributionsz/tags)distributions_route
tags_router   r   r   r   get_plugin_apps7   s    z#DistributionsPlugin.get_plugin_appsc                 C   s
   | j  S )zThis plugin is active iff any run has at least one histogram tag.

        (The distributions plugin uses the same data source as the
        histogram plugin.)
        )r
   	is_activer   r   r   r   r   =   s    zDistributionsPlugin.is_activec                 C   s
   | j jfS N)r
   plugin_namer   r   r   r   data_plugin_namesE   s    z%DistributionsPlugin.data_plugin_namesc                 C   s   t jddS )Nztf-distribution-dashboard)Zelement_name)r   ZFrontendMetadatar   r   r   r   frontend_metadataH   s    z%DistributionsPlugin.frontend_metadatac                    s2    j j|||| jd\}} fdd|D |fS )zResult of the form `(body, mime_type)`.

        Raises:
          tensorboard.errors.PublicError: On invalid request.
        )
experimentZdownsample_toc                    s   g | ]}  |qS r   )	_compress).0	histogramr   r   r   
<listcomp>W       z:DistributionsPlugin.distributions_impl.<locals>.<listcomp>)r
   Zhistograms_implSAMPLE_SIZE)r   ctxtagrunr   Z
histograms	mime_typer   r   r   distributions_implM   s    
z&DistributionsPlugin.distributions_implc                 C   s   |\}}}t |}|||gS r   )r   Zcompress_histogram)r   r   Z	wall_timestepZbucketsZconverted_bucketsr   r   r   r   [   s    

zDistributionsPlugin._compressc                 C   s   | j j||dS )Nr   )r
   
index_impl)r   r    r   r   r   r   r'   `   s    zDistributionsPlugin.index_implc                 C   s4   t |j}t |j}| j||d}t||dS )Nr&   zapplication/json)r   r   environexperiment_idr'   r   Respond)r   requestr    r   indexr   r   r   r   c   s    zDistributionsPlugin.tags_routec                 C   sT   t |j}t |j}|jd}|jd}| j||||d\}}t|||S )zMGiven a tag and single run, return an array of compressed
        histograms.r!   r"   r&   )	r   r   r(   r)   argsgetr$   r   r*   )r   r+   r    r   r!   r"   bodyr#   r   r   r   r   j   s    
z'DistributionsPlugin.distributions_routeN)__name__
__module____qualname____doc__r   ZPLUGIN_NAMEr   r   r   r   r   r   r   r$   r   r'   r   RequestZapplicationr   r   r   r   r   r   r	       s   
r	   N)r3   Zwerkzeugr   Ztensorboardr   Ztensorboard.backendr   Ztensorboard.pluginsr   Z tensorboard.plugins.distributionr   r   Ztensorboard.plugins.histogramr   ZTBPluginr	   r   r   r   r   <module>   s   