a
    dE                     @  s   d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZmZmZmZ ddlmZmZ ed e G d	d
 d
eeee
ZdS )zgr.Dataset() component.    )annotations)AnyLiteral)documentset_documentation_group)StringSerializable)	ComponentIOComponent	_Keywordsget_component_instance)	Clickable
Selectable	componentc                   @  s   e Zd ZdZdddddddddddddd	d
ddddddddddddZdd ZeejdddddfdddddddddZ	dddddZ
dd d!d"d#ZdS )$Dataseta9  
    Used to create an output widget for showing datasets. Used to render the examples
    box.
    Preprocessing: passes the selected sample either as a {list} of data (if type="value") or as an {int} index (if type="index")
    Postprocessing: expects a {list} of {lists} corresponding to the dataset data.
    Nvalues
   T   )labelsamplesheaderstypesamples_per_pagevisibleelem_idelem_classes	containerscale	min_widthz
str | Nonezlist[IOComponent] | list[str]zlist[list[Any]] | Nonezlist[str] | NonezLiteral['values', 'index']intboolzlist[str] | str | Nonez
int | None)r   
componentsr   r   r   r   r   r   r   r   r   r   c                K  s   t j| f|||	d| |
| _|| _|| _dd |D | _tdd | jD sXJ ddd | jD | _| jD ]}| j|_qp|du rg gn|| _| jD ]0}t	t
| j|D ]\}\}}||||< qq|| _|| _|dur|| _n0td	d | jD rg | _nd
d | jD | _|| _dS )a)  
        Parameters:
            components: Which component types to show in this dataset widget, can be passed in as a list of string names or Components instances. The following components are supported in a Dataset: Audio, Checkbox, CheckboxGroup, ColorPicker, Dataframe, Dropdown, File, HTML, Image, Markdown, Model3D, Number, Radio, Slider, Textbox, TimeSeries, Video
            samples: a nested list of samples. Each sublist within the outer list represents a data sample, and each element within the sublist represents an value for each component
            headers: Column headers in the Dataset widget, should be the same len as components. If not provided, inferred from component labels
            type: 'values' if clicking on a sample should pass the value of the sample, or "index" if it should pass the index of the sample
            samples_per_page: how many examples to show per page.
            visible: If False, component will be hidden.
            elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
            elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
            container: If True, will place the component in a container - providing some extra padding around the border.
            scale: relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.
            min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
        )r   r   r   c                 S  s   g | ]}t |d dqS )F)render)r   .0c r%   b/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/gradio/components/dataset.py
<listcomp>C       z$Dataset.__init__.<locals>.<listcomp>c                 s  s   | ]}t |tV  qd S N
isinstancer	   r"   r%   r%   r&   	<genexpr>F   s   z#Dataset.__init__.<locals>.<genexpr>zAAll components in a `Dataset` must be subclasses of `IOComponent`c                 S  s   g | ]}t |tr|qS r%   r*   r"   r%   r%   r&   r'   I   r(   Nc                 s  s   | ]}|j d u V  qd S r)   r   r"   r%   r%   r&   r,   U   r(   c                 S  s   g | ]}|j pd qS ) r-   r"   r%   r%   r&   r'   X   r(   )r   __init__r   r   r   r    allZroot_urlr   	enumeratezipZ
as_exampler   r   r   r   )selfr   r    r   r   r   r   r   r   r   r   r   r   kwargsr   Zexampleiexr%   r%   r&   r/      s>    



zDataset.__init__c              
   C  s>   dd | j D | j| j| j| j| j| j| j| jd	t	
| S )Nc                 S  s   g | ]}|  qS r%   )Zget_block_name)r#   r   r%   r%   r&   r'   ]   r(   z&Dataset.get_config.<locals>.<listcomp>)	r    r   r   r   r   r   r   r   r   )r    r   r   r   r   r   r   r   r   r   
get_config)r3   r%   r%   r&   r7   [   s    
zDataset.get_configz(Any | Literal[_Keywords.NO_VALUE] | Nonezbool | Noner   r   r   r   r   r   c                 C  s   | |||||ddS )Nupdate)r   r   r   r   r   r   __type__r%   r8   r%   r%   r&   r9   i   s    
zDataset.updater   )xreturnc                 C  s&   | j dkr|S | j dkr"| j| S dS )zM
        Any preprocessing needed to be performed on function input.
        indexr   N)r   r   )r3   r;   r%   r%   r&   
preprocess|   s    

zDataset.preprocesszlist[list[Any]]dict)r   r<   c                 C  s
   |ddS )Nr9   )r   r:   r%   )r3   r   r%   r%   r&   postprocess   s    zDataset.postprocess)__name__
__module____qualname____doc__r/   r7   staticmethodr
   ZNO_VALUEr9   r>   r@   r%   r%   r%   r&   r      s0   
(=	r   N)rD   
__future__r   typingr   r   Zgradio_client.documentationr   r   Zgradio_client.serializingr   Zgradio.components.baser   r	   r
   r   Zgradio.eventsr   r   r   r%   r%   r%   r&   <module>   s   