
    ;3h.                        d Z ddlmZ ddlZddlmZmZ ddlmZm	Z	m
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 erddlmZ  G d d      Z e       Z e        G d de             Zy)zgr.Dropdown() component.    )annotationsN)CallableSequence)TYPE_CHECKINGAnyLiteral)document)	ComponentFormComponent)Events)Error)I18nData)Timerc                      e Zd Zy)DefaultValueN)__name__
__module____qualname__     Z/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/components/dropdown.pyr   r      s     	r   r   c                  r    e Zd ZdZej
                  ej                  ej                  ej                  ej                  ej                  gZ	 de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dd
ZddZ	 	 	 	 ddZd Z	 	 	 	 ddZ xZS )Dropdownz
    Creates a dropdown of choices from which a single entry or multiple entries can be selected (as an input component) or displayed (as an output component).

    Demos: sentence_builder
    NvalueFT   )r   typemultiselectallow_custom_valuemax_choices
filterablelabelinfoeveryinputs
show_label	containerscale	min_widthinteractivevisibleelem_idelem_classesrenderkeypreserved_by_keyc                  |r<|D cg c]0  }t        |t        t        f      rt        |      nt        |      |f2 c}ng | _        ddg}||vrt        d| d|       || _        || _        |t        k(  r&|rg }n!| j                  r| j                  d   d   }nd}|rt        |t              r|g}|s|t        j                  d       |s|rd	}t        j                  d
       || _        || _        || _        t        | =  ||	|
|||||||||||||       d|rdnd d| j                  D cg c]  }t        |t              r|d   n| c} | _        yc c}w c c}w )a  
        Parameters:
            choices: a list of string or numeric options to choose from. An option can also be a tuple of the form (name, value), where name is the displayed name of the dropdown choice and value is the value to be passed to the function, or returned by the function.
            value: the value selected in dropdown. If `multiselect` is true, this should be list, otherwise a single string or number from among `choices`. By default, the first choice in `choices` is initally selected. If set explicitly to None, no value is initally selected. If a function is provided, the function will be called each time the app loads to set the initial value of this component.
            type: type of value to be returned by component. "value" returns the string of the choice selected, "index" returns the index of the choice selected.
            multiselect: if True, multiple choices can be selected.
            allow_custom_value: if True, allows user to enter a custom value that is not in the list of choices.
            max_choices: maximum number of choices that can be selected. If None, no limit is enforced.
            filterable: if True, user will be able to type into the dropdown and filter the choices by typing. Can only be set to False if `allow_custom_value` is False.
            label: the label for this component, displayed above the component if `show_label` is `True` and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component corresponds to.
            info: additional component description, appears below the label in smaller font. Supports markdown / HTML syntax.
            every: continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.
            inputs: components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.
            show_label: if True, will display label.
            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.
            interactive: if True, choices in this dropdown will be selectable; if False, selection will be disabled. If not provided, this is inferred based on whether the component is used as an input or output.
            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 be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
        r   indexz$Invalid value for parameter `type`: z. Please choose from one of: r      NzCThe `max_choices` parameter is ignored when `multiselect` is False.TzrThe `filterable` parameter cannot be set to False when `allow_custom_value` is True. Setting `filterable` to True.)r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r   onez or more z of )
isinstancetupleliststrchoices
ValueErrorr   r   DEFAULT_VALUEwarningswarnr   r   r    super__init___value_description)selfr9   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   cvalid_types	__class__s                            r   r?   zDropdown.__init__/   s   x  QXX1At}5U1XCFA;FX 	 ({"6tf<YZeYfg  	&M!Q*:eS1GE{6MMU 0JMM E '"4$!#%-! 	 	
$ %(k
r'J$  ~B  ~J  ~J  PKxyXbcdfkXlPQRSPTrsPs  PK  OL  #Mi Yh PKs   5E0E
c                    | j                   r%dd| j                  D cg c]  }|d   	 c}dd}|S d| j                  D cg c]  }|d   	 c}d}|S c c}w c c}w )Narraystringr2   )r   enum)r   itemsr   r9   )rA   rB   	json_types      r   api_infozDropdown.api_info   sm    "*4<<4PaQqT4PQI  !'+||4!14I  5Q
 5s   AAc                    | j                   r!| j                  r| j                  d   d   gS g S | j                  r| j                  d   d   S d S Nr   r2   rJ   rA   s    r   example_payloadzDropdown.example_payload   J    +/<<DLLOA&'?R?)-4<<?1%?4?r   c                    | j                   r!| j                  r| j                  d   d   gS g S | j                  r| j                  d   d   S d S rN   rJ   rO   s    r   example_valuezDropdown.example_value   rQ   r   c           	        |y| j                   D cg c]  \  }}|	 }}}| j                  sNt        |t              r)|D ]#  }||vst	        d|dt        |       d|        n||vrt	        d| d|       | j
                  dk(  r|S | j
                  dk(  rLt        |t              r%|D cg c]  }||v r|j                  |      nd c}S ||v r|j                  |      S dS t        d| j
                   d	      c c}}w c c}w )
