
    ;3hX                        d dl 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 d dlmZ d dlmZ d dlmZmZ d dlmZmZ d d	lmZmZ erd d
lmZ  G d d      Z e       	 	 ddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zy)    )annotations)CallableSequence)TYPE_CHECKINGLiteralUnioncast)document)Block)	Component)ContextLocalContext)EventListenerEventListenerMethod)ColumnRow)EventListenerCallablec                  :    e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd Zy)
Renderablec	                   t         j                  t        d      t        t         j                  j                        | _        t         j                  j                  j                  |        t        t         j                  t              rt        nt        | _        | j                  d      | _        | j                  j
                  | _        || _        || _        g | _        t         j                  j"                  | _        i | _        |D 	cg c]
  }	t)        |	  c}	| _        t         j                  j*                  j-                  | j                   | j.                  | j                  | j                  d||| |d||       y c c}	w )N0Reactive render must be inside a Blocks context.T)show_progressF)show_apiconcurrency_limitconcurrency_id
renderabletrigger_modepostprocessqueuer   )r   
root_block
ValueErrorlenrenderables_idappend
isinstanceblockr   r   ContainerClass	containercontainer_idfninputstriggerscurrent_pagepagekey_to_id_mapr   default_configset_event_triggerapply)
selfr+   r,   r-   r   r   r   r   r   ts
             Q/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/renderable.py__init__zRenderable.__init__   s-    %OPPw))556&&--d3%/s%Cc,,4,@ NN..35&&33	FH:BCQ,a0C));;MMJJKKNN/)%' 	< 	
 Ds   Fc                   t         j                  j                         }|t        d      g }|j                  j                         D ]%  \  }}|j                  | u s|j                  |       ' |D ]  }|j                  |=  | j                  dd      }| j                  |_
        | j                  |_        t         j                  j                  |        t         j                  j                  | j                         	 |5   | j                  |i | ||j                   | j                  <   |j#                  |        d d d        t         j                  j                  d        t         j                  j                  d        y # 1 sw Y   HxY w# t         j                  j                  d        t         j                  j                  d        w xY w)Nz.Reactive render must be inside a LocalContext.FT)renderr   )r   blocks_configgetr!   fnsitemsrendered_inr%   r(   r*   r$   r/   r   setr0   r+   blocksattach_load_events)r4   argskwargsr:   !fn_ids_to_remove_from_last_renderr$   r+   container_copys           r6   r3   zRenderable.apply=   s   $22668 MNN,.)$((..0 	>GC~~%188=	> 5 	'C!!#&	' ,,E,N!.."ii##D)""&&t'9'9:	1 7((:H$$T%6%670067
 ##''-&&**407 7
 ##''-&&**40s%   F =FF FF A GN)r+   r   r,   zSequence[Component]r-   zlist[tuple[Block | None, str]]r   int | None | Literal['default']r   
str | Noner   1Literal['once', 'multiple', 'always_last'] | Noner   boolr   $Literal['full', 'minimal', 'hidden'])__name__
__module____qualname__r7   r3        r6   r   r      s\    (
(
 $(
 1	(

 ;(
 #(
 H(
 (
 <(
T1rO   r   NTalways_lastfull)r   r   r   r   r   c               Z    t        t        t        t           t        df   |      }t        j
                  t        d      t         t              r gn g n  g |;t        j
                  dfg D ]"  }t        |d      sj                  |df       $ nJt        |t              r|gn|}|D 	cg c])  }	|	j                  rt        |	dd      nd|	j                  f+ c}	|r/|D ]*  }
|
j                  s|
j                  |
j                         ,  fd}|S c c}	w )a  
    The render decorator allows Gradio Blocks apps to have dynamic layouts, so that the components and event listeners in your app can change depending on custom logic.
    Attaching a @gr.render decorator to a function will cause the function to be re-run whenever the inputs are changed (or specified triggers are activated). The function contains the components and event listeners that will update based on the inputs.

    The basic usage of @gr.render is as follows:

    1. Create a function and attach the @gr.render decorator to it.

    2. Add the input components to the `inputs=` argument of @gr.render, and create a corresponding argument in your function for each component.

    3. Add all components inside the function that you want to update based on the inputs. Any event listeners that use these components should also be inside this function.

    Parameters:
        inputs: List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.
        triggers: List of triggers to listen to, e.g. [btn.click, number.change]. If None, will listen to changes to any inputs.
        queue: If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app.
        trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete.
        concurrency_limit: If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
        concurrency_id: If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
    Example:
        import gradio as gr

        with gr.Blocks() as demo:
            input_text = gr.Textbox()

            @gr.render(inputs=input_text)
            def show_split(text):
                if len(text) == 0:
                    gr.Markdown("## No Input Provided")
                else:
                    for letter in text:
                        with gr.Row():
                            text = gr.Textbox(letter)
                            btn = gr.Button("Clear")
                            btn.click(lambda: gr.Textbox(value=""), None, text)
    Nr   loadchange__self__c           
     ,    t        |        | S )N)r   )r+   	_triggersr   r   r,   r   r   r   s    r6   wrapper_functionz render.<locals>.wrapper_function   s*    		
 	rO   )r	   r   listr   r   r    r!   r&   r   hasattrr%   has_triggergetattr
event_namecallbackrU   )r,   r-   r   r   r   r   r   new_triggersinputr5   triggerrX   rW   s   ` `````     @r6   r9   r9   Y   s8   V d=1=$FGRL!KLL vy1V^rQW  13I((&12	 	4Euh'  %!23	4
 )}E\N< 	
 "
 ./]]WQ
D)allS
	
 # 	3G  !1!12	3  /
s   9.D()NN)r,   z&Sequence[Component] | Component | Noner-   z>Sequence[EventListenerCallable] | EventListenerCallable | Noner   rI   r   rH   r   rF   r   rG   r   rJ   )
__future__r   collections.abcr   r   typingr   r   r   r	   gradio_client.documentationr
   gradio.blocksr   gradio.componentsr   gradio.contextr   r   gradio.eventsr   r   gradio.layoutsr   r   r   r   r9   rN   rO   r6   <module>rk      s    " . 6 6 0  ' 0 < &3D1 D1N 
59OSS FS9=!%:@S2SLS 	S
 DS 7S S 8S SrO   