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.CheckboxGroup() component    )annotations)AnyCallableLiteral)documentset_documentation_group)ListStringSerializable)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dAd0d1Zd2d3 Zd4d5 Zddd6dBd8d9Zd:d; ZdS )CCheckboxGroupa  
    Creates a set of checkboxes of which a subset can be checked.
    Preprocessing: passes the list of checked checkboxes as a {List[str | int | float]} or their indices as a {List[int]} into the function, depending on `type`.
    Postprocessing: expects a {List[str | int | float]}, each element of which becomes a checked checkbox.
    Examples-format: a {List[str | int | float]} representing the values to be checked.
    Demos: sentence_builder, titanic_survival
    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=list[str | float | int] | str | float | int | Callable | Noner   Literal['value', 'index']r   
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 checkbox button and value is the value to be passed to the function, or returned by the function.
            value: Default selected list of options. If a single choice is selected, it can be passed in as a string or numeric type. 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 list of strings of the choices selected, "index" returns the list of indices of the choices 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 checkbox group will be checkable; if False, checking 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tuplestr.0cr/   r/   OD:\Projects\ConvertPro\env\Lib\site-packages\gradio/components/checkboxgroup.py
<listcomp>I      & z*CheckboxGroup.__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/   r7   r<   $   s>   &zCheckboxGroup.__init__c                 C  s   | j | jdt| S )N)r#   r   )r#   r   r
   
get_configr=   r/   r/   r7   r?   k   s
   zCheckboxGroup.get_configreturndict[str, Any]c                 C  s:   | j r| j d d gnd | j r| j d d gdS d dS )Nr      )rawZ
serialized)r#   r@   r/   r/   r7   example_inputsr   s
   zCheckboxGroup.example_inputsBlist[str | int | float] | str | Literal[_Keywords.NO_VALUE] | Nonec
           
      C  s6   |d u rd ndd |D }|||||||||	| ddS )Nc                 S  r.   r/   r0   r4   r/   r/   r7   r8      r9   z(CheckboxGroup.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/   r7   rG   x   s    zCheckboxGroup.updatexlist[str | int | float]*list[str | int | float] | list[int | None]c                   sL   | j dkr|S | j dkrdd | jD   fdd|D S td| j  d)z
        Parameters:
            x: list of selected choices
        Returns:
            list of selected choice values as strings or indices within choice list
        r   r:   c                 S     g | ]\}}|qS r/   r/   r5   _r   r/   r/   r7   r8          z,CheckboxGroup.preprocess.<locals>.<listcomp>c                   s"   g | ]}| v r  |nd qS N)r:   )r5   choiceZchoice_valuesr/   r7   r8      s    zUnknown type: z'. Please choose from: 'value', 'index'.)r   r#   r;   )r=   rH   r/   rQ   r7   
preprocess   s   
	

zCheckboxGroup.preprocessy2list[str | int | float] | str | int | float | Nonec                 C  s    |du rg S t |ts|g}|S )z
        Parameters:
            y: List of selected choice values. If a single choice is selected, it can be passed in as a string
        Returns:
            List of selected choices
        N)r1   list)r=   rS   r/   r/   r7   postprocess   s
   	
zCheckboxGroup.postprocessc                 C  sR   g }dd | j D D ]}t|}||v r|| n|| || q
|i fS )Nc                 S  rK   r/   r/   rL   r/   r/   r7   r8      rN   z>CheckboxGroup.get_interpretation_neighbors.<locals>.<listcomp>)r#   rU   removeappend)r=   rH   Zleave_one_out_setsrP   Zleave_one_out_setr/   r/   r7   get_interpretation_neighbors   s   
z*CheckboxGroup.get_interpretation_neighborsc           	      K  sJ   g }t dd | jD |D ]\}}||v r|dgnd|g}|| q|S )z
        Returns:
            For each tuple in the list, the first value represents the interpretation score if the input is False, and the second if the input is True.
        c                 S  rK   r/   r/   rL   r/   r/   r7   r8      rN   z;CheckboxGroup.get_interpretation_scores.<locals>.<listcomp>N)zipr#   rX   )	r=   rH   Z	neighborsZscoresr>   Zfinal_scoresrP   ZscoreZ	score_setr/   r/   r7   get_interpretation_scores   s
   z'CheckboxGroup.get_interpretation_scores)item_containerr   r\   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=   r\   r   r>   r/   r/   r7   style   s   
zCheckboxGroup.stylec                   s\   |d u rd S t |ts|g}|D ]}|dd  jD vr$td| dq fdd|D S )Nc                 S  s   g | ]}|d  qS )r   r/   r4   r/   r/   r7   r8      rN   z,CheckboxGroup.as_example.<locals>.<listcomp>zExample z provided not a valid choice.c                   s&   g | ] t  fd djD dqS )c                 3  s$    | ]}|d   kr|d V  qdS )rC   r   Nr/   r4   datar/   r7   	<genexpr>   s   " z6CheckboxGroup.as_example.<locals>.<listcomp>.<genexpr>N)nextr#   )r5   r@   r^   r7   r8      s    )r1   rU   r#   r;   )r=   Z
input_datar_   r/   r@   r7   
as_example   s   

zCheckboxGroup.as_examplerO   )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   rB   )r   rF   r#   r$   r   r'   r   r'   r   r)   r   r)   r   r+   r   r+   r   r)   r    r)   )rH   rI   rA   rJ   )rS   rT   rA   rI   )r\   r)   r   r)   )__name__
__module____qualname____doc__r<   r?   rE   staticmethodr   ZNO_VALUErG   rR   rV   rY   r[   r]   rb   r/   r/   r/   r7   r      sP    

G

"
r   N)rf   
__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/   r7   <module>   s(    

