
    Fg@!             	         % S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKJr  S SKJrJrJrJrJr  S SKJr  S SKJr  S SKJrJ r J!r!J"r"J#r#  S SK$J%r%J&r&  S SK'r'S SK(r(S SK)r)S S	K'J*r*  S S
K+J,r-  S SK.J/r/  S SK0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J,r,J8r8  S SK9J:r:J;r;J<r<  S SK=J>r>J?r?J@r@JArAJBrB  S SKCJDrDJErEJFrFJGrGJHrHJIrI  S SKJJKrKJLrLJMrM  S SKNJOrOJPrPJQrQJRrR  S SKSJTrTJUrUJVrV  S SKWJXrX  S SKYJZrZJ[r[  S SK\J]r]J^r^J_r_J`r`  S SKaJbrbJcrc  S SKdJerf  S SKdJgrh  S SKiJjrjJkrkJlrlJmrmJnrn  S SKoJprpJqrqJrrrJsrsJtrtJuruJvrv   S SKwrw\(       a  S SKyJzrz  S SK{J|r|  \7R                  " 5       \7R                  " 5       \7R                  " 5       \7R                  " 5       \7GR                   " 5       \7GR                  " 5       \7GR                  " 5       \7GR                  " 5       4 V s0 s H  n U GR                  U _M     sn rS\S'    " S S 5      r " S! S"\5      r " S# S$5      r S1     S2S% jjr      S3S& jr " S' S(5      r\/" S)S*S+S,S-5       " S. S/\\;\<S095       rg! \x a    Srw GN"f = fs  sn f )4    )annotationsN)defaultdict)AsyncIteratorCallable	CoroutineSequenceSet)Path)
ModuleType)TYPE_CHECKINGAnyLiteralUnioncast)urlparse
urlunparse)CapacityLimiter)utils)document)		analytics
components
networkingprocessing_utilsqueueingstringsthemesr   
wasm_utils)BLOCKS_EVENTSBlocksEvents
BlocksMeta)ContextLocalContextget_blocks_contextget_render_contextset_render_context)BlocksConfigDictDeveloperPathFileDataGradioModelGradioRootModelLayout)	EventDataEventListenerEventListenerMethod)ChecksumMismatchErrorDuplicateBlockErrorInvalidApiNameErrorInvalidComponentError)create_trackerskipspecial_args)start_node_server)
API_PREFIXMediaStream)INTERNAL_ROUTESVERSIONAppRequest)SessionStateStateHolder)Default)
ThemeClass)BINARY_FILENAMEBINARY_FOLDERBINARY_PATH
BINARY_URLCURRENT_TUNNELS)TupleNoPrintcheck_function_inputs_matchcomponent_or_layout_classget_cancelled_fn_indicesget_node_pathget_package_versionget_upload_folder)	Component)
Renderablezdict[str, Theme]BUILT_IN_THEMESc                      \ rS rSrSSSSSSS.           SS jjr\SS j5       r\SS j5       r\SS j5       r\  SS	 j5       r	S
 r
