o
    ۷iw                     @  s   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dddZe G dd deZdS )zgr.State() component.    )annotationsN)Callable)deepcopy)Any)document)	Component)Eventsxr   returnNonec                 C     d S N )r	   r   r   M/home/ubuntu/vllm_env/lib/python3.10/site-packages/gradio/components/state.pydefault_delete_callback      r   c                      s   e Zd ZejgZ	 dZ		d$dddd% fddZed&ddZ	d'ddZ
d(ddZd)ddZd*ddZd*ddZedd Z fd d!Zd&d"d#Z  ZS )+StateFNT)time_to_livedelete_callbackvaluer   renderboolr   int | float | Noner   Callable[[Any], None] | Nonec             
     sz   |du rt jn| | _| _|pt| _zt|}W n ty/ } ztdt| d|d}~ww t j	||d || _
dS )a:  
        Parameters:
            value: the initial value (of arbitrary type) of the state. The provided argument is deepcopied. If a callable is provided, the function will be called whenever the app loads to set the initial value of the state.
            render: should always be True, is included for consistency with other components.
            time_to_live: the number of seconds the state should be stored for after it is created or updated. If None, the state will be stored indefinitely. Gradio automatically deletes state variables after a user closes the browser tab or refreshes the page, so this is useful for clearing state for potentially long running sessions.
            delete_callback: a function that is called when the state is deleted. The function should take the state value as an argument.
        NzYThe initial value of `gr.State` must be able to be deepcopied. The initial value of type z cannot be deepcopied.)r   r   )mathinfr   r   r   r   	TypeErrortypesuper__init__r   )selfr   r   r   r   err	__class__r   r   r       s   


zState.__init__r
   c                 C     dS NTr   r    r   r   r   stateful<      zState.statefulpayloadc                 C     |S )z
        Parameters:
            payload: Value
        Returns:
            Passes a value of arbitrary type through.
        r   )r    r)   r   r   r   
preprocess@      zState.preprocessc                 C  r*   )z
        Parameters:
            value: Expects a value of arbitrary type, as long as it can be deepcopied.
        Returns:
            Passes a value of arbitrary type through.
        r   )r    r   r   r   r   postprocessI   r,   zState.postprocessdict[str, Any]c                 C  s
   i ddS )Nzany valid json)r   descriptionr   r&   r   r   r   api_infoR   s   
zState.api_infoc                 C  r   r   r   r&   r   r   r   example_payloadU   r   zState.example_payloadc                 C  r   r   r   r&   r   r   r   example_valueX   r   zState.example_valuec                 C  r$   r%   r   r&   r   r   r   skip_api[   r(   zState.skip_apic                   s   t   }|d= |S )Nr   )r   
get_config)r    configr"   r   r   r4   _   s   
zState.get_configc                 C  r$   )z:State components should not break wrapper grouping chains.Fr   r&   r   r   r   breaks_groupingd   r(   zState.breaks_groupingr%   )r   r   r   r   r   r   r   r   )r
   r   )r)   r   r
   r   )r   r   r
   r   )r
   r.   )r
   r   )__name__
__module____qualname__r   changeEVENTSallow_string_shortcutr   propertyr'   r+   r-   r0   r1   r2   r3   r4   r6   __classcell__r   r   r"   r   r      s*    

	
	


r   )r	   r   r
   r   )__doc__
__future__r   r   collections.abcr   copyr   typingr   gradio_client.documentationr   gradio.components.baser   gradio.eventsr   r   r   r   r   r   r   <module>   s    
