o
    e7                     @  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                   @  sn   e Zd ZdZ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$Z	d0d(d)Z
d1d,d-ZdS )2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_widthr   
str | None
componentslist[IOComponent] | list[str]r   list[list[Any]] | Noner   list[str] | Noner   Literal['values', 'index']r   intr   boolr   r   list[str] | str | Noner   r   
int | Noner   c                K  s  t j| f|||	d| |
| _|| _|| _dd |D | _tdd | jD s,J ddd | jD | _| jD ]}| j|_q8|du rFg gn|| _| jD ]}t	t
| j|D ]\}\}}||||< qVqL|| _|| _|durs|| _ntd	d | jD rg | _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 |qS  )r   .0cr(   r(   ID:\Projects\ConvertPro\env\Lib\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(   r0   r)   r(   r(   r,   r-   I   s    Nc                 s  s    | ]}|j d u V  qd S r/   r   r)   r(   r(   r,   r2   U   s    c                 S  s   g | ]}|j pd qS ) r3   r)   r(   r(   r,   r-   X   s    )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,   r5      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)r9   r(   r(   r,   r=   [   s   
zDataset.get_config(Any | Literal[_Keywords.NO_VALUE] | Nonebool | Nonec                 C  s   | |||||ddS )Nupdate)r   r   r   r   r   r   __type__r(   )r   r   r   r   r   r   r(   r(   r,   r@   i   s   
zDataset.updatexr   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   )r9   rB   r(   r(   r,   
preprocess|   s
   


zDataset.preprocesslist[list[Any]]dictc                 C  s
   |ddS )Nr@   )r   rA   r(   )r9   r   r(   r(   r,   postprocess   s   zDataset.postprocess)r   r   r   r    r   r!   r   r"   r   r#   r   r$   r   r%   r   r   r   r&   r   r%   r   r'   r   r$   )r   r>   r   r?   r   r   r   r?   r   r'   r   r'   )rB   r   rC   r   )r   rF   rC   rG   )__name__
__module____qualname____doc__r5   r=   staticmethodr
   ZNO_VALUEr@   rE   rH   r(   r(   r(   r,   r      s2    
=
	r   N)rL   
__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    