o
    ٷi                     @  s   d Z ddlmZ ddlZddlZddlmZ ddl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mZ ddlmZ e
rPddlmZ edG dd deZdS )zYPredefined buttons with bound events that can be included in a gr.Blocks for convenience.    )annotationsN)Sequence)Path)TYPE_CHECKINGAnyLiteral)document)Button	Component)get_blocks_context)GradioModelGradioRootModel)resolve_singleton)Timeraddc                      s   e Zd ZdZdZ	d:ddddddddddddddddddd	d; fd*d+Zd<d.d/Zd=d1d2Zd>d3d4Zd?d6d7Z	d?d8d9Z
  ZS )@ClearButtonaH  
    Button that clears the value of a component or a list of components when clicked. It is instantiated with the list of components to clear.
    Preprocessing: passes the button value as a {str} into the function
    Postprocessing: expects a {str} to be returned from a function, which is set as the label of the button
    TNClear	secondarylgvalueF)r   everyinputsvariantsizeiconlinkvisibleinteractiveelem_idelem_classesrenderkeypreserved_by_keyscale	min_widthapi_nameshow_api
components&None | Sequence[Component] | Componentstrr   Timer | float | Noner   7Component | Sequence[Component] | set[Component] | Noner   'Literal['primary', 'secondary', 'stop']r   Literal['sm', 'md', 'lg']r   str | Path | Noner   
str | Noner   bool | Literal['hidden']r   boolr   r   list[str] | str | Noner    r!   (int | str | tuple[int | str, ...] | Noner"   r#   
int | Noner$   r%   str | None | Literal['False']r&   c                  sT   t  j|f|||||||	|
|||||||d || _|| _t r(| | d S d S )N)r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   )super__init__r%   r&   r   r   )selfr'   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   	__class__ R/home/ubuntu/.local/lib/python3.10/site-packages/gradio/components/clear_button.pyr7       s0   zClearButton.__init__&None | Component | Sequence[Component]returnc                   s   ddl m} |s
| S t|tr|g}g }g }g  |D ]*}t||r/||  t|j |d}t|t	t
fr?| }|| qt|}| jdg |d| | j| jd |rl| j fddd|| j| jd | S )	z
        Adds a component or list of components to the list of components that will be cleared when the button is clicked.
        r   )StateNz() => )jsr%   r&   c                     s   t t S N)copydeepcopyr   r;   initial_statesr;   r<   <lambda>s   s    z!ClearButton.add.<locals>.<lambda>)r%   r&   )gradio.componentsr?   
isinstancer
   appendrB   rC   r   postprocessr   r   
model_dumpjsondumpsclickr%   r&   )r8   r'   r?   none_valuesstate_components	componentnoneclear_valuesr;   rD   r<   r   O   sD   





zClearButton.addpayloadc                 C     |S )z
        Parameters:
            payload: string corresponding to the button label
        Returns:
            (Rarely used) the `str` corresponding to the button label when the button is clicked
        r;   )r8   rT   r;   r;   r<   
preprocess{      zClearButton.preprocessc                 C  rU   )z
        Parameters:
            value: string corresponding to the button label
        Returns:
            Expects a `str` value that is set as the button label
        r;   )r8   r   r;   r;   r<   rJ      rW   zClearButton.postprocessr   c                 C     dS Nr   r;   r8   r;   r;   r<   example_payload      zClearButton.example_payloadc                 C  rX   rY   r;   rZ   r;   r;   r<   example_value   r\   zClearButton.example_valuerA   )&r'   r(   r   r)   r   r*   r   r+   r   r,   r   r-   r   r.   r   r/   r   r0   r   r1   r   r/   r   r2   r    r1   r!   r3   r"   r2   r#   r4   r$   r4   r%   r5   r&   r1   )r'   r=   r>   r   )rT   r/   r>   r/   )r   r/   r>   r/   )r>   r   )__name__
__module____qualname____doc__is_templater7   r   rV   rJ   r[   r]   __classcell__r;   r;   r9   r<   r      s:    
/
,
	
	r   )ra   
__future__r   rB   rL   collections.abcr   pathlibr   typingr   r   r   gradio_client.documentationr   rG   r	   r
   gradio.contextr   gradio.data_classesr   r   gradio.utilsr   r   r   r;   r;   r;   r<   <module>   s     