a  
        Parameters:
            payload: the value of the selected dropdown choice(s)
        Returns:
            Passes the value of the selected dropdown choice as a `str | int | float` or its index as an `int` into the function, depending on `type`. Or, if `multiselect` is True, passes the values of the selected dropdown choices as a list of corresponding values/indices instead.
        NzValue: z (type: z!) is not in the list of choices: z  is not in the list of choices: r   r1   zUnknown type: z'. Please choose from: 'value', 'index'.)r9   r   r5   r7   r   r   r1   r:   )rA   payload_r   choice_valueschoices         r   
preprocesszDropdown.preprocess   sO    ?/3||<81e<<&&'4($ EM1#%eYhtE{mCderdst 
 -gY&F}oV  99NYY'!'4( #* 4:]3JM''/PTT  5<}4LM''0RV  +RS 5 ="s   D0Dc                    | j                   s!|| j                  D cg c]  \  }}|	 c}}v ry t        j                  d d       y c c}}w )NzqThe value passed into gr.Dropdown() is not in the list of choices. Please update the list of choices to include: z  or set allow_custom_value=True.)r   r9   r<   r=   )rA   r   rV   s      r   _warn_if_invalid_choicez Dropdown._warn_if_invalid_choice   sX    ""edll/S(!U/S&S  AF  @G  Gg  h	
 0Ts   A	c                    |y| j                   r4t        |t              s|g}|D cg c]  }| j                  |       c} |S | j                  |       |S c c}w )aS  
        Parameters:
            value: Expects a `str | int | float` corresponding to the value of the dropdown entry to be selected. Or, if `multiselect` is True, expects a `list` of values corresponding to the selected dropdown entries.
        Returns:
            Returns the values of the selected dropdown entry or entries.
        N)r   r5   r7   r[   )rA   r   _ys      r   postprocesszDropdown.postprocess   s`     =eT*8=>"T))"->  ((/ ?s   A)N),r9   zBSequence[str | int | float | tuple[str, str | int | float]] | Noner   zPstr | int | float | Sequence[str | int | float] | Callable | DefaultValue | Noner   zLiteral['value', 'index']r   bool | Noner   boolr   
int | Noner    r`   r!   str | I18nData | Noner"   rb   r#   zTimer | float | Noner$   z7Component | Sequence[Component] | set[Component] | Noner%   r_   r&   r`   r'   ra   r(   intr)   r_   r*   r`   r+   z
str | Noner,   list[str] | str | Noner-   r`   r.   z(int | str | tuple[int | str, ...] | Noner/   rd   )returnzdict[str, Any])re   r   )rU   2str | int | float | list[str | int | float] | Nonere   zEstr | int | float | list[str | int | float] | list[int | None] | None)r   rf   re   rf   )r   r   r   __doc__r   changeinputselectfocusblurkey_upEVENTSr;   r?   rL   rP   rS   rY   r[   r^   __classcell__)rD   s   @r   r   r      s    	F oM *1#'#("&'+&*&*JN"& #'"/38<3:?oMoM
oM (oM !oM !oM  oM  !oM" %#oM$ $%oM& $'oM( H)oM*  +oM, -oM. /oM0 1oM2 !3oM4 5oM6 7oM8 -9oM: ;oM< 6=oM> 1?oMb@@(I(	N(T
G	;r   r   )rg   
__future__r   r<   collections.abcr   r   typingr   r   r   gradio_client.documentationr	   gradio.components.baser
   r   gradio.eventsr   gradio.exceptionsr   gradio.i18nr   gradio.componentsr   r   r;   r   r   r   r   <module>ry      s_     "  . . . 0 ;   #  '	 	  
\} \ \r   