S rSS jrSS jrSS jrS r\ S   SS jj5       r    SS jr    SS jr    SS jrSrg)Blockx   NT)elem_idelem_classesrenderkeyvisible	proxy_urlc                  [         R                  U l        [         =R                  S-  sl        XPl        Xl        [        U[        5      (       a  U/OUU l        X`l        [        R                  " S5      U l        S U l        S U l        U   SU l        U   SU l        [!        5       U l        [%        5       U l        X@l        [!        5       U l        SU l        U(       a  U R/                  5         g g )N       F'  )r!   id_idrW   rS   
isinstancestrrT   rX   secretstoken_urlsafeshare_tokenparentrendered_inis_renderedstate_session_capacityset
temp_filesrL   GRADIO_CACHErV   keep_in_cachehas_launchedrU   )selfrS   rT   rU   rV   rW   rX   s          ^/Users/admin/workspace/ai/PDFMathTranslate/myenv/lib/python3.13/site-packages/gradio/blocks.py__init__Block.__init__y   s     ::

a
(s;;\N 	 #"004+/.2!&&+#$'E-/ !U!KKM     c                    gNF rm   s    rn   statefulBlock.stateful       rq   c                    grs   rt   ru   s    rn   skip_apiBlock.skip_api   rx   rq   c                F    U R                   (       a  U R                   S   $ 0 $ )zlGet the arguments passed to the component's initializer.

Only set classes whose metaclass is ComponentMeta
r   )_constructor_argsru   s    rn   constructor_argsBlock.constructor_args   s"     -1,B,Bt%%a(JJrq   c                    [        U S/ 5      $ )NEVENTS)getattrru   s    rn   eventsBlock.events   s     tXr**rq   c                ,   [        5       n[        5       n[        R                  R	                  5       U l        Ub3  U R                  UR                  ;   a  [        SU R                   S35      eUb3  U(       a  UR                  R                  U l        UR                  U 5        Ubm  XR                  U R                  '   SU l        [        U [        R                   5      (       a/  UR                  R"                  R%                  U R&                  5        U $ )z)
Adds self into appropriate BlockContext
A block with id: 1 has already been rendered in the current Blocks.T)r#   r$   r"   
renderablegetre   r^   blocksr0   
root_blockcurrent_pagepageaddrf   r_   r   rM   temp_file_setsappendri   rm   root_contextrender_contexts      rn   rU   Block.render   s     *++-'22668#L4G4G(G%#DHH:-^_  %(33@@	t$#,0)#D$
 4 455''66==dooNrq   c                    [        5       n[        5       nUb   UR                  R                  U 5        Ub!   UR
                  U R                  	 SU l        U $ U $ ! [         a     N2f = f! [         a     U $ f = f)z
Removes self from BlockContext if it has been rendered (otherwise does nothing).
Removes self from the layout and collection of blocks, but does not delete any event triggers.
F)	r#   r$   childrenremove
ValueErrorr   r^   rf   KeyErrorr   s      rn   unrenderBlock.unrender   s    
 *++-%''..t4 # ''1#(  t    s"   A A* 
A'&A'*
A87A8c                    [        U S5      (       a.  U R                  R                  R                  R	                  5       $ U R                  R                  R	                  5       $ )a  
Gets block's class name. If it is template component it gets the parent's class name.
This is used to identify the Svelte file to use in the frontend. Override this method
if a component should use a different Svelte file than the default naming convention.
is_templatehasattr	__class____base____name__lowerru   s    rn   get_block_nameBlock.get_block_name   sQ     t]++ NN##,,224	
 ((..0	
rq   c                    [        U S5      (       a.  U R                  R                  R                  R	                  5       $ U R                  R                  R	                  5       $ )a  
Gets block's class name. If it is template component it gets the parent's class name.
Very similar to the get_block_name method, but this method is used to reconstruct a
Gradio app that is loaded from a Space using gr.load(). This should generally
NOT be overridden.
r   r   ru   s    rn   get_block_classBlock.get_block_class   sQ     t]++ NN##,,224	
 ((..0	
rq   c                    g Nrt   ru   s    rn   get_expected_parentBlock.get_expected_parent   s    rq   c                   0 n[         R                  " U R                  R                  5      nUR                  R                  5        Hs  n[        XR                  5      (       d  M  [        XR                  5      n[        R                  " U5      (       a  [        R                  " U5      nXAUR                  '   Mu     U R                   H"  nUR                  5       nU(       d  M  0 UEUEnM$     UR                  SS 5        0 UEU R                  U R!                  5       S.EnU R"                  b  U R"                  R$                  US'   S H  n[        XS 5      =nc  M  XU'   M     U$ )NrU   )rX   namere   )_selectable	_undoable
_retryablelikeable)inspect	signaturer   ro   
parametersvaluesr   r   r   dataclassesis_dataclassasdictr   config_datapoprX   r   re   r^   )	rm   configr   	parametervalueeto_addevent_attributeattributables	            rn   
get_configBlock.get_config   s/   %%dnn&=&=>	"--446It^^,,nn5++E22'..u5E).y~~& 7 A]]_Fv-F-f-  	

8T"XFXAUAUAWX'$($4$4$8$8F=!UO 't DDQ*6'  V rq   c                   U=(       d    / n[         R                  " U R                  5      n0 nUR                  R	                  5        HA  nUR
                  U;   d  M  UR
                  U;  d  M'  XR
                     XER
                  '   MC     U$ )z'
Recovers kwargs from a dict of props.
)r   r   ro   r   r   r   )clspropsadditional_keysr   kwargsr   s         rn   recover_kwargsBlock.recover_kwargs  sq     */R%%cll3	"--446I~~&9>>+P).~~)>~~& 7 rq   c                <  #    Uc  g[        U[        5      (       a  [        U5      n[        R                  " U5      (       aC  [
        R                  " XR                  S9I Sh  vN nU R                  R                  U5        U$ [        [        R                  " U5      5      n[        R                  " XR                  5      (       d    [
        R                  " XR                  S9nOUnU R                  R                  U5        U$  N! [         a    Us $ f = f7f)aa  Moves a file or downloads a file from a url to a block's cache directory, adds
to to the block's temp_files, and returns the path to the file in cache. This
ensures that the file is accessible to the Block and can be served to users.

This async version of the function is used when this is being called within
a FastAPI route, as this is not blocking.
N	cache_dir)r_   r
   r`   client_utilsis_http_url_liker   async_ssrf_protected_downloadrj   ri   r   r   abspathis_in_or_equalsave_file_to_cacheFileNotFoundErrorrm   url_or_file_pathtemp_file_paths      rn   "async_move_resource_to_block_cache(Block.async_move_resource_to_block_cache   s      #&--"#34(()9::#3#Q#Q ,=,=$ N OO/$ !  #5==1A#BC''(8:K:KLL	,%5%H%H(4E4E&N "2OO/- ) ,
 ,+,s7   A!D#D$A%D
D
 (!D
DDDDc                    Uc  g[        U[        5      (       a  [        U5      n[        R                  " U5      (       a;  [
        R                  " XR                  S9nU R                  R                  U5        U$ [        [        R                  " U5      5      n[        R                  " XR                  5      (       d    [
        R                  " XR                  S9nOUnU R                  R                  U5        U$ ! [         a    Us $ f = f)ap  Moves a file or downloads a file from a url to a block's cache directory, adds
to to the block's temp_files, and returns the path to the file in cache. This
ensures that the file is accessible to the Block and can be served to users.

This sync version of the function is used when this is being called outside of
a FastAPI route, e.g. when examples are being cached.
Nr   )r_   r
   r`   r   r   r   save_url_to_cacherj   ri   r   r   r   r   r   r   r   s      rn   move_resource_to_block_cache"Block.move_resource_to_block_cacheH  s     #&--"#34(()9::-?? ,=,=N OO/$ !  #5==1A#BC''(8:K:KLL	,%5%H%H(4E4E&N "2OO/ ) ,
 ,+,s    C> >DDc                <   Uc  g[        U[        5      (       a  U$ [        U[        5      (       a  [        U5      n[        R
                  " U5      (       a  [        XS9R                  5       $ USS0S.n [        R                  " X 5      $ ! [         a    Us $ f = f)a  If a file is a local file, moves it to the block's cache directory and returns
a FileData-type dictionary corresponding to the file. If the file is a URL, returns a
FileData-type dictionary corresponding to the URL. This ensures that the file is
accessible in the frontend and can be served to users.

Examples:
>>> block.serve_static_file("https://gradio.app/logo.png") -> {"path": "https://gradio.app/logo.png", "url": "https://gradio.app/logo.png"}
>>> block.serve_static_file("logo.png") -> {"path": "logo.png", "url": "/file=logo.png"}
>>> block.serve_static_file({"path": "logo.png", "url": "/file=logo.png"}) -> {"path": "logo.png", "url": "/file=logo.png"}
N)pathurl_typezgradio.FileData)r   meta)r_   dictr
   r`   r   r   r(   
model_dumpr   move_files_to_cacheAttributeError)rm   r   datas      rn   serve_static_fileBlock.serve_static_filep  s     #&--##&--"#34(()9::!1HSSUU,w@Q6RSD';;DGG! s   6B BB)rj   r^   rT   rS   rl   rf   rk   rV   r   rd   rX   re   rc   rg   ri   rW   )rS   
str | NonerT   list[str] | str | NonerU   boolrV   zint | str | NonerW   r   rX   r   )returnr   )r   dict[str, Any])r   zlist[EventListener]r   r`   )r   ztype[BlockContext] | Noner   )r   r   r   list[str] | None)r   zstr | Path | Noner   r   )r   zstr | Path | dict | Noner   zdict | None)r   
__module____qualname____firstlineno__ro   propertyrv   rz   r~   r   rU   r   r   r   r   r   classmethodr   r   r   r   __static_attributes__rt   rq   rn   rQ   rQ   x   s8    #/3 $ $" " -	"
 " " " "H     K K +	+ +
,(


, HL"5E & 1&	&P& 1&	&P 8	rq   rQ   c                      \ rS rSr    S       SS jjr\" S5      rSr\S 5       r	\
SS j5       r\S 5       rSS	 jrS
 rSS jrS rSSS jjrS rSrg)BlockContexti  Nc                @    / U l         [        R                  U UUUUS9  g)a  
Parameters:
    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 string or list of strings that are assigned as the class of this component in the HTML DOM. Can be used for targeting CSS styles.
    visible: If False, this will be hidden but included in the Blocks config file (its visibility can later be updated).
    render: If False, this will not be included in the Blocks config file at all.
)rS   rT   rW   rU   N)r   rQ   ro   )rm   rS   rT   rW   rU   s        rn   ro   BlockContext.__init__  s+     &(% 	 	
rq   z./templates/z../../frontend/c                    g)NTrt   ru   s    rn   rz   BlockContext.skip_api  s    rq   c                    U R                   n[        R                  U   R                  n[        R
                  " U R                   SU 3R                  5       5      R                  5       nU$ )N_)	r   sysmodules__file__hashlibsha256r   encode	hexdigest)r   module_namemodule_pathmodule_hashs       rn   get_component_class_id#BlockContext.get_component_class_id  sZ    nnkk+.77nn||nAk]+224

)+ 	 rq   c                "    U R                  5       $ r   )r
  ru   s    rn   component_class_idBlockContext.component_class_id  s    **,,rq   c                :    U R                   R                  U5        g r   )r   r   rm   childs     rn   	add_childBlockContext.add_child  s    U#rq   c                <    [        5       nXl        [        U 5        U $ r   )r$   rd   r%   rm   r   s     rn   	__enter__BlockContext.__enter__  s    +-$4 rq   c                F    Xl         U R                  R                  U5        g r   )rd   r   r   r  s     rn   r   BlockContext.add  s    U#rq   c                   [        5       n/ nS nU R                   H  nUR                  5       nU(       a  [        X5      (       a  S nUR	                  U5        M?  Ub"  [        X55      (       a  UR                  U5        O^U" SS9nXl        UR	                  U5        UR                  U5        UR                  Ul        U(       a  X1R                  UR                  '   X4l        M     X l        g )NF)rU   )
r#   r   r   r_   r   r  rd   r   r   r^   )rm   r   r   pseudo_parentr  expected_parents         rn   fill_expected_parents"BlockContext.fill_expected_parents  s    )+]]E#779O"j&G&G $& ,!2 2 "++E2$35$AM+/(OOM2!++E2).M&#AN++M,=,=>,% #& !rq   c                |    [        U R                  5        Ub  g [        U SS5      (       a  U R                  5         g g )Nallow_expected_parentsT)r%   rd   r   r  )rm   exc_typeargss      rn   __exit__BlockContext.__exit__  s8    4;;'41488&&( 9rq   c                    U$ )z?
Any postprocessing needed to be performed on a block context.
rt   )rm   ys     rn   postprocessBlockContext.postprocess  s	     rq   )r   rd   )NNTT)rS   r   rT   r   rW   r   rU   r   r   )r  rQ   r   r!  ztype[BaseException] | None)r   r   r   r   ro   r'   TEMPLATE_DIRFRONTEND_DIRr   rz   r   r
  r  r  r  r   r  r#  r'  r   rt   rq   rn   r   r     s     #/3

 -
 	

 
. !0L$L    - -$$!2)rq   r   c                      \ rS rSr                          S	                                                                   S
S jjrS rS rS rS rSr	g)BlockFunctioni  Nc#                P   Xl         Xl        X l        X0l        X@l        XPl        Xl        Xl        U=(       d    [        [        U5      5      U l
        Xl        Xl        SU l        SU l        X`l        Xpl        Ub  [#        USS5      OS U l        Xl        Xl        UU l        UU l        U=(       d    / U l        UU l        UU l        UU l        UU l        Uc  SOUU l        [:        R<                  " 5       (       a  SOUU l        UU l         [B        RD                  " U R                   5      =(       d     [B        RF                  " U R                   5      U l$        UU l%        UU l&        U"U l'        UU l(        UU l)        UU l*        UU l+        U U l,        U!U l-        U R]                  5         g )Nr   r   fnF)/r/  r^   inputsoutputs
preprocessr'  tracks_progressconcurrency_limitr`   r]   concurrency_idbatchmax_batch_sizetotal_runtime
total_runsinputs_as_dicttargetsr   r   api_namejsshow_progressshow_progress_oncancelscollects_event_datatrigger_aftertrigger_only_on_successtrigger_modequeuer   	get_spacescroll_to_outputshow_apir   isgeneratorfunctionisasyncgenfunctiontypes_generatorr   re   r   is_cancel_function
time_limitstream_every
connectionlike_user_messageevent_specific_argsspaces_auto_wrap)#rm   r/  r0  r1  r2  r'  r:  r;  r^   r6  r7  r4  r5  r3  r<  r=  r>  r?  r@  rA  rB  rC  rD  rE  rG  rH  r   re   rL  rO  rM  rN  rP  rQ  r   s#                                      rn   ro   BlockFunction.__init__  sx   J $&.BS,;BrF
,,57^GB
D1	 * 0}"#6 *'>$( jUe
).):):@P &::GG 
  1''0 	 %&	 #5$($!2#6 rq   c                    [         c  g [        R                  " 5       c  g [         R                  " U R                  5      U l        g r   )spacesr   rF  gradio_auto_wrapr/  ru   s    rn   rR  BlockFunction.spaces_auto_wrapA  s0    >??$))$''2rq   c                \    [        U R                  U R                  U R                  S.5      $ )N)r/  r2  r'  )r`   r   r2  r'  ru   s    rn   __str__BlockFunction.__str__H  s+    ii"oo#//
 	
rq   c                    [        U 5      $ r   )r`   ru   s    rn   __repr__BlockFunction.__repr__Q  s    4yrq   c                   0 SU R                   _SU R                  _SU R                   Vs/ s H  oR                   PM     sn_SU R                   Vs/ s H  oR                   PM     sn_SU R                  S L_SU R
                  _SU R                  _SU R                  _S	U R                  _S
U R                  _SU R                  c  S O%U R                   Vs/ s H  oR                   PM     sn_SU R                  _SU R                  _SU R                  _SU R                  U R                  S._SU R                   _SU R"                  _U R$                  U R&                  U R(                  U R*                  (       a  U R*                  R                   OS U R,                  U R.                  U R0                  U R2                  U R4                  S.	E$ s  snf s  snf s  snf )Nr]   r;  r0  r1  
backend_fnr=  rE  r<  rG  r>  r?  r6  r7  r@  types)	generatorcancelrA  rB  )	rC  rD  rH  re   rO  rM  rN  rP  rQ  )r^   r;  r0  r1  r/  r=  rE  r<  rG  r>  r?  r6  r7  r@  rK  rL  rA  rB  rC  rD  rH  re   rO  rM  rN  rP  rQ  )rm   blocks     rn   r   BlockFunction.get_configT  s    
$(( 
t|| 
 dkk:kUyyk: 
 t||<|e		|<	 

 $''- 
 $'' 
 TZZ 
  
  5 5 
 T// 
 $$, !%)-)>)>?)>)))>? 
 TZZ 
 d11 
  t||! 
" !1111# 
* "4#;#;+ 
, T//- 
. (,'C'C --373C3C4++////// --!%!7!7#'#;#;? 
  	
 ;< @s   GGG)&r^   r<  r6  r@  rA  r5  r4  rO  rQ  r/  r0  r:  rL  r=  rP  r7  r   r1  r   r'  r2  rE  r   re   rG  rH  r>  r?  rN  r;  rM  r9  r8  r3  rB  rD  rC  rK  )F   defaultNFFNfullNNFNFonceTFTNNFsseN      ?FN )Dr/  Callable | Noner0  "Sequence[Component | BlockContext]r1  rm  r2  r   r'  r   r:  r   r;  zlist[tuple[int | None, str]]r^   intr6  r   r7  rn  r4  int | None | Literal['default']r5  r   r3  r   r<  zstr | Literal[False]r=  r   r>  $Literal['full', 'minimal', 'hidden']r?  zSequence[Component] | Noner@  list[int] | NonerA  r   rB  
int | NonerC  r   rD  z*Literal['always_last', 'once', 'multiple']rE  r   rG  r   rH  r   r   Renderable | Nonere   rs  rL  r   rO  Literal['stream', 'sse']rM  float | NonerN  floatrP  r   rQ  r   r   r`   )
r   r   r   r   ro   rR  rY  r\  r   r   rt   rq   rn   r-  r-    s    =F%) %).>D7;$($)$((-CI!&(,)-#(/4#'!"'04GQ Q  3Q  4	Q 
 Q  Q  Q  .Q  Q  Q  Q  ;Q  #Q  Q  'Q   !Q " <#Q $ 5%Q & "'Q ( ")Q * "+Q , "&-Q . A/Q 0 1Q 2 3Q 4 5Q 6 &7Q 8 '9Q : !;Q < -=Q > !?Q @ AQ B  CQ D .EQ F GQ f3
!
rq   r-  c                   UR                  S[        R                  R                  5      nU Vs0 s H!  n[	        X5      (       d  M  U[        X5      _M#     nnU[        R                  R                  LaT  U(       aI  U R                  U5      US'   [        US   [        [        45      (       a  US   R                  5       US'   OX1S'   SUS'   U$ s  snf )a  
Converts a dictionary of updates into a format that can be sent to the frontend to update the component.
E.g. {"value": "2", "visible": True, "invalid_arg": "hello"}
Into -> {"__type__": "update", "value": 2.0, "visible": True}
Parameters:
    block: The Block that is being updated with this update dictionary.
    update_dict: The original update dictionary
    postprocess: Whether to postprocess the "value" key of the update dictionary.
r   update__type__)r   r   	_KeywordsNO_VALUEr   r   r'  r_   r)   r*   r   )rc  update_dictr'  r   ks        rn   postprocess_update_dictr~  x  s     OOGZ%9%9%B%BCE1<RA@Q'1ge''KRJ((111#(#4#4U#;K +g.o0NOO'27';'F'F'HG$#( &K
 Ss   CCc                   U Vs/ s H  n[        U[        5      PM     nn[        U5      (       a  U  Vs/ s H  n[        5       PM     nnUR	                  5        HC  u  pgUR
                  U ;  a  [        SU S35      eU R                  UR
                  5      nXuU'   ME     [        R                  " U5      nU$ [        U5      (       a  [        S5      eU$ s  snf s  snf )ai  
Converts a dictionary of component updates into a list of updates in the order of
the outputs_ids and including every output component. Leaves other types of dictionaries unchanged.
E.g. {"textbox": "hello", "number": {"__type__": "generic_update", "value": "2"}}
Into -> ["hello", {"__type__": "generic_update"}, {"__type__": "generic_update", "value": "2"}]
zReturned component z% not specified as output of function.zReturned dictionary included some keys as Components. Either all keys must be Components to assign Component values, or return a List of values to assign output values in order.)r_   rQ   allr4   itemsr^   r   indexr   resolve_singletonany)	outputs_idspredictionsrV   keys_are_blocksr   reordered_predictions	componentr   output_indexs	            rn   convert_component_dict_to_listr    s     :EE#z#u-OE
?1< =A = + 1 1 3I}}K/ ))4YZ  ',,Y]];L27,/ !4 --.CD
 	 
_		 @
 	
  F =s
   CCc                      \ rS rSrS	S jr                          S
                                                             SS jjrSSS jjrS rSSS jjrSr	g)BlocksConfigi  c                H    SU l         Xl        0 U l        0 U l        SU l        g )Nr   )r^   r   r   fnsfn_id)rm   r   s     rn   ro   BlocksConfig.__init__  s#    $46-/
rq   Nc           
        U Vs/ s H?  nU(       d'  UR                   (       a  UR                   R                  OSUR                  4PMA     n n[        U[        5      (       a  Sn![        US S9nO Sn!Uc  / nO[        U[        5      (       d  U/n[        U[        5      (       a  [        US S9nOUc  / nO[        U[        5      (       d  U/nU	(       a  [        U	[        5      (       d  U	/n	Ub  U(       d  [        X#U!5        [        U 5      (       a   Uc  U S   S   S	;   a  S
nOU S   S   S;   a  SnUc  SnOUS;  a  [        SU S/ SQ 35      eU(       a  UR                  OUn"U"(       a  [        U"5      OSu  n#n$n%U
b)  [        U
[        5      (       a  U
R                  5       S:X  a  Ub  [        US5      (       dF  [        US5      (       a2  [        UR                  S5      (       a  UR                  R                   n&OSn&OUR                   n&SR#                  U& V's/ s H)  n'U'[%        [&        R(                  5      SS1-
  ;  d  M'  U'PM+     sn'5      n
OUb  Sn
SnOSn
SnU
SLal  [*        R,                  " U
U R.                  R1                  5        Vs/ s H0  n[        UR2                  [        5      (       d  M$  UR2                  PM2     sn5      n
OSnUc  U%SLn[4        R6                  R9                  5       n([;        WUUUU40 SU R<                  _SU!_SU _SU_SU_SU_SU_S U$SL_S!U
_S"U_S#U_S$U	_S%U_S&U_S'U_S(U_S)U_S*U_S+U_S,U_S-U_S.U(_S/U_S0U_S1U_S2U_S3U_S4U_S5U R>                  R@                  _6n)U)U R.                  U R<                  '   U =R<                  S-  sl        U)U)R                  4$ s  snf s  sn'f s  snf )6a  
Adds an event to the component's dependencies.
Parameters:
    targets: a list of EventListenerMethod objects that define the event trigger
    fn: the function to run when the event is triggered
    inputs: the list of input components whose values will be passed to the function
    outputs: the list of output components whose values will be updated by the function
    preprocess: whether to run the preprocess methods of the input components before running the function
    postprocess: whether to run the postprocess methods of the output components after running the function
    scroll_to_output: whether to scroll to output of dependency on trigger
    show_progress: how to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "minimal" only shows the runtime display, "hidden" shows no progress animation at all
    show_progress_on: Component or list of components to show the progress animation on. If None, will show the progress animation on all of the output components.
    api_name: defines how the endpoint appears in the API docs. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given name. If None (default), the name of the function will be used as the API endpoint. If False, the endpoint will not be exposed in the API docs and downstream apps (including those that `gr.load` this app) will not be able to use this event.
    js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components
    no_target: if True, sets "targets" to [], used for the Blocks.load() event and .then() events
    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.
    batch: whether this function takes in a batch of inputs
    max_batch_size: the maximum batch size to send to the function
    cancels: a list of other events to cancel when this event is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method.
    collects_event_data: whether to collect event data for this event
    trigger_after: if set, this event will be triggered after 'trigger_after' function index
    trigger_only_on_success: if True, this event will only be triggered if the previous event was successful (only applies if `trigger_after` is set)
    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 `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.
    show_api: whether to show this event in the "view API" page of the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps as well as the Clients to use this event. If fn is None, show_api will automatically be set to False.
    is_cancel_function: whether this event cancels another running event.
    connection: The connection format, either "sse" or "stream".
    time_limit: The time limit for the function to run. Parameter only used for the `.stream()` event.
    stream_every: The latency (in seconds) at which stream chunks are sent to the backend. Defaults to 0.5 seconds. Parameter only used for the `.stream()` event.
Returns: dependency information, dependency index
NTc                    U R                   $ r   r^   xs    rn   <lambda>0BlocksConfig.set_event_trigger.<locals>.<lambda>  s    !%%rq   )rV   Fc                    U R                   $ r   r  r  s    rn   r  r    s    AEErq   r   rZ   )changekey_upalways_last)streammultiplerh  )rh  r  r  z,Invalid value for parameter `trigger_mode`: z. Please choose from: NNNrk  r   r   unnamed-r   js_fnr^   r:  r;  r6  r7  r4  r5  r3  r<  r=  r>  r?  r@  rA  rB  rC  rD  rE  rG  rH  r   re   rL  rO  rM  rN  rP  rQ  r   )!rc  r^   
event_namer_   r	   sortedr   rG   lenr   r/  r5   r`   stripr   r   r   joinrh   stringpunctuationr   append_unique_suffixr  r   r<  r"   r   r   r-  r  r   r   )*rm   r;  r/  r0  r1  r2  r'  rG  r>  r?  r<  r=  	no_targetrE  r6  r7  r@  rA  rB  rC  rD  r4  r5  rH  r   rL  rO  rM  rN  rP  rQ  target_targetsr:  fn_to_analyzer   progress_indexevent_data_indexr   sre   block_fns*                                             rn   set_event_triggerBlocksConfig.set_event_trigger  sq   f "

 " )2fll  !! " 	 
 fc""!NF8F"N~11 gs##W/:G_GGX..iGJ/?$J$J 01>''NCx==\1{1~!55,!Q:-)!L!DD>|nLb  dG  cH  I  *4
+8L'>P 	,>+
 z(C88X^^=MQS=S~r:..r;//GBLL*4U4U!||44(;;D77 $V1V5G5G1HCQT:1U(UQV " $ 5 11 #hhoo//!"++s3  BKK/H H
 &"2$">"--113 #
 

#
 *#
 #
 #
 *#
 0#
 *#
 +$6#
 #
 #
  (!#
" .##
$ %#
& !4'#
( ()#
* %<+#
, &-#
. /#
0 .1#
2 3#
4 "5#
6 $7#
8  29#
: ";#
< "=#
> &?#
@ 0A#
B !4C#
D --E#
J  (

a
%%{
r Ws   AN>!&OO#O
>O
c           
       ^^^ 0 / / S.nU R                   R                   H2  u  p4X2S   ;  d  M  U R                   R                  / S./ / S.US   U'   M4     / mS/mSUUU4S jjmU(       a  U R                  UR                     nOU R                   nT" U5      nXbS'   UR                  S/ 5       Hh  n[        U[        5      (       d  M  US	   U R                  ;   d  M/  U R                  US	      nUS   UR                     S   S   R                  U5        Mj     [        U R                  R                  5       5      n	U	 GH  u  pU(       a9  U
T;  a  M  UR                  (       a   UR                   S
UR                   3Ul        [        US5      (       a  UR                  5       O0 nU
UR                  5       [         R"                  " U5      UR$                  ['        USS 5      UR                  S.nU(       a  UR                  US'   UR$                  (       d  UR)                  5       US'   [        US5      (       a  UR+                  5       US'   OUR)                  5       US'   [        US5      (       a  UR-                  5       US'   OUR)                  5       US'   UR/                  5       US'   US   R                  U5        US   UR                     S   R                  UR                  5        GM     / nU R0                  R3                  5        H`  nUb  UR4                  U:X  d  M  UR                  5       nUR                  U5        US   UR                     S   R                  US	   5        Mb     XS'   U$ )N)r   r   dependenciesr   r]   r   )layoutr   r  r   c                z  > TR                  U R                  5        U R                  5       S:X  a,  TS==   S-  ss'   TS   S:  a  [        R                  " S5        [        U [        5      (       d  SU R                  0$ / nU R                   H  nT" U5      nUR                  U5        M     U R                  US.$ )Nsidebarr   rZ   zaMultiple sidebars detected in the same Blocks layout. Only one sidebar should be used per Blocks.r]   r  )r   r^   r   warningswarnr_   r   r   )rc  children_layoutr  r  
get_layoutrendered_idssidebar_counts       rn   r  +BlocksConfig.get_config.<locals>.get_layout  s    		*##%2a A%  #a'MM{ e\22eii(( O#E*&&v. (  ))AArq   r  r   r]   r  r   r  )r]   typer   rz   r  rV   r   api_infoapi_info_as_inputapi_info_as_outputexample_inputsr   r  )rc  rQ   r   r+   )r   pagesr^   r   container_idr   r_   r   r   r   listr  rV   r   r   r   r   delete_nonerz   r   r  r  r  r  r  r   re   )rm   r   r   r   r   r   r  
root_childrc  blocks_itemsr^   r   block_configr  r/  dependency_configr  r  r  s                   @@@rn   r   BlocksConfig.get_config  s&   
 ,,GD&>)%)__%8%8bI"$$&(vt$ - 	B 	B  Z%<%<=JJJ'!x **Z4J*d++
40@DKK0OJt$45vuzz*84Z@GG
S 5
 KK
 'JCl*99#->>"2!EII; ?EI*1%*F*FE$$&BE,,.**51!NN&-e5I4&PyyL -7^^\*>>+0>>+;Z(5"5668=8O8O8QL!458=8HL!455"6779>9Q9Q9SL!569>9IL!56161E1E1G-.< ''56N5::&|4;;EIIF; '> ((//#B!R^^z%A$&MMO!##$56vrww'7>>?PQU?VW	 $ ".~rq   c                    [        U R                  5      n[        R                  " U R                  5      Ul        [        R                  " U R                  5      Ul        U R
                  Ul        U$ r   )r  r   copyr   r  r  )rm   news     rn   __copy__BlocksConfig.__copy__  sH    4??+YYt{{+
))DHH%JJ	
rq   c           
        U R                   R                  5        H  nUb  UR                  U:w  a  M  [        U[        R
                  5      (       d  M9  UR                  (       d  ML  UR                  u  p4n[        U5      S:  nX@R                  S4/-  nU R                  U Vs/ s H  n[        U6 PM     snUUUU(       + U(       a  SOSS9S   nUR                  5       Ul        M     gs  snf )zYAdd a load event for every component whose initial value requires a function call to set.Nr   loadhiddenrg  )r  r>  )r   r   re   r_   r   rM   load_event_to_attachr  r   r  r.   r   
load_event)	rm   re   r  load_fntriggersr0  
has_targettriggerdeps	            rn   attach_load_eventsBlocksConfig.attach_load_events  s    ++-I&9+@+@K+O9j&:&:;;222,5,J,J)6 ]Q.
oov677 ,,BJK(w('2(K",n.8(f -   (+~~'7	$) . Ls   $C+
)r^   r   r  r  r   )r   Blocks)TTFrg  NNNFTFre  NNNFrh  rf  NTNFri  Nrj  FN)>r;  zSequence[EventListenerMethod]r/  rl  r0  dComponent | BlockContext | Sequence[Component | BlockContext] | Set[Component | BlockContext] | Noner1  r  r2  r   r'  r   rG  r   r>  rp  r?  z&Component | Sequence[Component] | Noner<  zstr | None | Literal[False]r=  r   r  r   rE  r   r6  r   r7  rn  r@  rq  rA  bool | NonerB  rr  rC  r   rD  z1Literal['once', 'multiple', 'always_last'] | Noner4  ro  r5  r   rH  r   r   rs  rL  r   rO  rt  rM  ru  rN  rv  rP  r   rQ  r   r   ztuple[BlockFunction, int]r   )r   rs  )re   rs  )
r   r   r   r   ro   r  r   r  r  r   rt   rq   rn   r  r    s   2   !&>DCG04$(+/$((-JP=F%)(,#(/4#'!"'04WK&.K& K&
K&K&$ %K&& 'K&( )K&* <+K&, A-K&. ./K&0 1K&2 3K&4 5K&6 7K&8 9K&: ";K&< )=K&> "?K&@ "&AK&B HCK&D ;EK&F #GK&H IK&J &KK&L !MK&N -OK&P !QK&R SK&T  UK&V .WK&X 
#YK&ZXt8 8rq   r  launchrE  	integrater  unloadc                    ^  \ rS rSrSr            S9                       S:U 4S jjjr\S;S j5       r\R                  S<S j5       r\S=S j5       r	S>S	 jr
\S
 5       r\        S?S j5       rS rS r\S 5       rS@S jrS rSASBS jjrSSS.SCS jjr      SD               SES jjrSFS jrSGS jrSHS jr SI       SJS jjrSKS jr        SLS jr  SM             SNS jjr SI             SOS jjr          SP                         SQS jjr      SRS  jrS! r S" r!SSS# jr"S$ r#STSUU 4S% jjjr$S& r%\&" 5          SVS'S(.       SWS) jjj5       r'S* r(           SXS+S,SSSSSS\)RT                  (       + SSSSS-SSSSSSSSSSSS..                                                                         SYS/ jjjr+   SZ     S[S0 jjr,S\S]S1 jjr-  S^S2 jr.S3 r/S4 r0SIS_S5 jjr1\2        S`S6 j5       r3\&" 5       STSaS7 jj5       r4S8r5U =r6$ )br  i  aB  
Blocks is Gradio's low-level API that allows you to create more custom web
applications and demos than Interfaces (yet still entirely in Python).


Compared to the Interface class, Blocks offers more flexibility and control over:
(1) the layout of components (2) the events that
trigger the execution of functions (3) data flows (e.g. inputs can trigger outputs,
which can trigger the next level of outputs). Blocks also offers ways to group
together related demos such as with tabs.


The basic usage of Blocks is as follows: create a Blocks object, then use it as a
context (with the "with" statement), and then define layouts, components, or events
within the Blocks context. Finally, call the launch() method to launch the demo.

Example:
    import gradio as gr
    def update(name):
        return f"Welcome to Gradio, {name}!"

    with gr.Blocks() as demo:
        gr.Markdown("Start typing below and then click **Run** to see the output.")
        with gr.Row():
            inp = gr.Textbox(placeholder="What is your name?")
            out = gr.Textbox()
        btn = gr.Button("Run")
        btn.click(fn=update, inputs=inp, outputs=out)

    demo.launch()
Demos: blocks_hello, blocks_flipper, blocks_kinematics
Guides: blocks-and-event-listeners, controlling-layout, state-in-blocks, custom-CSS-and-JS, using-blocks-like-functions
NFc           	       >^  ST l         Uc  [        5       nO\[        U[        5      (       aG  UR	                  5       [
        ;   a  [
        UR	                  5          nO [        R                  " U5      n[        U[        5      (       d   [        R                  " S5        [        5       nUT l        UR                  5       T l        UR                  T l        [         R"                  " 5       nUR%                  T R                  R'                  S5      5        UR)                  5       T l        ST l        ST l        ST l        ST l        [5        [6        5      T l        [5        [6        5      T l        ST l        U
T l        UT l         UT l!        / T l"        U=(       d    S	T l#        [H        RJ                  " U5      nU=(       d    /  H<  n[M        USS
9 nT =RF                  SURO                  5       -   -  sl#        SSS5        M>     U=(       d    S	T l(        U=(       d    S	T l)        [H        RJ                  " U	5      n	U	=(       d    /  H<  n[M        USS
9 nT =RR                  SURO                  5       -   -  sl)        SSS5        M>     / T l*        T   ST l+        ST l,        Ub  UO[Z        R\                  " 5       T l.        T R\                  (       aH  [^        R`                  (       d2  [b        Rd                  " [Z        Rf                  S9nURi                  5         OS[j        Rl                  S'   ST l7        [q        T 5      T l9        [t        TT ]  " SSS0UD6  UT l<        ST l=        ST l>        ST l?        ST l@        ST lA        [H        R                  " 5       SL T lC        [H        R                  " 5       T lD        ST lE        ST lF        [        [j        R                  " SS	5      5      T lI        [        R                  " S5      T lL        [        5       T lN        T R                  /T lO        UT lP        [^        R`                  (       + T lQ        ST lR        ST lS        ST lT        ST lU        ST lV        ST lW        ST lX        / T lY        / T lZ        [j        Rl                  R                  SS	5      T l\        [        5       T l]        S/T l^        S	T l_        T R\                  (       a|  [        U 4S j[
        R                  5        5       5      (       + nT Rx                  T RF                  SLT R                  R                  U[        5       S.n[Z        R                  " U5        T R                  5         g! [         a:  n[        R                  " SU S[        U5       35        [        5       n SnAGN)SnAff = f! , (       d  f       GM  = f! , (       d  f       GM  = f)av	  
Parameters:
    theme: A Theme object or a string representing a theme. If a string, will look for a built-in theme with that name (e.g. "soft" or "default"), or will attempt to load a theme from the Hugging Face Hub (e.g. "gradio/monochrome"). If None, will use the Default theme.
    analytics_enabled: Whether to allow basic telemetry. If None, will use GRADIO_ANALYTICS_ENABLED environment variable or default to True.
    mode: A human-friendly name for the kind of Blocks or Interface being created. Used internally for analytics.
    title: The tab title to display when this is opened in a browser window.
    css: Custom css as a code string. This css will be included in the demo webpage.
    css_paths: Custom css as a pathlib.Path to a css file or a list of such paths. This css files will be read, concatenated, and included in the demo webpage. If the `css` parameter is also set, the css from `css` will be included first.
    js: Custom js as a code string. The custom js should be in the form of a single js function. This function will automatically be executed when the page loads. For more flexibility, use the head parameter to insert js inside <script> tags.
    head: Custom html code to insert into the head of the demo webpage. This can be used to add custom meta tags, multiple scripts, stylesheets, etc. to the page.
    head_paths: Custom html code as a pathlib.Path to a html file or a list of such paths. This html files will be read, concatenated, and included in the head of the demo webpage. If the `head` parameter is also set, the html from `head` will be included first.
    fill_height: Whether to vertically expand top-level child components to the height of the window. If True, expansion occurs when the scale value of the child components >= 1.
    fill_width: Whether to horizontally expand to fill container fully. If False, centers and constrains app to a maximum width. Only applies if this is the outermost `Blocks` in your Gradio app.
    delete_cache: A tuple corresponding [frequency, age] both expressed in number of seconds. Every `frequency` seconds, the temporary files created by this Blocks instance will be deleted if more than `age` seconds have passed since the file was created. For example, setting this to (86400, 86400) will delete temporary files every day. The cache will be deleted entirely when the server restarts. If None, no cache deletion will occur.
NzCannot load z. Caught Exception: z1Theme should be a class loaded from gradio.themeszutf-8FT(   rk  )encoding
)r  TrueHF_HUB_DISABLE_TELEMETRYrU   GRADIO_WATCH_DIRS@   GRADIO_ROOT_PATH)rk  Homec              3  z   >#    U  H0  nTR                   R                  5       UR                  5       :H  v   M2     g 7fr   )themeto_dict).0built_in_themerm   s     rn   	<genexpr>"Blocks.__init__.<locals>.<genexpr>  s3      &&>N 

""$(>(>(@@&>s   8;)mode
custom_cssr  is_custom_themeversionrt   )flimiterDefaultThemer_   r`   r   rO   Themefrom_hub	Exceptionr  r  r  _get_theme_css	theme_css_stylesheetsstylesheetsr  r  rx  r  r  
theme_hashencryptshareenable_queuemax_threadsr   r   pending_streamspending_diff_streams
show_errorfill_height
fill_widthdelete_cacheextra_startup_eventscssr   none_or_singleton_to_listopenreadr=  headrenderablescustom_mount_pathpwar   analytics_enabledr   IS_WASM	threadingThreadversion_checkstartosenvironenable_monitoringr  default_configsuperro   r  
is_running	local_url	share_urlwidthheightrF  api_openspace_idfavicon_pathauthr   getenvdev_moderandomgetrandbitsapp_idrh   upload_file_setr   titlerH  predictinput_componentsoutput_componentsr   api_modeprogress_tracking
ssl_verifyallowed_pathsblocked_pathsr   	root_path
proxy_urlsr  r   r  r   r   rK   initiated_analyticsrE  )rm   r  r  r  r4  r  	css_pathsr=  r  
head_pathsr  r  r  r   r   theme_hashercss_pathcss_file	head_path	head_filetr  r   r   s   `                      rn   ro   Blocks.__init__  s   > = NEs##{{}/'6+!NN51E %''MMMN NE!
--/ --~~'DNN11':;&002
 *40$/$5!&$(SU!9"33I>	!RHh1XD8==?22 21 ( (JB	44Z@
#)r)Ii'2i		TINN$444	 32 * .0-1 !, ,,. 	
 !!%%$$I,C,CD	5;BJJ12.2*40000	
)T1) 	RYY':B?@((,"u#334
&...  $!%!%(:B?%-9N
!!"% &&5&<&<&>& # O
 		"hhd2#2.0D ))$/

W ! +MML7KCPQF8"TU(NE+6 21 32s0   U 'V%'V8
V"(/VV"%
V5	8
W	c                .    U R                   R                  $ r   r#  r   ru   s    rn   r   Blocks.blocks  s    "")))rq   c                $    XR                   l        g r   rJ  )rm   r   s     rn   r   rK    s    %*"rq   c                .    U R                   R                  $ r   )r#  r  ru   s    rn   r  
Blocks.fns  s    ""&&&rq   c                    U R                   U   n[        U[        R                  [        45      (       d  [        SU S35      eU$ )NzBlock with id z# is not a Component or BlockContext)r   r_   r   rM   r   	TypeError)rm   r]   comps      rn   get_componentBlocks.get_component  sA    {{2$!5!5| DEEnRD0STUUrq   c                T    [         R                  (       a  gSSKJn  [	        USS5      $ )NFr   )reload_threadrunning_reload)r   r  gradio.cli.commands.reloadrU  r   )rm   rU  s     rn   _is_running_in_reload_thread#Blocks._is_running_in_reload_thread  s#     <}&6>>rq   c           	       ^^^^^^ [         R                  " U5      nUS   mUR                  SS5      n0 mT1mS(UUU4S jjmUUU4S jmS/n[        US9 n[        R
                  =(       d    U=TS	'   nS
U;   a  T" US
   R                  S/ 5      5        SnSU;  a  [        S5      e[        US   USS9 GH  u  pSU	;   a  U	S   S:X  a  M  U H  nU	R                  US5        M     U	R                  S5      nU	R                  SS5      nSn[        US	   [        5      (       d(  US	   S   S;   a  [        U5      S:w  a  [        S5      eSnU	R                  S5        U	R                  SS5        U	S    Vs/ s H  nTU   PM
     snU	S'   U	S    Vs/ s H  nTU   PM
     snU	S'   U	R                  SS5        U	R                  SS5        U	R                  SS5        U	R                  SS5        U	R                  SS5        SU	S '   SU	S!'   U(       a;  [        SS"5      /nU	R                  S#5      U	S#'   U	R                  S$5      U	S$'   SU	S%'   OW[        R                  TX5       Vs/ s H6  n[        UR                  (       a  UR                  OSUR                   5      PM8     nnUR"                  R$                  " S)UU
S&.U	D6S	   n	Ub  GM  U	nGM     U(       aJ  ['        5       (       a;  US	   /Ul        UR*                  Ul        UR.                  Ul        S'Ul        SUl        SSS5        TWl        U$ s  snf s  snf s  snf ! , (       d  f       N&= f)*a  
Factory method that creates a Blocks from a config and list of functions. Used
internally by the gradio.external.load() method.

Parameters:
config: a dictionary containing the configuration of the Blocks.
fns: a list of functions that are used in the Blocks. Must be in the same order as the dependencies in the config.
proxy_url: an external url to use as a root URL when serving files for components in the Blocks.
r   r  rf  r]   c                  > T H  nUS   U :X  d  M    O   [        SU  35      e[        US   S   5      nUS   R                  S5      c  T	 S3US   S'   US   R                  SS 5      nUR	                  US   5      nU" S	0 UD6nUb  X5l        US   S   nXel        T
R                  U5        US   R                  SS 5      =n b  Xul        U$ )
Nr]   zCannot find block with id r   r   rX   /r   r   rt   )	r   rH   r   r   r   r   rX   r   r   )r]   r  r   postprocessed_valuer~   rc  block_proxy_urlr   components_configrX   r>  s           rn   get_block_instance.Blocks.from_config.<locals>.get_block_instance  s	    1%+ !2 !#=bT!BCC+L,A&,IJC
 G$((5=8A{!_W%k2".w"7";";GT"J"11,w2GH+*+E".1*73K@O-ONN?++G488MM %0!Lrq   c                   > U  Hb  nUS   nT" U5      nUTU'   UR                  S5      nUc  M+  [        U[        5      (       d  [        SU S35      eU   T" U5        S S S 5        Md     g ! , (       d  f       Mv  = f)Nr]   r   zInvalid config, Block with id z( has children but is not a BlockContext.)r   r_   r   r   )children_listchild_configr]   rc  r   r`  iterate_over_childrenoriginal_mappings        rn   re  1Blocks.from_config.<locals>.iterate_over_children  s     -!$'*2.', $'++J7'%e\::(<RD@hi  -h7  !. s   	A++
A:	r`  )r  r   r  r   Nr  zEThis config is missing the 'dependencies' field and cannot be loaded.Fstrictr  
fake_eventr;  rZ   )thensuccesszcThis logic assumes that .then() events are not combined with other events in a single gr.on() eventTr_  documentationr0  r1  status_trackerzerogpure   everyr2  r'  rk  rB  rC  r  )r;  r/  	Interface)r]   rn  r   rQ   rt   )r  deepcopyr   r  r!   r   r   zipr   r_   rn  r  r.   get_event_targetshas_trigger__self__r  r#  r  r#   r5  r0  r6  r1  r7  r   r8  r>  )r   r   r  rX   r  derived_fieldsr   r   first_dependency
dependencyr/  fieldr  r  is_then_eventior;  rG  r_  r`  re  rf  r>  s      `               @@@@@rn   from_configBlocks.from_config  s     v&"<0

7I.-/[
	 	<	8  "% F/6/A/A/KVKQ*6!%fX&6&:&::r&JK# V+ [  #&f^&<c%"P
 
*z)/D/T+ENN5$/ ,
 &>>)4$..D9 %
 "(1+s33A K 9 8})( B  %)M|,51;H1E(1EA$Q'1E(
8$ 2<I1F)1FA$Q'1F)
9% /6y$/tT*}d3w-+0
<(,1
=) 24@AG2<..2QJ/<FNN1=J89 /3J{+ "(!9!9,h"
"A	 ,*+--AJJTLL"   (66HH #.8
 $+'1$E #QJ  $6$8$8"%a&*:*A*A'+;+C+C("-"&q !r 'Y()$G ! s?   D"M9L8ML=$CM(=M%%MAM8M
Mc                "    U R                  5       $ r   )r\  ru   s    rn   rY  Blocks.__str__s  s    }}rq   c                0   [        U R                  R                  5        Vs/ s H  oR                  (       d  M  UPM     sn5      nSU S3nUSS[        U5      -   3-  nU R                  R	                  5        H  u  pUR                  (       d  M  USU 3-  nUS-  nUR
                   H$  nU R                  UR                     nUSU 3-  nM&     US-  nUR                   H$  nU R                  UR                     nUSU 3-  nM&     M     U$ s  snf )	NzGradio Blocks instance: z backend functionsr  r  z

fn_index=z	
 inputs:z
 |-z

 outputs:)	r  r  r   r/  r  r0  r   r^   r1  )rm   dnum_backend_fnsreprry  rc  s         rn   r\  Blocks.__repr__v  s   $((//*;D*;Qttq*;DE)/)::LM"S3t9_%&&!XX^^-MA}}}+aS))$'..E KK		2EeE7O+D / %'//E KK		2EeE7O+D 0 .  Es
   DDc                V    [        S U R                  R                  5        5       5      $ )z>Return whether the app expects user to authenticate via OAuth.c              3  V   #    U  H  n[        U[        R                  5      v   M!     g 7fr   )r_   r   LoginButtonr  rc  s     rn   r  'Blocks.expects_oauth.<locals>.<genexpr>  s$      
CW%Juj4455CWs   '))r  r   r   ru   s    rn   expects_oauthBlocks.expects_oauth  s+      
CG;;CUCUCW
 
 	
rq   c                r    U R                   R                  [        SS5      /USSSSSSSSSSSSSSSSSSS	9  g)
a  This listener is triggered when the user closes or refreshes the tab, ending the user session.
It is useful for cleaning up resources when the app is closed.
Parameters:
    fn: Callable function to run to clear resources. The function should not take any arguments and the output is not used.
Example:
    import gradio as gr
    with gr.Blocks() as demo:
        gr.Markdown("# When you close the tab, hello will be printed to the console")
        demo.unload(lambda: print("hello"))
    demo.launch()
Nr  Fr  Tre  rh  rf  )r;  r/  r0  r1  r2  r'  r>  r<  r=  r  r6  r7  r@  rA  rB  rC  rD  r4  r5  rH  )r#  r  r.   )rm   r/  s     rn   r  Blocks.unload  sc     	--(x89" $$)') 	. 	
rq   c                z   [        5       nUGb  [        R                  Gb  U R                  UR                  ;   a  [        SU R                   S35      e[        UR                  5      R                  U R                  5      nU H:  n[        U R                  U   [        R                  5      (       a  M1  [        S5      e   U R                  R                  5        H"  n[        R                  R                  Ul        M$     UR                  R                  U R                  5        [        UR                   R#                  5       SS9S-   nUR                   R                  5        Vs/ s H0  n[        UR$                  [&        5      (       d  M$  UR$                  PM2     nnU R                   R                  5        GHw  n[        R                  R                  Ul        U=R                  U-  sl        UR(                   H7  n	U	S   U R                  :X  d  M  [        R                  R                  U	S   4n	M9     UR$                  n
[        U
[&        5      (       a"  [*        R,                  " U
U5      nX:w  a  Xl        UR.                   Vs/ s H  oU-   PM	     snUl        UR0                  b  U=R0                  U-  sl        UR.                  (       aF  UR.                   Vs/ s H  oR                   U   R3                  5       PM!     nn[5        U5      Ul        XR                   UR                  '   GMz     [        UR                   R#                  5       SS9S-   Ul        [        R                  R8                  R;                  U R8                  5        [        R                  R<                  R                  U R<                  5        [        R                  R>                  R;                  U R>                  5        [A        5       nUb%  URB                  R;                  U RB                  5        U $ s  snf s  snf s  snf )Nr   r   z<At least one block in this Blocks has already been rendered.)rf  rZ   r   )"r#   r!   r   r^   r   r0   rh   intersectionr_   r   Stater   r   r   rx  maxr  keysr<  r`   r;  r   r  r@  rB  r   rI   r  r   extendr>  r  r$   r   )rm   r   overlapping_idsr]   rc  dependency_offsetr  existing_api_namesry  r  r<  	api_name_cr|  updated_cancelsr   s                   rn   rU   Blocks.render  s`   )+#(:(:(Fxx<...)'z1bc  ","5"56CCDKKPO%!$++b/:3C3CDD-V  & ++-$//<<
 .&&t{{3 #L$4$4$9$9$;R H1 L (++224"4CcllC0 4  "
 #hhoo/
")"4"4"A"A
"33 )00FayDHH,")"4"4"8"8&)!D 1 &..h,, % : : *!I  ,.7+EOEWEW%XEW*;&;EW%X
"++7,,0AA, %%BLBTBT'BTQ((+668BT $ ' *B/)RJ&3=  07 08 "%\%5%5%:%:%<b!IA!ML--44T5H5HI))00A33::4;T;TU+-%##**4==9S"* &Y's   (#P.P.P3"&P8r   c                \   U R                   U   nU R                   U   n[        R                  " UR                  5      (       a  g[        R                  " UR                  5      (       a  g[        S UR                   5       5      (       a  g[        S UR                   5       5      (       + $ )zVChecks if a particular Blocks function is callable (i.e. not stateful or a generator).Fc              3  8   #    U  H  oR                   v   M     g 7fr   rv   r  s     rn   r  %Blocks.is_callable.<locals>.<genexpr>  s     =+<%~~+<   c              3  8   #    U  H  oR                   v   M     g 7fr   r  r  s     rn   r  r    s     F3E%~~3Er  )r  r   rJ  r/  rI  r  r0  r1  )rm   fn_indexr  ry  s       rn   is_callableBlocks.is_callable  s    88H%XXh'
%%hkk22&&x{{33=:+<+<===F:3E3EFFFFrq   )r  r<  c          	     j  ^ TbA  [        U4S jU R                  R                  5        5       S5      nUc  [        ST 35      eUnU R	                  U5      (       d  [        S5      e[        U5      nU R                  X5      nU R                  U   nUR                  (       a  U Vs/ s H  ow/PM     nn[        R                  " U R                  UUS0 SS9nUS   nUR                  (       a  U V	s/ s H  oS   PM	     nn	U R                  X5      n[        R                  " U5      n
U
$ s  snf s  sn	f )	a  
Allows Blocks objects to be called as functions. Supply the parameters to the
function as positional arguments. To choose which function to call, use the
fn_index parameter, which must be a keyword argument.

Parameters:
*inputs: the parameters to pass to the function
fn_index: the index of the function to call (defaults to 0, which for Interfaces, is the default prediction function)
api_name: The api_name of the dependency to call. Will take precedence over fn_index.
Nc              3  P   >#    U  H  u  pUR                   T:X  d  M  Uv   M     g 7fr   )r<  )r  r|  r  r<  s      rn   r  "Blocks.__call__.<locals>.<genexpr>	  s"     J/tq1::3I/s   &	&z%Cannot find a function with api_name zThis function is not callable because it is either stateful or is a generator. Please use the .launch() method instead to create an interactive user interface.T)r  r0  requeststateexplicit_callr   r   )nextr  r  r1   r  r   r  serialize_datar6  r   synchronize_asyncprocess_apideserialize_datar   r  )rm   r  r<  r0  inferred_fn_indexprocessed_inputsr/  inpr1  outprocessed_outputss     `        rn   __call__Blocks.__call__  s@     $Jtxx~~/J! !();H:F  )H  ** r  f..x@XXh881AB1A#1AB00#
 &/88)01#1vG1'':!33G<  %  C 2s   'D+2D0c	           	       #    [        U[        5      (       a  U R                  U   nUR                  (       d  [	        S5      eSn	[        U[
        5      (       a  US   OUn
[        R                  " 5       n[        R                  " UR                  U UUU
US9nUc  UR                  (       a  [        [        UR                  USS95      /nUR                  (       a  UR                  R                  OUR                  n[        XX5      u  p.nUb  X.   OSnUb   Ub  [        UUR                   5      u  nnUX.'   ["        R$                  " U5      (       a  U" U6 I Sh  vN nO9[&        R(                  R*                  " U/UQ7SU R,                  06I Sh  vN nOSn["        R.                  " U5      (       d  ["        R0                  " U5      (       av   Uc  [3        [4        [6           U5      n["        R8                  " U5      (       a   [        R:                  " X0R,                  5      n[        R<                  " U5      I Sh  vN nSn	[        R                  " 5       U-
  nUUU	US
.$  GN
 N N*! [>         aX    [A        URB                  5      nUS	:X  a  [D        RF                  RH                  O[D        RF                  RH                  4U-  nSn Nf = f7f)a~  
Calls function with given index and preprocessed input, and measures process time.
Parameters:
    fn_index: index of function to call
    processed_input: preprocessed input to pass to function
    iterator: iterator to use if function is a generator
    requests: requests to pass to function
    event_id: id of event in queue
    event_data: data associated with event trigger
zfunction has no backend method.Fr   )r/  r   event_idin_event_listenerr  r  Nrh  r  TrZ   )
predictiondurationis_generatingiterator)%r_   rn  r  r/  
IndexErrorr  timer   get_function_with_localsr:  r   rs  r0  r   r5   r3   
track_tqdmr   iscoroutinefunctionanyio	to_threadrun_syncr  rI  rJ  r   r   r   isgeneratorSyncToAsyncIteratorasync_iterationStopAsyncIterationr  r1  r   rz  FINISHED_ITERATING)rm   r  processed_inputr  requestsr  
event_datar  r  r  r  r  r/  r  r  r   progress_trackerr  	n_outputsr  s                       rn   call_functionBlocks.call_function.  s    * h$$xx)H{{>??!+Hd!;!;(1+		++{{/
 &&X__oeLM#
 +3*=*=##&&8;;  2>2.OQ 4B3M/SW   +0J'5b:J:U:U'V$ "2B/**2..#%#77
#(??#;#;$($26,,$ 
 J&&r**g.H.H.L.L ##M#$6
CH&&x00$88<<PH#(#8#8#BB
 $ 99;& % * 	
 	
7 8 C%   0 01	 !A~ ((;;$..AACiO 
   s\   EKI'6KI*=KA.I. I,I.  K*K,I. .AKKKKc                   U R                   U   n/ nS n[        UR                  5       H  u  pg[        U[        R
                  5      (       d  [        UR                   S35      eUR                  5       n[        R                  " U5      (       a  [        R                  " X&   US 5      n	OX&   n	UR                  U	5        M     U$ )Nc                0    [        U S9R                  5       $ )N)r   )r(   r   r  s    rn   format_file*Blocks.serialize_data.<locals>.format_file  s    #..00rq   ' Component not a valid input component.c                h    [         R                  " U 5      =(       d    [         R                  " U 5      $ r   )r   is_filepathr   r  s    rn   r  'Blocks.serialize_data.<locals>.<lambda>  s'    l66q9 8#44Q78rq   )r  	enumerater0  r_   r   rM   r2   r   r  r   value_is_filetraverser   )
rm   r  r0  ry  r  r  r|  rc  r  serialized_inputs
             rn   r  Blocks.serialize_data  s    XXh'
	1 "*"3"34HAeZ%9%9::+''NO  ~~'H))(33#/#8#8I8$  $*9 ""#34 5" rq   c                F   U R                   U   n/ n[        UR                  5       Hv  u  pV[        U[        R
                  5      (       d  [        UR                   S35      e[        R                  " X%   S [        R                  5      nUR                  U5        Mx     U$ )N( Component not a valid output component.c                    U S   $ )Nr   rt   r  s    rn   r  )Blocks.deserialize_data.<locals>.<lambda>  s    airq   )r  r  r1  r_   r   rM   r2   r   r   r  is_file_objr   )rm   r  r1  ry  r  r}  rc  deserializeds           rn   r  Blocks.deserialize_data  s    XXh'
!*"4"45HAeZ%9%9::+''OP  (00
/1I1IL |, 6 rq   c                   UR                   n[        U5      [        U5      :  a  UR                  (       a   UR                  S:w  a  SUR                   S3OSn/ n/ nU H  nUR                  [	        U5      5        M     U H:  n[        U[        5      (       a  SU S3O
[	        U5      n	UR                  U	5        M<     SR                  U5      n
SR                  U5      n[        SU S[        U5       S	[        U5       S
U
 SU S35      eg )N<lambda> ()rk  ", zAn event handlerz- didn't receive enough input values (needed: z, got: zz).
Check if the event handler calls a Javascript function, and make sure its return value is correct.
Wanted inputs:
    [z]
Received inputs:
    [])r0  r  r   r   r`   r_   r  r   )rm   r  r0  
dep_inputsr   wanted_argsreceived_argsrc  r  vwantedreceiveds               rn   validate_inputsBlocks.validate_inputs  s   __

 v;Z( ==X]]j%@ X]]O1%  KM#""3u:. $",S#"6"6auAJCH$$Q'  YY{+Fyy/H $TF*WX[\fXgWhhopstzp{o| } X Zq ' )rq   c                  #    U=(       d    [        U 5      nU R                  X5        UR                  (       Ga<  / n[        UR                  5       GH  u  pg[        U[        R                  5      (       d  [        UR                   S35      eUR                  (       a  UR                  X7R                     5        Mm  UR                  U;   a  X7R                     n[        R                  " X&   UU(       + S9I S h  vN n[        USS 5      (       a<  Ub9  [!        ["        [$        [&        4   UR(                  5      n	U	R+                  USS0S9nUR                  UR                  U5      5        GM!     U$ UnU$  N}7f)Nr  )check_in_upload_folder
data_modelvalidate_metaT)context)r=   r  r2  r  r0  r_   r   rM   r2   r   rv   r   r^   r   async_move_files_to_cacher   r   r   r)   r*   r  model_validate)
rm   r  r0  r  r  r  r|  rc  inputs_cachedr  s
             rn   preprocess_dataBlocks.preprocess_data  s_     +d+X. O%hoo6!%)=)=>>/ ??++RS  >>#**5+;<yyE) %ii 0*:*T*T	3@/@+ %M
 ulD99m>W%)!+">?AQAQ&
 )3(A(A)OT3J )B ) $**5+;+;M+JK- 72  %O%s   C:E<<E:=A>E<c                F   UR                   n[        U[        [        45      (       d  U/n[	        U5      [	        U5      :w  Ga^  UR
                  (       a   UR
                  S:w  a  SUR
                   S3OSn/ n/ nU H+  nUR                  [        UR                  5       5      5        M-     U H:  n[        U[        5      (       a  SU S3O
[        U5      n	UR                  U	5        M<     SR                  U5      n
SR                  U5      n[	        U5      [	        U5      :  a-  [        SU S[	        U5       S	[	        U5       S
U
 SU S35      e[	        U5      S:X  a  US   c  g [        R                  " SU S[	        U5       S	[	        U5       SU
 SU S35        g g )Nr  r  r  rk  r  r  zA  functionz- didn't return enough output values (needed: z, returned: z#).
    Output components:
        [z']
    Output values returned:
        [r  rZ   r   z
A functionz* returned too many output values (needed: z:). Ignoring extra values.
    Output components:
        [)r1  r_   r  tupler  r   r   r`   r   r  r   r  r  )rm   r  r  dep_outputsr   r  r  rc  predr  r  r  s               rn   validate_outputsBlocks.validate_outputs   s   &&+e}55&-K{s;// ==X]]j%@ X]]O1%  KM$""3u'<'<'>#?@ %##-dC#8#8avQKc$i$$Q' $ YY{+Fyy/H;#k"22 #D6)VWZ[fWgVhhtux  zE  vF  uG G

 

1	  {#q([^-C "4&(RSVWbScRddpqt  vA  rB  qC C

 

1	? 0rq   c                b  #    U=(       d    [        U 5      n[        U[        5      (       aH  U[        5       :X  a:  [	        UR
                  5      S:  a!  [        5       /[	        UR
                  5      -  n[        U[        5      (       a?  [	        U5      S:  a0  [        UR
                   Vs/ s H  oDR                  PM     snU5      n[	        UR
                  5      S:X  a  UR                  (       d  U/nU R                  X5        / n[        UR
                  5       GHS  u  pd X&   [        R                  R                  L a  UR                  S 5        M9   UR&                  (       a@  [(        R*                  " X&   5      (       d  X&   X4R                  '   UR                  S 5        M  X&   n[(        R*                  " U5      (       a  [(        R,                  " USS9n[        U[.        5      (       a  UR0                  R3                  5       nSUS'   [(        R*                  " U5      (       a  X4R                     R0                  R3                  5       n	U	R5                  U5        U	R7                  SS 5        U	R7                  S5        S	U	S
'   UR8                  " S0 U	D6X4R                  '   [;        X4R                     UUR<                  S9nOwUR<                  (       af  [        U[        R>                  5      (       d  [A        UR8                   S35      eUR                  U;   a  X4R                     nUR=                  U5      n[B        RD                  " UUSS9I S h  vN n
UR                  U
5        GMV     U$ s  snf ! [        [         4 a  n[#        SUR$                   35      UeS nAff = f NR7f)NrZ   r   zXNumber of output components does not match number of values returned from from function T)
skip_valuerx  ry  r   FrU   )rc  r|  r'  r  r'  rt   )#r=   r_   r   r4   r  r1  r  r^   r6  r  r  r   rz  r  r   r  r   r   r   rv   r   is_prop_updater  rQ   r~   r  rx  r   r   r~  r'  rM   r2   r   r  )rm   r  r  r  rc  outputr|  errprediction_valuer   outputs_cacheds              rn   postprocess_dataBlocks.postprocess_data-  s5     +d+{D))tv%H$$%)  6(S)9)9%::Kk4((S-=-A8(0(8(89(8u(89;K x A%hnnK 	h4!("2"23HA>Z%9%9%L%LLMM$' M ~~++KN;;'2~E))$d##.> ''$  (-'8'8(T($ .66'7'H'H'M'M'O$3;$Z0''(899"99->>CCEFMM"23JJw-JJz*',F8$','@'@E))$'>#II.$4$,$8$8($
 ))%eZ-A-ABB3$//WX  yyE) %ii 0','8'89I'J$'7'Q'Q$ $( "
 n-m 4p G :  )  ==E]]OM X"sD   B)N/+M7 A#N/$0M<HN/N-!N/<N*N%%N**N/c           
     \  #    Ub  Uc  U$ X@R                   U   ;  a  0 U R                   U   U'   U R                   U   U   n[        UR                  5       GHI  u  pU	R                  n
[	        U	[
        R                  5      (       d  M3  U	R                  (       d  MF  [        R                  " X(   5      (       a  Me  U(       a  Xz   R                  5         X;  nU	R                  X(   U SU SU
 S3U5      I S h  vN u  pU(       aA  S nUR                  S5      =n(       a  [        U5      R                  SS  n[        US9Xz'   Xz     Xz   R!                  U5      I S h  vN   ["        R$                  " UU	SS9I S h  vN nUb  ["        R&                  " XS 5      nXU'   GML     U$  N NI N-7f)Nr\  z/playlist.m3u8	orig_namerZ   )desired_output_formatTr
  )r  r  r1  r^   r_   r   StreamingOutput	streamingr   r  
end_streamstream_outputr   r
   suffixr8   add_segmentr   r  add_root_url)rm   r  r   session_hashrunr=  final
stream_runr|  rc  	output_idfirst_chunkbinary_dataoutput_datar  r  s                   rn   handle_streaming_outputsBlocks.handle_streaming_outputs  s     3;K**<8868D  .s3-1-A-A,-OPS-T
!("2"23HA		I5*"<"<==OOO,,TW55)446'9161D1DG#nAcU!I;nE2 ,(
 ,0)$/OOK$@@y@04Y0F0Fqr0J-,7.C-J) ) +77DDD$4$N$N $% 
 ("2"?"?##K &QE 4H 5, EsI   BF,	F,F,;>F,9F&:A$F,F(F,<F*=*F,(F,*F,c                   Ub  Uc  U$ X@R                   U   ;  nU(       a  S /[        U5      -  U R                   U   U'   U R                   U   U   n[        [        UR                  5      5       HO  n	U(       a  X   X)'   M  U(       a  X)   X'   M!  X   n
X)   X'   U(       a  M4  [        R
                  " XU	   5      X)'   MQ     U(       a  U R                   U   U	 U$ r   )r  r  ranger1  r   diff)rm   r  r   r  r  r  simple_format	first_run
last_diffsr|  
prev_chunks              rn   handle_streaming_diffsBlocks.handle_streaming_diffs  s     3;K88FF	<@6CI;MD%%l3C8..|<SA
s8++,-A$- $
']
 $
$}#jj!W=DG . )),7<rq   Tc           
       ^ #    [        U[        5      (       a  U R                  U   nUR                  nU R	                  X5      u  p/ n[
        R                  R                  U 5        U(       Ga  UR                  nU Vs/ s H  n[        U5      PM     nnUS   m [        R                  " UR                  5      (       d%  [        R                  " UR                  5      (       a  [        S5      e[        U 4S jU 5       5      (       d  [        SU S35      eT U:  a  [        ST  SU S35      e[!        US	S
06 Vs/ s H'  nU R#                  U[%        U5      X;5      I Sh  vN PM)     nnU R'                  U[%        [!        US	S
065      SUUUU	U5      I Sh  vN nUS   n[!        US	S
06 Vs/ s H'  nU R)                  U[%        U5      U5      I Sh  vN PM)     nnUb  [*        R,                  " UUS5      n[%        [!        US	S
065      nSu  nnGO7UnU(       a  / nOU R#                  XX;5      I Sh  vN nUSLnU R'                  UUUUUUU	U5      I Sh  vN nU R)                  UUS   U5      I Sh  vN nU(       a>  [!        XS
S9 VVs/ s H'  u  nnU[.        R0                  " UU   5      :w  d  M%  UPM)     nnnUb  [*        R,                  " UUS5      nUS   US   nnU(       d  U(       aW  U(       a  [3        U5      O
[3        U5      nU R5                  UUUUUU(       + S9I Sh  vN nU R7                  UUUUU(       + U
S9nU=R8                  US   -  sl        U=R:                  S-  sl        UUUUS   UR8                  UR:                  -  SUS.nUR<                  (       al  U(       ae  UR>                  RA                  UR<                  5      US'   UR<                  RB                  US   S'   Ub  [*        R,                  " US   US5      US'   U$ s  snf  GNs  snf  GN GNXs  snf  GN GN GNs  snnf  GN7f)a  
Processes API calls from the frontend. First preprocesses the data,
then runs the relevant function, then postprocesses the output.
Parameters:
    fn_index: Index of function to run.
    inputs: input data received from the frontend
    state: data stored from stateful components for session (key is input block id)
    request: the gr.Request object containing information about the network request (e.g. IP address, headers, query parameters, username)
    iterators: the in-progress iterators for each generator function (key is function index)
    event_id: id of event that triggered this API call
    event_data: data associated with the event trigger itself
    in_event_listener: whether this API call is being made in response to an event listener
    explicit_call: whether this call is being made directly by calling the Blocks function, instead of through an event listener or API route
    root_path: if provided, the root path of the server. All file URLs will be prefixed with this path.
Returns: None
r   z1Gradio does not support generators in batch mode.c              3  ,   >#    U  H	  oT:H  v   M     g 7fr   rt   )r  r  
batch_sizes     rn   r  %Blocks.process_api.<locals>.<genexpr>  s     <1Js   zQAll inputs to a batch function must have the same length but instead have sizes: .zBatch size (z0) exceeds the max_batch_size for this function (r  ri  FNr  )NNrh  r  r  )r  r  r=  r  )r  r  r  r)  r  rZ   )r   r  r  r  average_durationrender_configchanged_state_idsr5  	render_id)"r_   rn  r  r6  get_state_ids_to_trackr"   r   rh   r7  r  r   rJ  r/  rI  r   r  rs  r   r  r  r  r   r  r   	deep_hashr]   r$  r-  r8  r9  r   blocks_configr   r^   )!rm   r  r0  r  r  r  r  r  r  r  r)  r  r=  r6  state_ids_to_trackhashed_valuesr6  r7  r  batch_sizesr|  resultpredsr}  r   r  old_iteratorwas_generating
hash_valuestate_idr  r  r1  s!                                   @rn   r  Blocks.process_api  s    > h$$xx)H,0,G,G,X)%%44N/56v3s8vK6$QJ))(++66':U:U; ; !!TUU<<<< ghsgttuv  N* ":,.^_m^nnop 
 f3U33A **8T!WeSSS3    --S&//0!	 	F <(E e2E22A ++Hd1guEEE2   $'44T9dKT0%01D&0#M8#L#33e   *5N--!	 	F ..x9MuUUD 14%%1%1,
H "U__U8_%EE	 1 " % $'44T9dK&,_&=vj?Q8M*8b&bl!::!-'++ ;   22!-++"/ 3  	&"44q * z* ( 6 69L9L L!!2
 5&+&9&9&D&D##'F?# 4<3F3F3J3JF?#K0$*:*G*G?+Y+' [ 7 T	 F	 V%s   A=Q
 P B*Q
?%P($P%
%P(-/Q
P-Q
3%P3P0
P3!AQ
:P8;#Q
P;Q
<P>=Q
$Q=QA/Q
2Q3C2Q
%P((Q
0P33Q
;Q
>Q
Q
c                  ^ Uc  / / 4$ / n/ nUR                    H  mTR                  (       d  M  [        U4S jUR                  R                  R                  5        5       5      (       d  MT  UTR                     nUR                  TR                  5        UR                  [        R                  " U5      5        M     X44$ )Nc              3  Z   >#    U  H   nTR                   S 4UR                  ;   v   M"     g7f)r  N)r^   r;  )r  r/  rc  s     rn   r  0Blocks.get_state_ids_to_track.<locals>.<genexpr>y  s*      &:B H%3:s   (+)
r1  rv   r  r:  r  r   r^   r   r   r9  )rm   r  r  r;  r<  r   rc  s         @rn   r8  Blocks.get_state_ids_to_trackq  s     =r6M%%E~~~# &--1188:& # # eii("))%))4$$U__U%;< & "00rq   c                d    U R                   S:X  a  S U l        g [        U R                   S9U l        g )Nr  )total_tokens)r
  r   r  ru   s    rn   create_limiterBlocks.create_limiter  s5     2%  	 !d.>.>? 	rq   c                
    SS0$ )Nr  columnrt   ru   s    rn   r   Blocks.get_config  s    !!rq   c                   0 S[         _S[        _SU R                  _SU R                  _SU R                  _SU R
                  _S/ _SU R                  _S	S
_SU R                  _SU R                  _SU R                  =(       d    S_SU R                  _SS_S[        U SS
5      _SU R                  _S[        R                  " 5       _[        U SS 5      U R                  U R                   R"                  SU R                   R%                  S5      U R                   R%                  S5      U R                   R%                  S5      U R                   R%                  S5      S.U R&                  U R(                  U R*                  U R,                  U R.                  0 S.EnUR1                  U R2                  R5                  5       5        [        R6                  " XR8                  R;                  5       5      US	'   U$ )Nr  
api_prefixr  r2  r/  r  r   r  connect_heartbeatFr=  r  r4  Gradior+  r	  Tr  rH  is_colabmax_file_sizesse_v3body_background_fillbody_text_colorbody_background_fill_darkbody_text_color_dark)rW  rX  rY  rZ  )rU  r  r  protocolbody_cssr  r  r  r  r  r   )r:   r7   r  r2  r/  r  r  r=  r  r4  r+  r   rH  r   colab_checkr  r  r   _get_computed_valuer  r  r  r  r  rx  r#  r   rR  r   r   )rm   r   s     rn   get_config_fileBlocks.get_config_file  s   ($
w($
*($
 DII($
 dkk	($

 ($
  !7!7($
 "($
 488($
  ($
 $''($
 DII($
 TZZ+8($
 ($
 D($
 '$e<($
  !($
" ))+#($
$ %T?DA++ZZ__ (,

(F(F*) $(::#A#ABS#T-1ZZ-K-K/. )-

(F(F*)  ++////88ZZO($
R 	d))4467&+&=&=KK&&('
"# rq   c                f    [        5       nUc  U [        l        Xl        [	        U 5        SU l        U $ rs   )r$   r!   r   rd   r%   exitedr  s     rn   r  Blocks.__enter__  s1    +-!!%G$4 rq   c                  > Ub  [        S 5        S [        l        g [        TU ]  5         [        U R
                  5        U R                  R                  5         U R
                  c  S [        l        O/U R
                  R                  R                  U R                  5        U R                  5       U l        [        R                  " U 5      U l        [        S U R                   R#                  5        5       5      U l        SU l        SU l        g )Nc              3  8   #    U  H  oR                   v   M     g 7fr   )r3  )r  r  s     rn   r  "Blocks.__exit__.<locals>.<genexpr>  s      %
5F$$5Fr  rk  T)r%   r!   r   r$  r  rd   r#  r  r   r  r_  r   r;   
create_appappr  r  r   r9  r   rb  )rm   r!  r"  r   s      rn   r#  Blocks.__exit__  s    t$!%G%'4;;'..0;;!%GKK  ''6**,>>$'!$ %
59XX__5F%
 "
 	rq   c                X    0 U R                   l        0 U R                   l        / U l        U $ )z'Resets the layout of the Blocks object.)r#  r   r  r   ru   s    rn   clearBlocks.clear  s*    %'""$rq   not_set)default_concurrency_limitc          	         Ub  X l         [        R                  " 5       (       a  Uc  SOUn[        R                  " US:H  U R
                  US:w  a  UOSUU US9U l        [        R                  " U 5      U l	        U $ )a;  
By enabling the queue you can control when users know their position in the queue, and set a limit on maximum number of events allowed.
Parameters:
    status_update_rate: If "auto", Queue will send status estimations to all clients whenever a job is finished. Otherwise Queue will send status at regular intervals set by this parameter as the number of seconds.
    api_open: If True, the REST routes of the backend will be open, allowing requests made directly to those endpoints to skip the queue.
    max_size: The maximum number of events the queue will store at any given moment. If the queue is full, new events will not be added and a user will receive a message saying that the queue is full. If None, the queue size will be unlimited.
    default_concurrency_limit: The default value of `concurrency_limit` to use for event listeners that don't specify a value. Can be set by environment variable GRADIO_DEFAULT_CONCURRENCY_LIMIT. Defaults to 1 if not set otherwise.
Example: (Blocks)
    with gr.Blocks() as demo:
        button = gr.Button(label="Generate Image")
        button.click(fn=image_generator, inputs=gr.Textbox(), outputs=gr.Image())
    demo.queue(max_size=10)
    demo.launch()
Example: (Interface)
    demo = gr.Interface(image_generator, gr.Textbox(), gr.Image())
    demo.queue(max_size=20)
    demo.launch()
rZ   auto)live_updatesconcurrency_countupdate_intervalsmax_sizer   rn  )
r*  r   is_zero_gpu_spacer   Queuer
  _queuer;   rg  rh  )rm   status_update_rater*  rt  rn  s        rn   rE  Blocks.queue  sy    6 $M""$$$,q(Hnn+v5"..3E3O/UV&?
 >>$'rq   c                   U R                   R                  5        Hl  nUR                   H,  nU R                   U   R                  (       a  M#  [	        S5      e   UR
                  (       d  MR  UR                  SL d  Mc  [	        S5      e   g )Na!  Queue needs to be enabled! You may get this error by either 1) passing a function that uses the yield keyword into an interface without enabling the queue or 2) defining an event that cancels another event without enabling the queue. Both can be solved by calling .queue() before .launch()Fz4In order to use batching, the queue must be enabled.)r  r   r@  rE  r   r6  )rm   r  r|  s      rn   validate_queue_settingsBlocks.validate_queue_settings	  sm    88??$C[[xx{((($+  ! yyySYY%/ !WXX %rq   i  z100%r\   )r)  r(  r,  ssl_keyfilessl_certfilessl_keyfile_passwordr:  quietrH  r;  r<  r=  
app_kwargsrg   share_server_addressshare_server_protocolauth_dependencyrU  r"  strict_corsnode_server_name	node_portssr_moder  	_frontendc          
        SSK Jn%  U R                  (       a  gU R                  (       d  U R	                  5         Ub  Ub  [        S5      eU(       aI  [        U5      (       d9  [        US   [        5      (       d!  [        US   [        5      (       d	  U/U l
        OX`l
        U R                  (       a  [        U R                  5      (       dn  [        S U R                   5       5      (       a  [        R                  " S5        [        S U R                   5       5      (       a  [        R                  " S	5        Xpl        Xl        Xl        Xl        Xl        UU l        UU l        Uc&  [*        R,                  R/                  S
S5      U l        OUU l        UU l        U(       a  UU l        Ol[*        R,                  R/                  SS5      n&[7        U&5      S:  a6  U&R9                  S5       V's/ s H  n'U'R;                  5       PM     sn'U l        O/ U l        U(       a  UU l        Ol[*        R,                  R/                  SS5      n([7        U(5      S:  a6  U(R9                  S5       V's/ s H  n'U'R;                  5       PM     sn'U l        O/ U l        [        U R4                  [        5      (       d  [        S5      e[        U R<                  [        5      (       d  [        S5      eU R?                  5         [@        RB                  " U5      U l"        U RF                  (       aE  U RH                  RK                  5        H'  n)U)RL                  b  M  SU)RN                   S3U)l&        M)     U#c  [@        RP                  " 5       SLOU#U l)        XPl*        XPRV                  l,        U R[                  5       U l.        [^        R`                  (       a  SO,U"b  U"O'[*        Rb                  " SS5      Re                  5       S:H  U l3        [*        R,                  R/                  S[^        R`                  (       a  SO	[i        5       5      U l5        U Rf                  (       a)  [m        U U!U Rj                  S9u  U l7        U l8        U l9        OS=U l7        =U l9        U l8        U%Rt                  " U UUUU Rf                  S9=U l;        U l<        U Rz                  (       aK  [        U R|                  [~        5      (       d  [        SU R|                   35      eU(       d  [        S5        GOr[^        R`                  (       a)  Sn
SnSn*Sn+[^        R                  " U Rx                  5        O)SSKBJCn,  U,R                  U Rx                  U
UUUUS9u  n
nn*n+XlE        U*U l>        U R|                  R                  S5       [         S3U lH        XlI        U+U lJ        S U l=        [@        R                  " 5       U lL        [@        R                  " 5       U lN        UU lO        U=(       d    Ub  S!OS"U lP        S U lQ        U R|                  R                  S"5      (       d  U R                  (       a  S"OS!U lS        [^        R`                  (       d  U R                  (       dx  U(       dq  U Rf                  (       a  [        R                  S#   O[        R                  S$   n-[        U-R                  U R                  U R                  U R                  5      5        U RV                  R                  U Rv                  5        [^        R`                  (       d$  [        R.                  " U R                   S%3USS&9  O4U R                  5         [        R                  " U R                  5       5        SU l]        Uc  U R                  (       a  U(       d  [        S'5        S U l^        OU R                  (       a  U(       d  [        S(5        S U l^        OmU R                  (       a  U(       d  [        S)5        S U l^        OBSU l^        [*        Rb                  " S*5      n.U.b  U.Re                  5       S:X  a  S U l^        OX0l^        U(       a/  [        S+U R|                   S,U Rx                  R                   35        US-;   U l`        U$(       aV  [^        R`                  (       dA  [        R                  " U R|                  5      (       d  U R                  (       d  [        S.5      eU R                  (       a  U(       d  U(       a  [        [        R                  S/   5        O[        [        R                  S0   5        U R                  (       d5  [        [        R                  S1   R                  U R                  5      5        U R                  (       a`  U R                  (       a  [        R                  " S25        SU l^        [^        R`                  (       a  [        R                  " S35        SU l^        U R                  (       a   U R                  ck  [        R                  " U R                  U R                  U R                  U R                  S49n/[        U/5      n0[        U R                  4U0S5S -   5      U ld        [        [        R                  S6   R                  U R                  5      5        U(       d  [        [        R                  S7   5        O?U(       d1  [^        R`                  (       d  [        [        R                  S<   5        SU ld        U(       ae  [^        R`                  (       dP  U R                  (       a  U R                  (       a  U R                  OU R|                  n2[        R                  " U25        Uc  [@        R                  " 5       nU(       Ga   SS=KwJxn3Jyn4Jzn5  U R                  (       a  U R                  (       a  [        R                  " U R                  5      (       d=  [        R                  " S>5        [        R                  " U R                  5      (       d  M=  U3" S?U R                   S@U R"                   SAU R                    SB35      n6OU R                  (       a  SCSDR                  [        R                  " U R                  5      [        R                  " S5      [        R                  " U R"                  5      [        R                  " U R                   5      [        R                  " S5      SE9-   n7U4" U75      n6O0U3" S?U R|                   S@U R"                   SAU R                    SB35      n6U6U l        U5" U65        G[        U SFS5      (       aT  U(       a  SGOSHU R                  U R                  U R                  SLU GR                  SI.n8[        GR                  " U U85        G[	        G[        G[
        SJG[
        GR                  GR                  5      5      n9U(       d]  G[        [*        Rb                  " SKSL5      5      S5:X  a  [^        R`                  (       a#  U(       d-  U9(       d&  [^        R`                  (       d  U GR                  5         G[        U Rv                  U R|                  U R                  45      $ s  sn'f s  sn'f ! [         Ga  n1U R                  (       a  [        R                  " S85        SU ld        SU l^        [        U1[        5      (       a5  [        [        R                  S9   R                  [        5      5         Sn1A1GN[        [        5      R                  5       (       a"  [        [        R                  S:   5         Sn1A1GNV[        [        R                  S;   R                  [        [        [        [        5      5         Sn1A1GNSn1A1ff = f! G[          a     GNsf = f)Ma  
Launches a simple web server that serves the demo. Can also be used to create a
public link used by anyone to access the demo from their browser by setting share=True.
Parameters:
    inline: whether to display in the gradio app inline in an iframe. Defaults to True in python notebooks; False otherwise.
    inbrowser: whether to automatically launch the gradio app in a new tab on the default browser.
    share: whether to create a publicly shareable link for the gradio app. Creates an SSH tunnel to make your UI accessible from anywhere. If not provided, it is set to False by default every time, except when running in Google Colab. When localhost is not accessible (e.g. Google Colab), setting share=False is not supported. Can be set by environment variable GRADIO_SHARE=True.
    debug: if True, blocks the main thread from running. If running in Google Colab, this is needed to print the errors in the cell output.
    auth: If provided, username and password (or list of username-password tuples) required to access app. Can also provide function that takes username and password and returns True if valid login.
    auth_message: If provided, HTML message provided on login page.
    prevent_thread_lock: By default, the gradio app blocks the main thread while the server is running. If set to True, the gradio app will not block and the gradio server will terminate as soon as the script finishes.
    show_error: If True, any errors in the gradio app will be displayed in an alert modal and printed in the browser console log
    server_port: will start gradio app on this port (if available). Can be set by environment variable GRADIO_SERVER_PORT. If None, will search for an available port starting at 7860.
    server_name: to make app accessible on local network, set this to "0.0.0.0". Can be set by environment variable GRADIO_SERVER_NAME. If None, will use "127.0.0.1".
    max_threads: the maximum number of total threads that the Gradio app can generate in parallel. The default is inherited from the starlette library (currently 40).
    width: The width in pixels of the iframe element containing the gradio app (used if inline=True)
    height: The height in pixels of the iframe element containing the gradio app (used if inline=True)
    favicon_path: If a path to a file (.png, .gif, or .ico) is provided, it will be used as the favicon for the web page.
    ssl_keyfile: If a path to a file is provided, will use this as the private key file to create a local server running on https.
    ssl_certfile: If a path to a file is provided, will use this as the signed certificate for https. Needs to be provided if ssl_keyfile is provided.
    ssl_keyfile_password: If a password is provided, will use this with the ssl certificate for https.
    ssl_verify: If False, skips certificate validation which allows self-signed certificates to be used.
    quiet: If True, suppresses most print statements.
    show_api: If True, shows the api docs in the footer of the app. Default True.
    allowed_paths: List of complete filepaths or parent directories that gradio is allowed to serve. Must be absolute paths. Warning: if you provide directories, any files in these directories or their subdirectories are accessible to all users of your app. Can be set by comma separated environment variable GRADIO_ALLOWED_PATHS. These files are generally assumed to be secure and will be displayed in the browser when possible.
    blocked_paths: List of complete filepaths or parent directories that gradio is not allowed to serve (i.e. users of your app are not allowed to access). Must be absolute paths. Warning: takes precedence over `allowed_paths` and all other directories exposed by Gradio by default. Can be set by comma separated environment variable GRADIO_BLOCKED_PATHS.
    root_path: The root path (or "mount point") of the application, if it's not served from the root ("/") of the domain. Often used when the application is behind a reverse proxy that forwards requests to the application. For example, if the application is served at "https://example.com/myapp", the `root_path` should be set to "/myapp". A full URL beginning with http:// or https:// can be provided, which will be used as the root path in its entirety. Can be set by environment variable GRADIO_ROOT_PATH. Defaults to "".
    app_kwargs: Additional keyword arguments to pass to the underlying FastAPI app as a dictionary of parameter keys and argument values. For example, `{"docs_url": "/docs"}`
    state_session_capacity: The maximum number of sessions whose information to store in memory. If the number of sessions exceeds this number, the oldest sessions will be removed. Reduce capacity to reduce memory usage when using gradio.State or returning updated components from functions. Defaults to 10000.
    share_server_address: Use this to specify a custom FRP server and port for sharing Gradio apps (only applies if share=True). If not provided, will use the default FRP server at https://gradio.live. See https://github.com/huggingface/frp for more information.
    share_server_protocol: Use this to specify the protocol to use for the share links. Defaults to "https", unless a custom share_server_address is provided, in which case it defaults to "http". If you are using a custom share_server_address and want to use https, you must set this to "https".
    auth_dependency: A function that takes a FastAPI request and returns a string user ID or None. If the function returns None for a specific request, that user is not authorized to access the app (they will see a 401 Unauthorized response). To be used with external authentication systems like OAuth. Cannot be used with `auth`.
    max_file_size: The maximum file size in bytes that can be uploaded. Can be a string of the form "<value><unit>", where value is any positive integer and unit is one of "b", "kb", "mb", "gb", "tb". If None, no limit is set.
    enable_monitoring: Enables traffic monitoring of the app through the /monitoring endpoint. By default is None, which enables this endpoint. If explicitly True, will also print the monitoring URL to the console. If False, will disable monitoring altogether.
    strict_cors: If True, prevents external domains from making requests to a Gradio server running on localhost. If False, allows requests to localhost that originate from localhost but also, crucially, from "null". This parameter should normally be True to prevent CSRF attacks but may need to be False when embedding a *locally-running Gradio app* using web components.
    ssr_mode: If True, the Gradio app will be rendered using server-side rendering mode, which is typically more performant and provides better SEO, but this requires Node 20+ to be installed on the system. If False, the app will be rendered using client-side rendering mode. If None, will use GRADIO_SSR_MODE environment variable or default to False.
    pwa: If True, the Gradio app will be set up as an installable PWA (Progressive Web App). If set to None (default behavior), then the PWA feature will be enabled if this Gradio app is launched on Spaces, but not otherwise.
Returns:
    app: FastAPI app object that is running the demo
    local_url: Locally accessible link to the demo
    share_url: Publicly accessible link to the demo (if share=True, otherwise None)
Example: (Blocks)
    import gradio as gr
    def reverse(text):
        return text[::-1]
    with gr.Blocks() as demo:
        button = gr.Button(value="Reverse")
        button.click(reverse, gr.Textbox(), gr.Textbox())
    demo.launch(share=True, auth=("username", "password"))
Example:  (Interface)
    import gradio as gr
    def reverse(text):
        return text[::-1]
    demo = gr.Interface(reverse, "text", "text")
    demo.launch(share=True, auth=("username", "password"))
r   )r;   r  NzTYou cannot provide both `auth` and `auth_dependency` in launch(). Please choose one.c              3  4   #    U  H  oS    (       + v   M     g7f)r   Nrt   r  authenticables     rn   r   Blocks.launch.<locals>.<genexpr>	       GYMQ'''Y   zOYou have provided an empty username in `auth`. Please provide a valid username.c              3  4   #    U  H  oS    (       + v   M     g7f)rZ   Nrt   r  s     rn   r  r  	  r  r  zOYou have provided an empty password in `auth`. Please provide a valid password.r  rk  GRADIO_ALLOWED_PATHS,GRADIO_BLOCKED_PATHSz.`allowed_paths` must be a list of directories.z.`blocked_paths` must be a list of directories.__FGRADIO_SSR_MODEFalsetrueGRADIO_NODE_PATH)server_nameserver_port	node_path)r  r  r  r  zInvalid local_url: z[Rerunning server... use `close()` to stop if you need to change `launch()` parameters.
----xxxi )http_server)rh  r  r  r}  r~  r  r\  ThttphttpsRUNNING_LOCALLY_SSRRUNNING_LOCALLYzstartup-events)verifytimeoutzRunning Gradio in a Colab notebook requires sharing enabled. Automatically setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).
zKaggle notebooks require sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).
zSagemaker notebooks may require sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).
GRADIO_SHAREzMonitoring URL: zmonitoring/)TNzWhen localhost is not accessible, a shareable link must be created. Please set share=True or check your proxy settings to allow access to localhost.COLAB_DEBUG_TRUECOLAB_DEBUG_FALSECOLAB_WARNINGz:Setting share=True is not supported on Hugging Face Spacesz;Setting share=True is not supported in the Wasm environment)
local_host
local_portrc   r  rZ   SHARE_LINK_DISPLAYSHARE_LINK_MESSAGEzNot able to set up tunnel!COULD_NOT_GET_SHARE_LINK_CHECKSUMCOULD_NOT_GET_SHARE_LINK%COULD_NOT_GET_SHARE_LINK_MISSING_FILEPUBLIC_SHARE_TRUE)HTML
Javascriptdisplayg      ?z<div><iframe src="	" width="
" height="zx" allow="autoplay; camera; microphone; clipboard-read; clipboard-write;" frameborder="0" allowfullscreen></iframe></div>aW  (async (port, path, width, height, cache, element) => {
                        if (!google.colab.kernel.accessAllowed && !cache) {
                            return;
                        }
                        element.appendChild(document.createTextNode(''));
                        const url = await google.colab.kernel.proxyPort(port, {cache});

                        const external_link = document.createElement('div');
                        external_link.innerHTML = `
                            <div style="font-family: monospace; margin-bottom: 0.5rem">
                                Running on <a href=${new URL(path, url).toString()} target="_blank">
                                    https://localhost:${port}${path}
                                </a>
                            </div>
                        `;
                        element.appendChild(external_link);

                        const iframe = document.createElement('iframe');
                        iframe.src = new URL(path, url).toString();
                        iframe.height = height;
                        iframe.allow = "autoplay; camera; microphone; clipboard-read; clipboard-write;"
                        iframe.width = width;
                        iframe.style.border = 0;
                        element.appendChild(iframe);
                    })z<({port}, {path}, {width}, {height}, {cache}, window.element))portr   r(  r)  cacher  browserinline)launch_methodis_google_colabis_sharing_onis_spacer  ps1GRADIO_DEBUG0)gradio.routesr;   rX  rb  r#  r   callabler_   r  r  r-  r  r  r  auth_messager  r)  r(  r,  r:  rg   r   r!  r   r=  rH  r;  r  splitr  r<  r{  r   _parse_file_sizerU  r/  r   r   rV   r^   rF  r  r
  rw  max_thread_countr_  r   r   r  r.  r   r  rJ   r  r6   r  node_processr  rg  
server_apprh  r%  r&  r`   printregister_appgradior  start_serverr  rstripr7   local_api_urlr  serverr]  rT  kaggle_check	is_kaggler  r  rl   
startswithr[  r   enformatset_server_apphttpxrun_startup_eventsasynciocreate_taskrun_extra_startup_eventsis_sagemakerr  analytics_keyr"  r   url_okr+  r'  setup_tunnelrc   r   r   r  r  r   error_analyticsr/   rC   r
   existsrD   rA   rB   
webbrowserr  ipython_checkIPython.displayr  r  r  r  sleepjsondumpsartifactImportErrorr   r  launched_analyticsr   r   flagsinteractivern  block_threadrF   ):rm   r  	inbrowserr  debugr
  r-  r  prevent_thread_lockr  r  r  r)  r(  r,  r}  r~  r  r:  r  rH  r;  r<  r=  r  rg   r  r  r  rU  r"  r  r  r  r  r  r  r;   allowed_paths_envitemblocked_paths_envrc  r&  r  r  r  	share_envr'  
parsed_urlr   linkr  r  r  r  coder   is_in_interactive_modes:                                                             rn   r  Blocks.launch	  s   D 	&,,#{{MMO ;f  TNNtAw..tAw--DII99Xdii00GTYYGGGe GTYYGGGe )$
($&<#ZZ^^,>CDN&DN !.D "

/Er J$%)->-D-DS-I&-ITDJJL-I&" &("!.D "

/Er J$%)->-D-DS-I&-ITDJJL-I&" &("$,,d33MNN$,,d33MNN$$&"33MB==++-99$"$UYYKr 2EI . 58K5??$D0S&'2$**, !!  ' YY0':@@BfL 	 j&8&8mo
 ==! 0 )"nn ED!4#4dn JNMD!MDNT5F &)^^+!#]]&
 	
$( ??dnnc22 #6t~~6F!GHHr !!##	 ''1.  ,, + + +!-)= -   +&DN$(NN$9$9#$>#?
|1!MD* DK"DO!--/DM"//1DN(<D%)> *.: & !%D >>,,W55  M
 %%dmmE }} JJ45 $56 
 ahht}}d.>.>@P@PQRKK&&t7%% 		))*.9%  '') ##D$A$A$CD  	 =}} G "
 f "
"" m "
"
 IIn5	(Y__->&-H!%DJJ"4>>"2+dhh>T>T=UV "3l!B
 &&%%dnn55JJ g  ==gjj!345gjj!456::gjj1889I9IJK::}}P #
!!Q #
::$>>) * 7 7#'#3#3#'#3#3$($4$4-1-F-F	!I "*)!4J%/335
12F&DN gjj!56==dnnMN'**%9:;0 !3!3gjj!456!DNZ//%)ZZDNN4>>DOOD! >((*F4EE::$..(//??

4( )//??#,T^^,<Idjj\Q[\`\g\g[h  ia  b H ]]0 [aa!ZZ(8(89!ZZ_"jj4#zz$++6"jj/ b 1D@  *$/H#,T^^,<Idjj\Q[\`\g\g[h  ia  b H !)! 4,e44.7X#'==!% MM5		D ((t4!%gc5#)):O:O&P!Q 299^S12a7&& (. #** T__dnndnnMNNC&&B  ))--.IJ!%"
a!677

#FGNN' 
 +&--//'**%?@AA

#JKRR'&+)	 l  sL   .z!)z&Cz+ 0B >D" +6A9~=5>~=9>~==c           	     F   SnUb  SnUR                  SS5        U R                  b/  UR                  SU R                   35        UR                  5         OKU R                  (       a/  UR                  SU R                   35        UR                  5         O[        S5      eUb  SnU R                  be  UR                  S	UR                  S
U R                  -   S-   [        U R                  5      -   S-   [        U R                  5      -   S-   5      05        O[        S5        UbH  SnU R                  b  UR                  SU R                  5        OUR                  SU R                  5        U R                  (       a#  U(       a  SU0n[        R                  " U5        ggg)a  
A catch-all method for integrating with other libraries. This method should be run after launch()
Parameters:
    comet_ml: If a comet_ml Experiment object is provided, will integrate with the experiment and appear on Comet dashboard
    wandb: If the wandb module is provided, will integrate with it and appear on WandB dashboard
    mlflow: If the mlflow module  is provided, will integrate with the experiment and appear on ML Flow dashboard
rk  NCometMLzCreated fromrS  zgradio: zPlease run `launch()` first.WandBzGradio panelz<iframe src="r  r  z" frameBorder="0"></iframe>zAThe WandB integration requires you to `launch(share=True)` first.MLFlowzGradio Interface Share LinkzGradio Interface Local Linkintegration)	log_otherr'  log_textendr&  r   logHtmlr`   r(  r)  r  	log_paramr  r   integration_analytics)rm   comet_mlwandbmlflowanalytics_integrationr   s         rn   r  Blocks.integrate  s    !#$-!~x8~~)!!HT^^,<"=>!!HT^^,<"=> !?@@$+!~~)		&

+"nn-)* "$**o. +	+
 "$++./ <<)
 W $,!~~)  !>O  !>O!!&;!#89D++D1 '<!rq   c                    [         R                  (       a4  U R                  R                  5         U R                  R                  5         U R                  R                  5         SU l        U R                  R                  R                  5         U R                  (       a  U R                  R                  5         SU R                  l        U(       a  [        SU R                   35        gg! [        [        4 a     gf = f)z<
Closes the Interface that was launched and frees the port.
Fz Closing server running on port: N)r   r  rw  _cancel_asyncio_tasksr  closer%  rh  
stop_eventrh   r  startup_events_triggeredr  r  r   OSError)rm   verboses     rn   r  Blocks.closeH  s    	!! 113557KK#DOHH##%{{!!# 16DHH-89I9I8JKL ( 		s   C)C- -D ?D c                     [         R                  " S5        M  ! [        [        4 aV    [	        S5        U R
                  (       a  U R
                  R                  5         [         H  nUR                  5         M      gf = f)z,Block main thread until interrupted by user.g?z7Keyboard interruption in main thread... closing server.N)	r  r  KeyboardInterruptr  r  r  r  rE   kill)rm   tunnels     rn   r  Blocks.block_threade  sa    	

3 !7+ 	KL{{!!#) *		s    A#B Bc                    U R                   R                  5         SU R                   l        SU l        U R	                  5         g)zGEvents that should be run when the app containing this block starts up.FTN)rw  r  stoppedr%  rK  ru   s    rn   r  Blocks.run_startup_eventss  s1    #rq   c                T   #    U R                    H  nU" 5       I S h  vN   M     g  N	7fr   )r  )rm   startup_events     rn   r  Blocks.run_extra_startup_events{  s#     !66M/!! 7!s   (&
(c                   U R                   n0 0 S.nU R                  R                  5        GH  nUR                  (       a  UR                  SL a  M&  U(       d  UR
                  (       d  M@  / / UR
                  S.n[        R                  " UR                  5      nSnUR                  n[        U5       GH  u  pUS    H  nUS   U
R                  :X  d  M    O   Sn  GOUS   S   nU R                  US      R                  (       a  MW  US   R                  S	S
U
R                   35      nU R                  US   5      n[        U[         R"                  5      (       d  [%        U< S35      eUR                  SUR                  S5      5      nUR'                  5       n[(        R*                  " U5      nUR                  (       a"  U	[-        U5      :  a  Xi   S   S;  a  Xi   S   nOSU	 3nUS   R                  S5      b  SnUS   S   nO=UR                  (       a(  U	[-        U5      :  a  Xi   S   (       a  Xi   S   c  SnSnOSnSnUS   R/                  UUUUUUUR                  SS5      S.UR1                  5       US.5        GM     UR2                  nU GH.  nUS    H  nUS   UR                  :X  d  M    O   Sn  GO	US   S   nU R                  US      R                  (       a  MU  US   R                  S	SUR                   35      nU R                  US   5      n[        U[         R"                  5      (       d  [%        U< S35      eUR                  SUS   5      nUR'                  5       n[(        R*                  " U5      nUS   R/                  UUUUR                  SS5      S.UR1                  5       S.5        GM1     U(       a  GM  XSS   S UR                   3'   GM     U$ )!z
Gets the information needed to generate the API docs from a Blocks.
Parameters:
    all_endpoints: If True, returns information about all endpoints, including those with show_api=False.
)named_endpointsunnamed_endpointsF)r   returnsrH  r   r]   Tr   r   label
parameter_z is not a Componentr  r  r   )r<  r  result_callbacksparam_r   NrZ      r   additional_descriptionrk  )r  description)r!  parameter_nameparameter_has_defaultparameter_defaultr  python_typer  example_inputvalue_r  r   r'  )r!  r  r+  r  r  r\  )r   r  r   r/  r<  rH  r   get_function_paramsr0  r  r^   r   rz   r   rR  r_   r   rM   rP  r  r   json_schema_to_python_typer  r   
capitalizer1  )rm   all_endpointsr   r  r/  dependency_infofn_infoskip_endpointr0  r  input_blockr  r  r!  rQ  infoexampler+  r(  r)  r*  r1  r}  s                          rn   get_api_infoBlocks.get_api_info  s    ')C((//#B55BKK50 -/BBKKXO//6G!MYYF&/&7"!'!5I +//9 "6 %)M )&1;;y/88!'*..w*[__DU8VW)))D/:!$
(<(<==#th.A$BCC }}%8)--
:ST--/*EEdK EEG,q)GH &-^A%6N'-eW%5N W%))'2>,0)(1'(:7(C%EEG,q)q)1,0)(,%,1)(,%-44!&*81F-> $$/+/884Lb+Q( &*__%6)0e '8D jjG!'!5I !%%/ "6 %)M )&1;;y/88!'*..w&8HI)))D/:!$
(<(<==#th.A$BCC }}%99Z;PQ--/*EEdK	*11!& $$/+/88M2+F( &*__%6
# : !=AP*+a},=>Y $\ rq   c           	        / nU H  n[        U[        5      (       a  UOUS   n[        U[        5      (       a  UOUS   nU R                  U5      nUc\  U[         Vs/ s H&  n[        U[        5      (       a  UR
                  OUPM(     sn;   a  [        R                  nO[        SU S35      e[        Xv5      nUR                  U5        M     U$ s  snf )Nr   rZ   zCannot find Block with id: z) but is present as a target in the config)r_   rn  r   r   r-   r  r!   r   r   r   r   )	rf  r  r  target_eventsr  	target_idr  rc  events	            rn   rt  Blocks.get_event_targets  s     F #-VS"9"9vayI$.vs$;$;J$((3E}!."!. )35-(H(HE$$eS!."  $..E$5i[@ij  E.E  '% & "s   -Cc                   [        5       (       a  [        S5      eU(       aL  UR                  S5      n[        R                  " S5      nUR                  U5      (       d  [        SU S35      eU[        ;   a  [        SU S35      eUc^  UR                  5       R                  SS	5      nS
R                  U Vs/ s H!  oDR                  5       (       d  US	:X  d  M  UPM#     sn5      nU[        ;   d"  X R                   Vs/ s H  oUS   PM	     sn;   a5  SU-   nU[        ;   a  M  X R                   Vs/ s H  oUS   PM	     sn;   a  M5  U R                  R                  X!45        X l        U $ s  snf s  snf s  snf )ak  
Adds a new page to the Blocks app.
Parameters:
    name: The name of the page as it appears in the nav bar.
    path: The URL suffix appended after your Gradio app's root URL to access this page (e.g. if path="/test", the page may be accessible e.g. at http://localhost:7860/test). If not provided, the path is generated from the name by converting to lowercase and replacing spaces with hyphens. Any leading or trailing forward slashes are stripped.
Example:
    with gr.Blocks() as demo:
        name = gr.Textbox(label="Name")
        ...
    with demo.route("Test", "/test"):
        num = gr.Number()
        ...
zzYou cannot create a route while inside a Blocks() context. Call route() outside the Blocks() context (unindent this line).r\  z#^[a-zA-Z0-9-._~!$&'()*+,;=:@\[\]]+$zPath 'z' contains invalid characters. Paths can only contain alphanumeric characters and the following special characters: -._~!$&'()*+,;=:@[]zRoute with path 'z' already exists r  rk  r   r   )r#   r   r  recompilematchr9   r   replacer  isalnumr  r   r   )rm   r   r   valid_path_regexletterr   s         rn   routeBlocks.route  s\     M  ::c?D!zz*PQ#))$// TF  #j  k  ?"06FGHH<::<''S1D77&*PdFnn.>.>&C-dPD o%jj1Qjdq'j1Q)Q:D o%jj1Qjdq'j1Q)Q

4,'  Q1Q1Qs   9E-E- E23E7)Rr   rw  r;  r  r8  r*  rh  r2  r  r-  r  r<  r   r   r  r   r  r#  r  r/  r"  r	  r  rb  r  r,  r  r  rl   r  r)  r6  rT  r  r%  r  r=  r  r  r&  rU  r
  r  r  r  r  r  r7  r   r  rd   r  r  r5  r9  r[  r>  r  r  r=  r  r  r  r  r  r  r  r'  rH  r  r+  r:  r  rg   r  r   r  r  r  r4  r3  r(  )NNr   rS  NNNNNFFN)r  zTheme | str | Noner  r  r  r`   r4  r`   r  r   r@  (str | Path | Sequence[str | Path] | Noner=  r   r  r   rA  rJ  r  r   r  r   r  ztuple[int, int] | None)r   dict[int, Component | Block])r   rK  )r   zdict[int, BlockFunction])r]   rn  r   Component | BlockContext)r   r&   r  zlist[Callable]rX   r`   r   r  )r/  zCallable[..., Any]r   None)r   )r  rn  r   r   )r  rn  r<  r   )NNNNFN)r  BlockFunction | intr  	list[Any]r  zAsyncIterator[Any] | Noner  Request | list[Request] | Noner  r   r  EventData | Noner  r   r  SessionState | None)r  rn  r0  rO  r   rO  )r  rn  r1  rO  r   rO  )r  r-  r0  rO  )F)r  r-  r0  rO  r  rR  r  r   )r  r-  r  zAny | list[Any])r  r-  r  list | dictr  rR  r   rO  rs   )r  r-  r   r  r  r   r  rr  r=  r   r  r   r   r  )r  r-  r   r  r  r   r  rr  r  r   r)  r   r   r  )
NNNNNNTFFN)r  rN  r0  rO  r  rR  r  rP  r  zAsyncIterator | Noner  r   r  r   r  rQ  r  r   r)  r   r  r   r=  r   r   r   )r  r-  r  rR  r   ztuple[list[int], list])r   r&   r   r)  )rp  NN)rx  zfloat | Literal['auto']r*  r  rt  rr  rn  zint | None | Literal['not_set'])NFNFr  NNFFNN)Jr  r  r  r   r  r  r  r   r
  rn  r-  zKCallable[[str, str], bool] | tuple[str, str] | list[tuple[str, str]] | Noner  r   r  r   r  r   r  r   r  rr  r)  rn  r(  z	int | strr,  r   r}  r   r~  r   r  r   r:  r   r  r   rH  r   r;  r   r<  r   r=  r   r  dict[str, Any] | Nonerg   rn  r  r   r  zLiteral['http', 'https'] | Noner  z.Callable[[fastapi.Request], str | None] | NonerU  zstr | int | Noner"  r  r  r   r  r   r  rr  r  r  r  r  r  r   r   ztuple[App, str, str]r  )r  ModuleType | Noner  rU  r   rM  T)r  r   r   rM  )r   rM  )r1  r   r   rT  )rf  zdict[int, Block]r  r  r  r`   r   r  )r   r`   r   r   r   r  )7r   r   r   r   __doc__ro   r   r   setterr  rR  rX  r   r~  rY  r\  r  r  rU   r  r  r  r  r  r  r   r  r  r$  r-  r  r8  rK  r   r_  r  r#  rk  r   rE  r{  r   r  r  r  r  r  r  r  r8  staticmethodrt  rH  r   __classcell__)r   s   @rn   r  r    sf    H %))->B?C! /3S!S 'S 	S
 S S <S S S =S S S -S Sj * * ]]+ + ' ' ? ? _ _ _ 	_
 
_ _B" 
 
!
F<|G 12$ 0!l /337#'+"'%)[
%[
 #[
 ,	[

 1[
 [
 %[
  [
 #[
z4" N $&& & #	&
 &P+ZTT !T #	T
 
Tx !%33 3 !	3
 3 3 3 
3x $     !	 
       
 L &*26)-#'#'+"&## $U%U U #	U
 0U 'U !U U %U  U U U U 
Un1%1.A1	1"
".` * Z 7= $#	' FO'3' ' 	' $C' 'RY  #! #'$) "&"&vO  !#'"&#'+/'///*.*. $,0&++/AEJN*.)- '+ $ $QvOvO vO 	vO
 vO vO XvO !vO "vO vO  vO  vO  !vO" #vO$ !%vO&  'vO( !)vO* )+vO, -vO. /vO0 1vO2 (3vO4 (5vO6 7vO8 *9vO: !$;vO< )=vO>  ??vO@ HAvOB (CvOD 'EvOF GvOH %IvOJ KvOL MvON OvOP QvOR 
SvOt #'$(	52 !52 "	52
 
52n:	"wr *6:EH	 2 Z% %rq   r  )	metaclassrV  )rc  rL  r|  r   r'  r   )r  z	list[int]r  r   r   rS  )
__future__r   r  r  r   r  r   r  r   r0  rA  ra   r  r   r  r  r  r  collectionsr   collections.abcr   r   r   r   r	   pathlibr
   r`  r   typingr   r   r   r   r   urllib.parser   r   r  fastapir  r   gradio_clientr   r   gradio_client.documentationr   r  r   r   r   r   r   r   r   r   gradio.blocks_eventsr   r   r    gradio.contextr!   r"   r#   r$   r%   gradio.data_classesr&   r'   r(   r)   r*   r+   gradio.eventsr,   r-   r.   gradio.exceptionsr/   r0   r1   r2   gradio.helpersr3   r4   r5   gradio.node_serverr6   gradio.route_utilsr7   r8   r  r9   r:   r;   r<   gradio.state_holderr=   r>   gradio.themesr?   r  r@   r  gradio.tunnelingrA   rB   rC   rD   rE   gradio.utilsrF   rG   rH   rI   rJ   rK   rL   rU  r  gradio.components.baserM   gradio.renderablerN   Base
MonochromeSoftGlassOriginCitrusOceanr   rO   __annotations__rQ   r   r-  r~  r  r  r  )rG  s   0rn   <module>r{     s-   "       	  	   
     # M M   ; ; -    ! / 0
 
 
 I H   
  > = 0 6 @ @ 9 1 -   
 0,
 		%	 FFAI	%! R Rj]5 ]@H
 H
X MQ#26EI2)-6L8 L8^
 
(G[&(;| \<: |  <| w  F%s   	I$ (I3$I0/I0