o
    e!                     @  s   d Z ddlmZ ddlmZ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 ddlmZmZ ddlmZmZmZmZ dd	lmZ e	d
 e G dd deeeeeee	ZdS )zgr.Radio() component.    )annotations)AnyCallableLiteral)documentset_documentation_group)StringSerializable)FormComponentIOComponent	_Keywords)warn_deprecationwarn_style_method_deprecation)
ChangeableEventListenerMethod	Inputable
Selectable)NeighborInterpretable	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Zd d! Zd<d$d%Zeej	dddddddddf
d=d'd(Z
d>d+d,Zd-d. Zd?d2d3Zddd4d@d6d7Zd8d9 ZdS )ARadioa  
    Creates a set of (string or numeric type) radio buttons of which only one can be selected.
    Preprocessing: passes the value of the selected radio button as a {str} or {int} or {float} or its index as an {int} into the function, depending on `type`.
    Postprocessing: expects a {str} or {int} or {float} corresponding to the value of the radio button to be selected.
    Examples-format: a {str} representing the radio option to select.

    Demos: sentence_builder, titanic_survival, blocks_essay
    NvalueT   )r   typelabelinfoevery
show_label	containerscale	min_widthinteractivevisibleelem_idelem_classeschoices>list[str | int | float | tuple[str, str | int | float]] | None#str | int | float | Callable | Noner   strr   
str | Noner   r   float | Noner   bool | Noner   boolr   
int | Noner   intr   r    r!   r"   list[str] | str | Nonec                K  s   |r	dd |D ng | _ ddg}||vrtd| d| || _|  	 tj| f||||||	|
|||||d| t|  dS )	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 callable, the function will be called whenever the app loads to set the initial value of the 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: Component name in interface.
            info: Additional component description.
            every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.
            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.
        c                 S  &   g | ]}t |tr|nt||fqS  
isinstancetupler&   .0cr/   r/   GD:\Projects\ConvertPro\env\Lib\site-packages\gradio/components/radio.py
<listcomp>J      & z"Radio.__init__.<locals>.<listcomp>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   N)r#   
ValueErrorr   r
   __init__r   )selfr#   r   r   r   r   r   r   r   r   r   r   r    r!   r"   kwargsZvalid_typesr/   r/   r6   r;   %   s>   &zRadio.__init__c                 C  s   | j | jdt| S )N)r#   r   )r#   r   r
   
get_configr<   r/   r/   r6   r>   l   s
   zRadio.get_configreturndict[str, Any]c                 C  s6   | j r
| j d d nd | j r| j d d dS d dS )Nr      )rawZ
serialized)r#   r?   r/   r/   r6   example_inputss   s
   zRadio.example_inputs6str | int | float | Literal[_Keywords.NO_VALUE] | Nonec
           
      C  s6   |d u rd ndd |D }|||||||||	| ddS )Nc                 S  r.   r/   r0   r3   r/   r/   r6   r7      r8   z Radio.update.<locals>.<listcomp>update)r#   r   r   r   r   r   r   r   r    r   Z__type__r/   )
r   r#   r   r   r   r   r   r   r   r    r/   r/   r6   rF   y   s    zRadio.updatexstr | int | float | Nonec                 C  s\   | j dkr|S | j dkr%|du rdS dd | jD }||v r#||S dS td| j  d)z
        Parameters:
            x: selected choice
        Returns:
            value of the selected choice as string or index within choice list
        r   r9   Nc                 S     g | ]\}}|qS r/   r/   r4   _r   r/   r/   r6   r7          z$Radio.preprocess.<locals>.<listcomp>zUnknown type: z'. Please choose from: 'value', 'index'.)r   r#   r9   r:   )r<   rG   Zchoice_valuesr/   r/   r6   
preprocess   s   

zRadio.preprocessc                 C  s"   dd | j D }|| |i fS )Nc                 S  rI   r/   r/   rJ   r/   r/   r6   r7      rL   z6Radio.get_interpretation_neighbors.<locals>.<listcomp>)r#   remove)r<   rG   r#   r/   r/   r6   get_interpretation_neighbors   s   
z"Radio.get_interpretation_neighborsscoreslist[float | None]listc                 K  s&   dd | j D }|||d |S )zs
        Returns:
            Each value represents the interpretation score corresponding to each choice.
        c                 S  rI   r/   r/   rJ   r/   r/   r6   r7      rL   z3Radio.get_interpretation_scores.<locals>.<listcomp>N)r#   insertr9   )r<   rG   Z	neighborsrP   r=   r#   r/   r/   r6   get_interpretation_scores   s   zRadio.get_interpretation_scores)item_containerr   rU   c                K  s(   t   |durtd |dur|| _| S )zc
        This method is deprecated. Please set these arguments in the constructor instead.
        Nz-The `item_container` parameter is deprecated.)r   r   r   )r<   rU   r   r=   r/   r/   r6   style   s   
zRadio.stylec                   s   t  fdd| jD d S )Nc                 3  s$    | ]}|d   kr|d V  qdS )rB   r   Nr/   r3   
input_datar/   r6   	<genexpr>   s   " z#Radio.as_example.<locals>.<genexpr>)nextr#   )r<   rX   r/   rW   r6   
as_example   s   zRadio.as_example)N)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@   rA   )r   rE   r#   r$   r   r'   r   r'   r   r)   r   r)   r   r+   r   r+   r   r)   r    r)   )rG   rH   r@   rH   )rP   rQ   r@   rR   )rU   r)   r   r)   )__name__
__module____qualname____doc__r;   r>   rD   staticmethodr   ZNO_VALUErF   rM   rO   rT   rV   r[   r/   r/   r/   r6   r      sN    
G

#
r   N)r_   
__future__r   typingr   r   r   Zgradio_client.documentationr   r   Zgradio_client.serializingr   Zgradio.components.baser	   r
   r   Zgradio.deprecationr   r   Zgradio.eventsr   r   r   r   Zgradio.interpretationr   r   r/   r/   r/   r6   <module>   s(    

