
    ;3h                        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
rddlmZ  ed       G d de             Zy)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                       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
ZddZddZddZddZ	ddZ
 x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_apic                   t         |   ||||||||	|
|||||||       || _        || _        t	               r| j                  |       y y )N)r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   )super__init__r'   r(   r   r   )self
componentsr   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   	__class__s                       ^/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/components/clear_button.pyr+   zClearButton.__init__    sn    . 	#%-! 	 	
$ ! HHZ       c                f   ddl m} |s| S t        |t              r|g}g }g }g |D ]  }t        ||      r?|j	                  |       j	                  t        j                  |j                               |j                  d      }t        |t        t        f      r|j                         }|j	                  |        t        j                  |      }| j                  dg |d| | j                  | j                          |r-| j                  fdd|| j                  | j                          | 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                 @    t        j                  t                     S N)copydeepcopyr   )initial_statess   r/   <lambda>z!ClearButton.add.<locals>.<lambda>s   s    &7&GH r0   )r'   r(   )gradio.componentsr2   
isinstancer   appendr6   r7   r   postprocessr   r   
model_dumpjsondumpsclickr'   r(   )	r,   r-   r2   none_valuesstate_components	componentnoneclear_valuesr8   s	           @r/   r   zClearButton.addO   s$    	, Kj),$J# 	%I)U+ ''	2%%dmmIOO&DE((.D$o >?(t$	% zz+.

~&]]]] 	 	
 JJH    r0   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,   payloads     r/   
preprocesszClearButton.preprocess{   s	     r0   c                    |S )z
        Parameters:
            value: string corresponding to the button label
        Returns:
            Expects a `str` value that is set as the button label
        rH   )r,   r   s     r/   r=   zClearButton.postprocess   s	     r0   c                     yNr   rH   r,   s    r/   example_payloadzClearButton.example_payload       r0   c                     yrM   rH   rN   s    r/   example_valuezClearButton.example_value   rP   r0   r5   )&r-   z&None | Sequence[Component] | Componentr   strr   zTimer | float | Noner   z7Component | Sequence[Component] | set[Component] | Noner   z'Literal['primary', 'secondary', 'stop']r   zLiteral['sm', 'md', 'lg']r   zstr | Path | Noner   
str | Noner   boolr   rU   r    rT   r!   list[str] | str | Noner"   rU   r#   z(int | str | tuple[int | str, ...] | Noner$   rV   r%   
int | Noner&   rW   r'   zstr | None | Literal['False']r(   rU   )r-   z&None | Component | Sequence[Component]returnr   )rI   rT   rX   rT   )r   rT   rX   rT   )rX   r   )__name__
__module____qualname____doc__is_templater+   r   rJ   r=   rO   rR   __classcell__)r.   s   @r/   r   r      s/    K >B-! &*JN;F*."& "/38<3:  $26+-!:-! 	-!
 $-! H-! 9-! (-!  -! -! -! -! -! --! -!  6!-!" 1#-!$ %-!& '-!( 0)-!* +-!^*Xr0   r   )r\   
__future__r   r6   r?   collections.abcr   pathlibr   typingr   r   r   gradio_client.documentationr	   r:   r
   r   gradio.contextr   gradio.data_classesr   r   gradio.utilsr   r   r   rH   r0   r/   <module>rg      sT    _ "   $  . . 0 / - < *' 
%z& z zr0   