
    ;3h                        d Z ddlm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  e        G d de             Zy)zgr.Radio() component.    )annotations)CallableSequence)TYPE_CHECKINGAnyLiteral)document)	ComponentFormComponent)Events)Error)I18nData)Timerc                      e Zd ZdZej
                  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 fdZ	dd	Z
dd
ZddZddZddZ xZS )Radioz
    Creates a set of (string or numeric type) radio buttons of which only one can be selected.

    Demos: sentence_builder, blocks_essay
    NvalueT   F)r   typelabelinfoeveryinputs
show_label	containerscale	min_widthinteractivevisibleelem_idelem_classesrenderkeypreserved_by_keyrtlc                  |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        | %  ||||||	|
|||||||||       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 select from. An option can also be a tuple of the form (name, value), where name is the displayed name of the radio button and value is the value to be passed to the function, or returned by the function.
            value: The option selected by default. If None, no option is selected by default. 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.
            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 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.
            interactive: If True, choices in this radio group 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 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.
            rtl: If True, the radio buttons will be displayed in right-to-left order. Default is False.
        r   indexz$Invalid value for parameter `type`: z. Please choose from one of: )r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r   zone of    N)
isinstancetupleliststrchoices
ValueErrorr   r$   super__init___value_description)selfr,   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   cvalid_types	__class__s                         W/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/components/radio.pyr/   zRadio.__init__   s   d  QXX1At}5U1XCFA;FX 	 ({"6tf<YZeYfg  	!#%-! 	 	
& DLLQqz!U3qt:QRS 	; Y< Rs   5CC
c                B    | j                   r| j                   d   d   S d S Nr   r'   r,   r1   s    r5   example_payloadzRadio.example_payloado        %)\\t||Aq!;t;    c                B    | j                   r| j                   d   d   S d S r7   r8   r9   s    r5   example_valuezRadio.example_valuer   r;   r<   c                &   |y| j                   D cg c]  \  }}|	 }}}||vrt        d|dt        |       d|       | j                  dk(  r|S | j                  dk(  r|j                  |      S t	        d| j                   d      c c}}w )	z
        Parameters:
            payload: Selected choice in the radio group
        Returns:
            Passes the value of the selected radio button as a `str | int | float`, or its index as an `int` into the function, depending on `type`.
        NzValue: z (type: z!) is not in the list of choices: r   r&   zUnknown type: z'. Please choose from: 'value', 'index'.)r,   r   r   r&   r-   )r1   payload_r   choice_valuess        r5   
preprocesszRadio.preprocessu   s     ?/3||<81e<<-''HT']O;\]j\kl  99NYY'! &&w// +RS  =s   Bc                    |S )z
        Parameters:
            value: Expects a `str | int | float` corresponding to the value of the radio button to be selected
        Returns:
            The same value
         )r1   r   s     r5   postprocesszRadio.postprocess   s	     r<   c                N    | j                   D cg c]  }|d   	 c}dddS c c}w )Nr'   r   string)enumtitler   r8   )r1   r2   s     r5   api_infozRadio.api_info   s+    #'<<0aQqT0
 	
0s   ")N)&r,   zBSequence[str | int | float | tuple[str, str | int | float]] | Noner   z#str | int | float | Callable | Noner   zLiteral['value', 'index']r   str | I18nData | Noner   rL   r   zTimer | float | Noner   z7Component | Sequence[Component] | set[Component] | Noner   bool | Noner   boolr   z
int | Noner   intr   rM   r   rN   r   z
str | Noner    list[str] | str | Noner!   rN   r"   z(int | str | tuple[int | str, ...] | Noner#   rP   r$   rN   )returnr   )r@   str | int | float | NonerQ   rR   )r   rR   rQ   rR   )rQ   zdict[str, Any])__name__
__module____qualname____doc__r   selectchangeinputEVENTSr/   r:   r>   rC   rF   rK   __classcell__)r4   s   @r5   r   r      sW    mmV]]FLL9F
 P

 6:*1'+&*&*JN"& #'"/38<3:-P
P

 3P
 (P
 %P
 $P
 $P
 HP
  P
 P
 P
 P
 !P
  !P
" #P
$ -%P
& 'P
( 6)P
* 1+P
, -P
d<<2
r<   r   N)rV   
__future__r   collections.abcr   r   typingr   r   r   gradio_client.documentationr	   gradio.components.baser
   r   gradio.eventsr   gradio.exceptionsr   gradio.i18nr   gradio.componentsr   r   rE   r<   r5   <module>re      sI     " . . . 0 ;   #  ' 
H
M H
 H
r<   