
    AF[i                         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
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 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_selfvalueundocumented)r   everyinputsvariantsizeiconlinklink_targetvisibleinteractiveelem_idelem_classesrenderkeypreserved_by_keyscale	min_widthapi_nameapi_visibilityc                   t         |   ||||||||	|
||||||||       || _        || _        t	               r| j                  |       yy)a  
        Parameters:
            value: default text for the button to display. If a function is provided, the function will be called each time the app loads to set the initial value of this component.
            every: continuously 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.
            variant: sets the background and text color of the button. Use 'primary' for main call-to-action buttons, 'secondary' for a more subdued style, 'stop' for a stop button, 'huggingface' for a black background with white text, consistent with Hugging Face's button styles.
            size: size of the button. Can be "sm", "md", or "lg".
            icon: URL or path to the icon file to display within the button. If None, no icon will be displayed.
            link: URL to open when the button is clicked. If None, no link will be used.
            visible: If False, component will be hidden. If "hidden", component will be visually hidden and not take up space in the layout but still exist in the DOM
            interactive: if False, the Button will be in a disabled state.
            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.
            scale: relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.
            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.
        )r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   N)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*   r+   	__class__s                        g/var/www/html/chatbot/moweb-chatbot/venv/lib/python3.12/site-packages/gradio/components/clear_button.pyr.   zClearButton.__init__    ss    V 	##%-# 	 	
& !,HHZ       c                R   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                  d       |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() => private)jsr*   r+   c                 @    t        j                  t                     S N)copydeepcopyr   )initial_statess   r2   <lambda>z!ClearButton.add.<locals>.<lambda>   s    &7&GH r3   )r*   r+   )gradio.componentsr5   
isinstancer   appendr:   r;   r   postprocessr   r   
model_dumpjsondumpsclickr*   r+   )	r/   r0   r5   none_valuesstate_components	componentnoneclear_valuesr<   s	           @r2   r   zClearButton.addd   s"    	, Kj),$J# 	%I)U+ ''	2%%dmmIOO&DE((.D$o >?(t$	% zz+.

~&]]$ 	 	
 JJH #22   r3   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     r2   
preprocesszClearButton.preprocess   s	     r3   c                    |S )z
        Parameters:
            value: string corresponding to the button label
        Returns:
            Expects a `str` value that is set as the button label
        rL   )r/   r   s     r2   rA   zClearButton.postprocess   s	     r3   c                     yNr   rL   r/   s    r2   example_payloadzClearButton.example_payload       r3   c                     yrQ   rL   rR   s    r2   example_valuezClearButton.example_value   rT   r3   r9   )(r0   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    z-Literal['_self', '_blank', '_parent', '_top']r!   zbool | Literal['hidden']r"   boolr#   rX   r$   list[str] | str | Noner%   rY   r&   z(int | str | tuple[int | str, ...] | Noner'   rZ   r(   
int | Noner)   r[   r*   rX   r+   z,Literal['public', 'private', 'undocumented'])r0   z&None | Component | Sequence[Component]returnr   )rM   rX   r\   rX   )r   rX   r\   rX   )r\   r   )__name__
__module____qualname____doc__is_templater.   r   rN   rA   rS   rV   __classcell__)r1   s   @r2   r   r      sT    K >BB! &*JN;F*."&EL,0 "/38<3:  $#GU-B!:B! 	B!
 $B! HB! 9B! (B!  B! B! CB! *B! B! B! -B!  !B!" 6#B!$ 1%B!& 'B!( )B!* +B!, E-B!H*Xr3   r   )r`   
__future__r   r:   rC   collections.abcr   pathlibr   typingr   r   r   gradio_client.documentationr	   r>   r
   r   gradio.contextr   gradio.data_classesr   r   gradio.utilsr   r   r   rL   r3   r2   <module>rk      sT    _ "   $  . . 0 / - < *' 
%O& O Or3   