
    ;3h(                        d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZmZ dd	lmZ dd
lmZ  e
        G d de             Zy)zgr.Dataset() component.    )annotationsN)Sequence)AnyLiteral)document)processing_utils)	Componentget_component_instance)Events)I18nDatac                       e Zd ZdZej
                  ej                  gZddddddddddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Zdd
Z	 fdZ
ddZddZddZddZ xZS )Datasetz
    Creates a gallery or table to display data samples. This component is primarily designed for internal use to display examples.
    However, it can also be used directly to display a dataset and let users select examples.
    NTvalues
   value   )label
show_label
componentscomponent_propssamplesheaderstypelayoutsamples_per_pagevisibleelem_idelem_classesrenderkeypreserved_by_key	containerscale	min_width	proxy_urlsample_labelsc          	        t         |   |
|||||       || _        || _        || _        || _        || _        |xs g D cg c]  }t        |       c}| _        |?| j                  D cg c]#  }|j                  |j                         dg      % c}| _        n|| _        t        d | j                  D              st        d      | j                  D cg c]  }t        |t              s| c}| _        || _        | j                  D ]	  }||_         |g gn|| _        g | _        | j"                  D ]  }| j$                  j'                  g        t)        | j                  |d      D ]V  \  }}| j                   |j+                  |      }| j$                  d   j'                  t-        j.                  ||d	
             X  || _        || _        ||| _        nQt        d | j                  D              rg | _        n-| j                  D cg c]  }|j2                  xs d c}| _        |	| _        || _        yc c}w c c}w c c}w c c}w )aT  
        Parameters:
            label: the label for this component, appears above the component.
            show_label: If True, the label will be shown above the component.
            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, "index" if it should pass the index of the sample, or "tuple" if it should pass both the index and the value of the sample.
            layout: "gallery" if the dataset should be displayed as a gallery with each sample in a clickable card, or "table" if it should be displayed as a table with each sample in a row. By default, "gallery" is used if there is a single component, and "table" is used if there are more than one component. If there are more than one component, the layout can only be "table".
            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.
            render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
            key: in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render.
            preserved_by_key: A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.
            container: If True, will place the component in a container - providing some extra padding around the border.
            scale: relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.
            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.
            proxy_url: The URL of the external Space used to load this component. Set automatically when using `gr.load()`. This should not be set manually.
            sample_labels: A list of labels for each sample. If provided, the length of this list should be the same as the number of samples, and these labels will be used in the UI instead of rendering the sample values.
        )r   r   r   r   r    r!   Nr   c              3  <   K   | ]  }t        |t                y wN)
isinstancer	   .0cs     Y/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/components/dataset.py	<genexpr>z#Dataset.__init__.<locals>.<genexpr>e   s     F:a+Fs   z?All components in a `Dataset` must be subclasses of `Component`F)strictT)keep_in_cachec              3  8   K   | ]  }|j                   d u   y wr)   )r   r+   s     r.   r/   z#Dataset.__init__.<locals>.<genexpr>   s     ;QD;s    )super__init__r"   r#   r$   r   r   r
   _componentsrecover_kwargs
get_configr   all	TypeErrorr*   r	   r%   raw_samplesr   appendzip
as_exampler   move_files_to_cacher   r   r   r   r&   )selfr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r-   	componentexampleex	__class__s                            r.   r6   zDataset.__init__   sX   \ 	%- 	 	
 #
"$?I?ORP!215P" "&!1!1$
 	 ((((*I$D  $3D  FT5E5EFFQ  (,'7'7T!:a;SAT")) 	,I"+I	,#*?B4#%'' 	GLL#!$T%5%5wu!M 	2 >>) #--b1BR ''$88IT	" 	
"DL;$*:*:;;DL373C3CDaAGGMrMDDL 0*c Q$ U< Es   I,(II/IIc                    dddS )Nintegerzindex of selected example)r   description rA   s    r.   api_infozDataset.api_info   s    !2MNN    c                   t         |          }g |d<   | j                  |d<   | j                  |d<   g |d<   | j                  D ]B  }|d   j                  |j                                |d   j                  |j                         D |S )Nr   r   r&   component_ids)r5   r9   r   r&   r7   r=   get_block_name_id)rA   configrB   rE   s      r.   r9   zDataset.get_config   s    #%!|$($8$8 !"&"4"4"$)) 	:I< ''	(@(@(BC?#**9==9	:
 rL   c                    |y| j                   dk(  r|S | j                   dk(  r| j                  |   S | j                   dk(  r|| j                  |   fS y)ab  
        Parameters:
            payload: the index of the selected example in the dataset
        Returns:
            Passes the selected sample either as a `list` of data corresponding to each input component (if `type` is "value") or as an `int` index (if `type` is "index"), or as a `tuple` of the index and the data (if `type` is "tuple").
        Nindexr   tuple)r   r<   )rA   payloads     r.   
preprocesszDataset.preprocess   sa     ?99NYY("##G,,YY'!D,,W555 "rL   c                    |t        |t              r|S t        |t              r	 | j                  j	                  |      }|S y# t
        $ r d}t        j                  d       Y |S w xY w)a  
        Parameters:
            value: Expects an `int` index or `list` of sample data. Returns the index of the sample in the dataset or `None` if the sample is not found.
        Returns:
            Returns the index of the sample in the dataset.
        NzThe `Dataset` component does not support updating the dataset data by providing a set of list values. Instead, you should return a new Dataset(samples=...) object.)r*   intlistr   rS   
ValueErrorwarningswarn)rA   r   rS   s      r.   postprocesszDataset.postprocess   su     =Juc2LeT"**51 L #  j Ls   A  A('A(c                     y)Nr   rI   rJ   s    r.   example_payloadzDataset.example_payload   s    rL   c                    g S r)   rI   rJ   s    r.   example_valuezDataset.example_value   s    	rL   )(r   zstr | I18nData | Noner   boolr   z&Sequence[Component] | list[str] | Noner   zlist[dict[str, Any]] | Noner   zlist[list[Any]] | Noner   list[str] | Noner   z#Literal['values', 'index', 'tuple']r   z"Literal['gallery', 'table'] | Noner   rX   r   rb   r   
str | Noner   list[str] | str | Noner   rb   r    z(int | str | tuple[int | str, ...] | Noner!   re   r"   rb   r#   
int | Noner$   rX   r%   rd   r&   rc   )returnzdict[str, str])rU   rf   rg   z$int | list | tuple[int, list] | None)r   zint | list | Nonerg   rf   )rg   r   )__name__
__module____qualname____doc__r   clickselectEVENTSr6   rK   r9   rV   r]   r_   ra   __classcell__)rE   s   @r.   r   r      s\   
 llFMM*F
 (,=A7;*.$(4<59 ""/38<3:  $*.-l+ %l+ 	l+
 ;l+ 5l+ (l+ "l+ 2l+ 3l+ l+ l+ l+ -l+ l+  6!l+" 1#l+$ %l+& 'l+( )l+* +l+, (-l+\O6 (rL   r   )rk   
__future__r   r[   collections.abcr   typingr   r   gradio_client.documentationr   gradior   gradio.components.baser	   r
   gradio.eventsr   gradio.i18nr   r   rI   rL   r.   <module>rx      sG     "  $  0 # !   
pi p prL   