
    ;3hSO                      d Z ddlmZ ddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZ ddlmZ ddlmZ ddlmZmZmZmZm Z m!Z! ddl"Z"ddl#Z#ddl$Z$ddl%Z%ddl"m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ dd	l,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 dd
l3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9 ddl:m;Z< ddl=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZD ddlEmFZF ddlGmHZI ddlJmKZK ddlLZLddlLmMZMmNZNm;Z;mOZO ddlPmQZQ ddlRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\ ddl]m^Z^m_Z_ ddl`maZa ddlbmcZc ddldmeZe ddlfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZr ddlsmtZt ddlumvZvmwZwmxZxmyZymzZzm{Z{m|Z| ddl}m~Z~ dd lmZmZmZmZ erdd!lmZ ddlZddlZ ej                           e!eWej                  j                  d"      j                  d#      j                               Z e!eWej                  j                  d"      j                  d$      j                               Z e!eWej                  j                  d"      j                  d%      j                               Z e       Zh d&Zej$                  j'                  d'      xs!  e e ej*                               d"z        Z G d( d)e/      Zd* Z e6e+      Zeej4                  j6                  d,<    e#j8                   e#j:                  d-d./       e#j<                  d0      1      Z ei       Z G d2 d3e)      Zd:d4Zd;d5Z e>       	 	 	 	 d<dddddddd6dddddddd7	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d=d8       Zg d9Zy)>zImplements a FastAPI server to run the gradio interface. Note that some types in this
module use the Optional/Union notation so that they work correctly with pydantic.    )annotationsN)AsyncIteratorCallable)Path)Empty)TYPE_CHECKINGAnyLiteralOptionalUnioncast)	APIRouterBackgroundTasksDependsFastAPIHTTPExceptionstatus)FileResponseHTMLResponseJSONResponsePlainTextResponseResponseStreamingResponse)OAuth2PasswordRequestForm)Jinja2Templates)	WebSocketWebSocketDisconnect)utils)document)ServerMessage)TemplateNotFound)parse_options_header)BackgroundTask)
UploadFile)RedirectResponse)ranged_responseroute_utilsr   
wasm_utils)Context)

CancelBodyComponentServerBlobBodyComponentServerJSONBodyDataWithFilesDeveloperPathPredictBodyPredictBodyInternal	ResetBodySimplePredictBodyUserProvidedPath)ErrorInvalidPathError)I18n)start_node_server)attach_oauth)
API_PREFIXCustomCORSMiddlewareFileUploadProgress FileUploadProgressNotQueuedError!FileUploadProgressNotTrackedErrorGradioMultiPartParserGradioUploadFileMultiPartExceptionRequestcompare_passwords_securelycreate_lifespan_handlermove_uploaded_files_to_cache)process_video_with_ffmpeg)CloseStreamMessageEstimationMessageEventMessageHeartbeatMessageProcessCompletedMessageProcessGeneratingMessageUnexpectedErrorMessage)StateHolder)cancel_tasksget_node_pathget_package_versionget_upload_folder)Blockgradio	templatesztemplates/frontend/staticztemplates/frontend/assets>   	audio/ogg	audio/wav	image/gif	video/ogg
audio/mpeg
image/jpeg
image/webp
text/plain
video/webm	image/png	video/mp4application/jsonGRADIO_TEMP_DIRc                  <    e Zd ZdZedd       ZddZedd       Zy)ORJSONResponser`   c                x    t        j                  | t         j                  t         j                  z  t              S )Noptiondefault)orjsondumpsOPT_SERIALIZE_NUMPYOPT_PASSTHROUGH_DATETIMEstrcontents    M/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/routes.py_renderzORJSONResponse._render   s-    ||--0O0OO
 	
    c                ,    t         j                  |      S N)rc   rp   )selfrn   s     ro   renderzORJSONResponse.render   s    %%g..rq   c                J    t         j                  |       j                  d      S )Nutf-8)rc   rp   decoderm   s    ro   _render_strzORJSONResponse._render_str   s    %%g.55g>>rq   N)rn   r	   returnbytes)rn   r	   rz   rl   )__name__
__module____qualname__
media_typestaticmethodrp   ru   ry    rq   ro   rc   rc      s2    #J
 
/ ? ?rq   rc   c                    t        j                  t        j                  |       j	                  dd      j	                  dd      j	                  dd      j	                  dd            S )	N<z\u003c>z\u003e&z\u0026'z\u0027)
markupsafeMarkuprc   ry   replace)values    ro   toorjsonr      sS    ""5)	i	 	i	 	i	 	i	  rq   )	directoryr   d      )max_connectionsmax_keepalive_connectionsg      $@)limitstimeoutc                       e Zd ZdZdZ	 d
	 d fdZ ej                         Ze		 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z
ddZddZd Zd Ze		 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 dd	       Z xZS )Appz
    FastAPI App Wrapper
    Nc                   i | _         d | _        t        j                  d      | _        d| _        d | _        t               | _        i | _	        t               | _        t        j                         | _        t        j                         | _        t        j                  d      | _        t        j                  d      | _        d| _        t)               | _        d| _        d | _        d | _        g | _        || _        d | _        d | _        |j;                  dd        |j;                  dd        i | _        t?        |   di | y )N   F    r   docs_url	redoc_urlr   )!tokensauthsecretstoken_urlsafeanalytics_keymonitoring_enabledblocksrM   state_holder	iteratorssetiterators_to_resetr   safe_get_locklocksafe_get_stop_event
stop_event	cookie_idqueue_tokenstartup_events_triggeredrQ   uploaded_file_dirchange_countchange_typereload_error_message_asyncio_tasksauth_dependencyapi_infoall_app_info
setdefaultcustom_component_hashessuper__init__)rt   r   kwargs	__class__s      ro   r   zApp.__init__   s   
 	$2226"',0'M35,/E'')	335 ..r2"004(-%!2!4!">B04!24.  	*d++t,79$"6"rq   c                  K   | j                   j                  }|r|j                  |d      }| j                   j                  r|d| j                   j                   z  }| d| d| | }| d| }|r|d| z  }|r||z  }t	        | j
                        }	||	d<   t        |      |	d<   t        j                  d      rd|	d	<   t        j                  j                  | j                  t        j                  |      |	
      }
t        j                  j                  |
d       d {   }t!        |j#                         |j$                  |j
                  t'        |j(                              S 7 Hw)N ?z://:zx-gradio-serverzx-gradio-portGRADIO_LOCAL_DEV_MODE1zx-gradio-local-dev-modeheadersTstreamstatus_coder   
background)urlpathr   querydictr   rl   osgetenvr   clientbuild_requestmethodhttpxURLsendr   	aiter_rawr   r#   aclose)requestserver_name	node_portpython_portschememounted_path	full_pathr   
server_urlr   new_requestnode_responses               ro   proxy_to_nodezApp.proxy_to_node   sf     KK$$	!)),;I;;1W[[../00IK=)YK@xs;-0
Ak]++J,&Jw'%/!"#&{#3 99,-14G-.jj..NNEIIcNG / 
 "jjook$oGG ##%%11!))%m&:&:;	
 	
 Hs   D&E3(E1)A	E3c                   |j                   }|0t        |      s|D ci c]  }|d   |d    c}| _         n|| _         nd | _         || _        t        j                         | _        |j                  | _        i | _        |j                  xs |j                  xs d| _        | j                  j                  |       y c c}w )Nr      r   )r   callabler   r   getcwdcwdfavicon_pathr   	root_pathcustom_mount_pathr   
set_blocks)rt   r   r   accounts       ro   configure_appzApp.configure_app&  s    {{D>CGHWQZ3H	 	DI99;"//))KV-E-EK$$V, Is   B=c                H    | j                   t        d      | j                   S )Nz+No Blocks has been configured for this app.)r   
ValueError)rt   s    ro   
get_blockszApp.get_blocks7  s"    ;;JKK{{rq   c                r   t        j                  |      | j                  sJ t        fd| j                  j                  D              }|st        d      j                  j                  d      }i }t        j                  |rdt        j                   |d<   t        j                  d|      }|S )Nc              3  v   K   | ]0  }j                   t        j                  |      j                   k(   2 y wrs   )hostr   r   ).0rootr   s     ro   	<genexpr>z*App.build_proxy_request.<locals>.<genexpr>A  s-      
15CHH		$,,,
s   69zThis URL cannot be proxied.z	.hf.spacezBearer AuthorizationGETr   )r   r   r   any
proxy_urlsPermissionErrorr   endswithr)   hf_tokenr   r   )rt   url_pathis_safe_url	is_hf_urlr   rp_reqr   s         @ro   build_proxy_requestzApp.build_proxy_request<  s    ii!{{{  
9=9O9O
 
 !"?@@HH%%k2	'I)01A1A0B'CGO$%%eS'%Brq   c                T    | j                   D ]  }|j                           g | _         y rs   )r   cancel)rt   tasks     ro   _cancel_asyncio_taskszApp._cancel_asyncio_tasksM  s(    '' 	DKKM	 rq   c           	        /0123456789 |xs i }|j                  dt                j                  xs d}t        |j	                  dd       g| |d<   t        dd|i|ddi0t        t              }0j                          t        j                  s0j                  t        |       |r0j                  d	      	 	 d fd
       }|j	                  d      |j	                  d      d0fd              3|j	                  d      |j	                  d      t        3      fd0fd              }|j	                  d      |j	                  d      d0fd              }	|j	                  d      |j	                  d      d0fd              }
|j	                  dt        |      g      	 	 d0fd       }0j                  d      0j                  d      t               f	 	 	 d0fd              }0j                   "0j                   j"                  rt%        0       n%0j	                  d      t        3      fd0fd       }0j	                  d      dd        }036fd!} j&                  D ]  }|d"   }|d#k7  s ||        	 d	 	 	 	 	 d0fd$50j)                  d%t*        &      0j	                  d%t*        &      t        3      d#d#f	 	 	 	 	 	 	 d/05fd'              60j	                  d(      d0fd)       }|j	                  d*t        |      g      |j	                  d+t        |      g      d0fd,              /|j	                  d-t        |      g      d/0fd.       }0j	                  d/t        |      g      0j	                  d0t        |      g      dd0 35fd1              }0j	                  d2      dd3       9|j	                  d4      	 	 	 	 	 	 	 	 	 	 d0fd5       }0j	                  d6      dd7       }0j	                  d8      09fd9       }|j)                  d:t        |      g      |j	                  d:t        |      g      d0fd;              }|j)                  d<t        |      g      |j	                  d<t        |      g      d0fd=              2|j                  d>      d0fd?       }|j-                  d>      d0fd@       }|j                  dA      d0fdB       }|j	                  dC      d0fdD       }|j	                  dE      	 	 	 	 	 	 	 	 	 	 d0fdF       }|j	                  dG      d0fdH       }|j	                  dIt        |      g      d2fdJ       }|j                  dK      |j                  dL      ddM              }|j	                  dN      t        3      f	 	 	 	 	 	 	 d0fdO       }|j                  dPt        |      g      |j                  dQt        |      g      |j                  dRt        |      g      |j                  dSt        |      g      t        3      f	 	 	 	 	 	 	 d0fdT                            }|j                  dUt        |      g      |j                  dVt        |      g      t        3      f	 	 	 	 	 	 	 d08fdW              }|j                  dXt        |      g      t        3      f	 	 	 	 	 d8fdY       }	 	 	 	 	 	 d0fdZ8|j                  d[      d0fd\       } |j	                  d]t        |      g      	 	 	 	 d7fd^       }!|j	                  d_t        |      g      	 	 	 	 d7fd`       }"	 	 	 	 	 	 d0fda7	 	 	 	 ddb4|j                  dct        |      g      |j                  ddt        |      g      	 	 d04fde              }#|j	                  dft        |      gt.        g      0fdh       }$|j	                  di      ddj       }%|j                  dkt        |      g      	 d	 	 	 	 	 d0 fdl       }&|j	                  dm      0fdn       }'|j	                  dot0        &      0j	                  dot0        &      0fdp              }(0j	                  dqt0        &      0fdr       })0j	                  ds      0j	                  dt      dd0fdu              }*0j	                  dv      0 fdw       }+0j	                  dxt        |      g      d0 fdy       },0j	                  dz      d0 fd{       }-|j                  d|t        |      g      	 	 d1fd}       }.d~ 10j3                  |       0S )Ndefault_response_class)NNlifespanr   debugT)prefix)strict_corshttpc           	       K   j                   }|4| j                  j                  j                  j                   xs dd      n| j                  j                  t	        dd       Չj
                  t        fdt        D              st        j                  @| j                  j                  xs t        t        j                  dd            t        _	        	 t        j                  | j                  xs dj
                  t        j                  | j                  j                   |xs d       d {   S  ||        d {   }|S 7 # t"        $ r}t%        |       Y d }~-d }~ww xY w7 )w)Nr   node_processc              3  F   K   | ]  }j                  d |         yw)/N)
startswith)r   r   r   s     ro   r   zIApp.create_app.<locals>.conditional_routing_middleware.<locals>.<genexpr>x  s      Vs!C5	 :Vs   !GRADIO_SERVER_PORT78600.0.0.0)r   r   r   r   getattrr   r   INTERNAL_ROUTESr   app_portportintr   r   r   node_server_namer   	Exceptionprint)r   	call_nextr   eresponser   r   s        @ro   conditional_routing_middlewarez6App.create_app.<locals>.conditional_routing_middlewarej  sA     %+$<$<! )4 KK$$,,V-E-E-KRP ))  FND9E((4VoVV||+'.{{'7'7 (3II&:FC<
!%(%6%6#"33@y",,LL#KK..-3&    "+7!33  % !a!3sO   CE6AE :E;E >E6
E4E6E 	E1E,'E6,E11E6z/userz/user/c                   j                   j                  |       S | j                  j                  dj                         xs( | j                  j                  dj                         }j                  j                  |      S )Naccess-token-access-token-unsecure-)r   cookiesgetr   r   r   tokenapps     ro   get_current_userz(App.create_app.<locals>.get_current_user  s     "".**733OO''/ O$$'=cmm_%MN  ::>>%((rq   z/login_checkz/login_check/c                p    j                   j                  | y t        t        j                  d      )NNot authenticatedr   detail)r   r   r   r   HTTP_401_UNAUTHORIZED)userr&  s    ro   login_checkz#App.create_app.<locals>.login_check  s;      S%8%8%@TEU"88AT rq   z/tokenz/token/c                    | j                   j                  dj                         }|j                  j                  |      dS )Nr   )r%  r-  )r"  r#  r   r   r$  s     ro   	get_tokenz!App.create_app.<locals>.get_token  s<     OO''-(GHE"CJJNN5,ABBrq   z/app_idz/app_id/c                <    dj                         j                  iS )Napp_id)r   r2  )r   r&  s    ro   r2  zApp.create_app.<locals>.app_id  s     cnn.5566rq   z/dev/reload)dependenciesc                >   K   dfd}t         ||       d      S w)Nc                 K   d}d}t        j                         }j                  }	 | j                          d {   ry j                  |k7  rSj                  }j                  dk(  r t        j                  j                         nd}dj                   d| d t        j                  |       d {    t        j                         |z
  |kD  rd t        j                          }7 7 :w)	N   皙?errorz{}event: 
data: 

zevent: heartbeat
data: {}

)
timeperf_counterr   is_disconnectedr   jsonri   r   asynciosleep)r   heartbeat_rate
check_ratelast_heartbeatcurrent_countmsgr&  s         ro   reload_checkerz>App.create_app.<locals>.notify_changes.<locals>.reload_checker  s     !#!
!%!2!2!4 # 0 0$44666''=8(+(8(8  #'9 !JJ#*B*B)CE!% 
 #*#//):(3%tNN!--
333((*^;nLBB)-! 6 4s"   9C9C5A?C9<C7=9C97C9text/event-streamr   r   fastapi.Request)r   )r   rG  r&  s     ro   notify_changesz&App.create_app.<locals>.notify_changes  s&     50 %w'. s   /loginz/login/c                   |j                   j                         |j                  }}j                  =t	        j
                  | dj                        }t        |t        j                        S t        j                        s'|j                  v rt        |j                  |         s1t        j                        rj                  j                  ||      rxt        j                  d      }|j                  |<   t!        ddi      }|j#                  dj$                   |dd	d
       |j#                  dj$                   |d       |S t'        dd      )NrM  r   
route_pathr   r   r   r   successTrm   r   none)keyr   httponlysamesitesecurer!  )rT  r   rU    zIncorrect credentials.r*  )usernamestrippasswordr   r'   get_root_urlr   r%   r   HTTP_302_FOUNDr   rB   __call__r   r   r   r   
set_cookier   r   )r   	form_datarY  r[  r   r%  r  r&  s          ro   loginzApp.create_app.<locals>.login  sA   
 "+!3!3!9!9!;Y=O=OhHxx"//#'!mm
 (Df>S>STTSXX&(.x(9KL388$):):8X)N--b1$,

5!'D0AB##'7!# $  ##0@! $ 
  #<TUUrq   /logoutc                   t        j                  | dj                        }t        |t        j
                        }|j                  dj                   d       |j                  dj                   d       t        j                  j                               D ]"  }j                  |   |k(  sj                  |= $ |S )Nrb  rO  rQ  r   r  )rT  r   r!  )r'   r\  r   r%   r   r]  delete_cookier   listr   keys)r   r-  r   r  r%  r&  s        ro   logoutzApp.create_app.<locals>.logout  s    "//#(!mm
 ,&BWBWX&&]3==/+JQT&U&&0@s '  "#**//"34 .Ezz%(D0JJu-.  rq   z/svelte/{path:path}c           	         t        t              dz  }t        t        t	        t        |            t        |                   S )Nsvelte)r   BUILD_PATH_LIBr   routes_safe_joinr.   rl   r3   )r   svelte_paths     ro   _zApp.create_app.<locals>._  s;    ~.9K !#k"235Ed5K rq   c                     j                  d  t              j                  d  dt              t              df	 	 	 	 	 d fd              }y )Nr  response_classr   c                     | ||      S rs   r   )r   r-  	deep_linkmainpages      ro   
page_routez7App.create_app.<locals>.attach_page.<locals>.page_route  s     GT4;;rq   )r   rK  r-  rl   rr  rl   )r#  r   r   )rt  ru  r&  r'  rs  s   ` ro   attach_pagez#App.create_app.<locals>.attach_page  sm    WWqZW=WWqa[W> $$45!#<(<< < ? ><rq   r   r   c                `   |d   }	 t        j                        dz  | z  dz  }|j                         r&t        j                  |j                               }d}nd}|r|D cg c]  }|d   |d   |   d   v r| }}||fS # t        t        t        j                  f$ r d}g }Y Iw xY wc c}w )N
components
deep_links
state.jsonvalidinvalididrt  )	r   r   existsrh   loads
read_bytesFileNotFoundErrorOSErrorJSONDecodeError)rr  configrt  rx  r   deep_link_state	componentr&  s          ro   load_deep_linkz&App.create_app.<locals>.load_deep_link*  s      -J ../"#  ##  ;;=!'doo.?!@J&-O&/O  &0! &.*>|*LL 
 
 .. &w0F0FG  "+
 s   AB $B+"B('B(r  ro  c           
        t        j                  dd       j                         }t        j                  | d| j
                        }j                  j                  |t        j                  |j                        }t        j                  ||      }d}|d   D cg c]  }|d   |d   |   d   v r| }	}|r |||      \  }	}||d	<   ||d
<   |	|d<   |j                  dg       D 
cg c]  }
|
d   |d   |   d   v r|
 c}
|d<   |d   |   d   |d<   ||d<   nLj                  rt        t        j                  d      d|j                   |j"                  |ddi iidgg g dd	}	 |j$                  rdnd} |       }t&        j)                  | |||d      }|S c c}w c c}
w # t*        $ r)}|j$                  rt-        d      |t-        d      |d }~ww xY w)Nzapplication/javascriptz.jsr  rO  rS  rx  r}  rt  rY  r  r3  layoutcurrent_pager)  r*  Tr   )	auth_requiredauth_messagespace_idr   rt  pagesrx  r3  r  zfrontend/share.htmlzfrontend/index.html)r  gradio_api_info)r   namecontextzqDid you install Gradio from source files? Share mode only works when Gradio is installed through the pip package.znDid you install Gradio from source files? You need to build the frontend by running /scripts/build_frontend.sh)	mimetypesadd_typer   r'   r\  r   r   r   r   safe_deepcopyr  update_root_in_configr#  r   r   r,  r  r  sharerT   TemplateResponser!   r   )r   r-  rt  rr  r   r   r  r  r  rx  
dependencytemplater  resperrr   r&  r  s                  ro   rs  zApp.create_app.<locals>.mainF  ss    7?^^%F++tf:--D
  S%8%8%@TEU,,V]];$::64H"( &,L%9! &.*>|*LL 
 
 2@!3/J
 &*z",;()'1|$ '-jj&D*"!$'6&>$+?+OO *~&
 $*&>$#7#Ax )-~&$$# & < <EX 
 &*$*$7$7 & (B0 T"$$&$&
-3\\)?T  #+7"3 11#!"(+: 2  g*L $ 
<<$R 
 %M 
s$   %F'2F,24F1 1	G#:$GG#z/gradio_api/deep_linkc                
   | j                   v rj                   |    j                  D cg c]  }t        j                  |       }}t	        j
                  |t        j                  t        j                  z  t              }t        j                  |      }t        j                        dz  |z  }|j                  dd       t        |dz  d      5 }|j                  |       d d d        |S yc c}w # 1 sw Y   |S xY w)Nre   ry  T)parentsexist_okrz  wbr   )r   rx  r   r  rh   ri   rj   rk   rl   r'   create_url_safe_hashr   r   mkdiropenwrite)session_hashcrx  components_jsonrr  r   fr&  s          ro   rr  z!App.create_app.<locals>.deep_link  s    s/// !--l;FF ''*
  #),,!558W8WW#
 (<<_M	 !6!67,FR	t<)l2D9 -QGGO,-  !-  s   C3C88Dz/info/z/infoc                   | j                   j                  dd      }|r=j                  s%j                         j	                  d      _        j                  S j
                  sjt        j                  j                         j	                               }t        t        t        t        f   |      }t        j                  |      }|_        j
                  S )Nall_endpointsFT)r  )query_paramsr#  r   r   get_api_infor   r   r  r   r   rl   r	   r'   'update_example_values_to_use_public_url)r   r  r   r&  s      ro   r   z App.create_app.<locals>.api_info  s     $0044_eLM'''*~~'7'D'DSW'D'XC$'''<< ..s~~/?/L/L/NOS#X9&NNxX'<<rq   z/openapi.jsonc                    |       }dt        j                         dd      t        j                         dd      t        di di id}|j                  d	i       j	                         D ]  \  }}|j                  d
d      sd|j                  dd|       |j                  dd      |j                  d      j                  dd      ddddi diiddddddi diididi}|d   d   d   d   d   d   }|j                  dg       D ]  }|d   }|j                  di       }	d|	v rt        |	      }	|	j                  dd        d|	v rd|	vrt        |	      }	d|	d<   |	||<   d!|v s]d"|d   d   d   d   vrd#d$i ii|d   d   d   d   d"<   |d!   |d   d   d   d   d"   d#   d$   |<    |d   d%   d   d   d   d   d   }
t        |j                  d&g             D ]a  \  }}|d'kD  rd(| nd)}|j                  di       }d|v rt        |      }|j                  dd        d|v rd|vrt        |      }d|d<   ||
|<   c ||d*   d+| <    |S ),z:Generate an OpenAPI schema from the Gradio app's API info.z3.0.2titlez
Gradio Appdescriptionr   )r  r  versionschemas)openapiinfopathsrx  named_endpointsshow_apiTpostz	Endpoint r  rm  r`   schemaobject)type
properties)requiredrn   200zSuccessful response)r  rn   )summaryr  operationIdrequestBody	responsesr  rn   r  
parametersparameter_namer  additional_descriptionNexample_inputexamplesexample1r   r  returnsr   output_outputr  z/run)
r  r   VERSIONr#  itemsrZ  r   r   pop	enumerate)r   r  r  endpoint_pathendpoint_info	path_itemrequest_propertiesparam
param_name
param_typeresponse_propertiesiretret_nameret_typer   r&  s                  ro   openapi_schemaz&App.create_app.<locals>.openapi_schema  sz    G$D"$S^^%5wM#*3>>+;]B#O&
 ("o	F 159JB0O0U0U0W OD,}$((T:#0#4#4)Y}o+F$ (5'8'8'K'4':':3'?'G'GS'Q(, 2$,xr.R5"(( "/D$6(08SU2V9&,"$	&	8 &/v%6}%Ei%P&&&(&*" +..|R@ TE!&'7!8J!&62!6J/:=%)*%5
"'?F#z1fJ6N%)*%5
-5
6*5?&z2&%/&#,V#4]#CI#N 2$ .8'2,G &f-m<YG 2(*
 >C?=S "&)-8CDVW&$&&-//9;1T8 '0&7&DU&KI&V&''('*# ((9(9)R(HI =FAs01A}8H"wwvr2H/8;#'> %=tD#x/F(4J#'>+3(4<'1= ;Dw$}o 67_ODb Mrq   z/config//configc                   t        j                  j                         j                        }t	        j
                  | dj                        }t	        j                  ||      } |       |d<   |r 	||d      \  }}||d<   ||d<   t        d      r&j                  rj                  j                  |d	<   nd |d	<   t        |
      S )Nr  rO  rY  r   )rt  rx  r  i18n_instancei18n_translationsrm   )r   r  r   r  r'   r\  r   r  hasattrr  translations_dictrc   )
r   rr  r  r   rx  r  r&  r   r'  r  s
         ro   
get_configz"App.create_app.<locals>.get_config  s     (()9)@)@AF++ID !66vtDF!1'!:F:.<YUW.X+
O'1|$,;()v/F4H4H.4.B.B.T.T*+.2*+!&11rq   z/static/{path:path}c                J    t        t        t        |             }t        |      S rs   )rk  STATIC_PATH_LIBr3   r   )r   static_files     ro   static_resourcez'App.create_app.<locals>.static_resource2  s    *?<LT<RSK,,rq   z7/custom_component/{id}/{environment}/{type}/{file_name}c           	         |dvrt        dd      t        j                         }t         fd|D        d       }|t        dd      |j                  }t
        j                  |   j                  }|t        dd      	 t        j                  |j                  t        | d|             }	t        t        t        t        |      j                               t        |	            }
  d| d| }|j"                  vrWt%        j&                  t        |
      j)                  d	
      j+                               j-                         j"                  |<   j"                  j/                  |      }ddi}|r||d<   |r+|j0                  j/                  d      |k(  rt3        d|      S t5        |
|      S # t        $ r t        dd      d w xY w)N)r   server  zEnvironment not supported.r*  c              3  J   K   | ]  }|j                         k(  s|  y wrs   )get_component_class_id)r   itemr}  s     ro   r   z@App.create_app.<locals>.custom_component_path.<locals>.<genexpr>E  s"     T$0K0K0MQS0STs   ##zComponent not found.r  -rw   )encodingzCache-Controlzmax-age=0, must-revalidateETagzif-none-matchi0  )r   r   r   )r   r   get_all_componentsnextr}   sysmodules__file__	safe_joinTEMPLATE_DIRr3   r5   rk  r.   rl   r   parentr   hashlibsha256	read_textencode	hexdigestr#  r   r   r   )r}  environmentr  	file_namereqrx  locationmodule_namemodule_pathrequested_pathr   rT  r  r   r&  s   `             ro   custom_component_pathz-App.create_app.<locals>.custom_component_path7  s    "66# #,H  113JT*TH #<RSS"--K++k2;;K"#<RSS!&))$vQyk%:;" $c${"3":":;< 0D D$q,C#5553:>>J(('(:AAC4)+ ++C0 1155c:G&(DEG")3;;???;wF(S'JJg66; $ # #,Bs   .F< <Gz/assets/{path:path}c                J    t        t        t        |             }t        |      S rs   )rk  rj  r3   r   )r   
build_files     ro   build_resourcez&App.create_app.<locals>.build_resourceu  s    ).:J4:PQJ
++rq   z/favicon.icoc                 ~   K   j                         } | j                   d      S t        | j                        S w)Nzimg/logo.svg)r   r   r   )r   r&  r  s    ro   faviconzApp.create_app.<locals>.faviconz  s;     ^^%F""*&~66#F$7$788s   :=z/proxy={url_path:path}c                  K   	 j                  |       }t        j                  |d       d {   }t        j                  |       \  }}|t        vr:|j                  j                  ddi       |j                  j                  ddi       t        |j                         |j                  |j                  t        |j                        	      S # t        $ r}t        dt        |            |d }~ww xY w7 ʭw)
NrX  r*  Tr   Content-Disposition
attachmentContent-Typeapplication/octet-streamr   )r   r   r   rl   r   r   r  
guess_typeXSS_SAFE_MIMETYPESr   updater   r   r   r#   r   )r   r   r  rp_resp	mime_typerm  r&  s         ro   reverse_proxyz%App.create_app.<locals>.reverse_proxy  s     O00: #KKtK<<G$//9LIq 22&&(=|'LM&&8R'ST$!!##//)'..9	  # O#CHE3NO<s2   C=C C=C;B"C=	C8C33C88C=z/file={path_or_url:path}c                  K   j                         }t        j                  |       rt        | t        j
                        S t        j                  |       rt        dd|  d      t        j                  |       }	 |j                         s|j                         st        dd|  d      	 ddlm} t        j                   ||j"                  |j$                  |j&                  z   j(                  t        j*                         g      \  }}|st        dd|  d      t-        j.                  |      \  }}	|t0        v s|dk(  r	|xs d	}
d
}nd	}
d}|j2                  j5                  dd      j7                         }|j9                  d      rd|v r|dd  }|j;                  d      \  }}|j=                         r|j=                         rwt?        |      }t?        |      }tA        |j2                        }||d<   |
|d<   tC        jD                  |tC        jF                  ||      |tI        jJ                  |            }|S tM        |ddi||
|jN                        S # t        $ r}t        dd|  d      |d }~ww xY ww)NrQ    zFile not allowed: .r   )_StaticFiles)blocked_pathsallowed_pathscreated_pathsallowedr  inliner  Ranger   zbytes=r     r  r  )stat_resultzAccept-Rangesr{   )r   content_disposition_typer   filename)(r   client_utilsis_http_url_liker%   r   r]  r'   starts_with_protocolr   r   abspathis_dirr~  r  gradio.data_classesr  is_allowed_filer  r  	all_pathsr   get_cache_folderr  r  r  r   r#  rZ  r  split	isnumericr  r   r&   RangedFileResponse	OpenRanger   statr   r  )path_or_urlr   r   abs_pathr  r  r  reasonr  rm  r   r!  	range_valstartendr   r  r&  s                    ro   filezApp.create_app.<locals>.file  su     ^^%F,,[9'#1F1F  //<#C+=k]!)LMM}}[1HU??$HOO,='/A+a-PQQ ->
 9#33$22$22\5K5KK"44e6L6L6NO	OGV #C+=k]!)LMM$//9LIq..&I2E&D*D
+3(7
+7(++GR8>>@I##H-#2B%abM	&__S1
s??$JEc(C"7??3G5MG12.8GN+.AA '11%=$&GGH$5	 H $O('2)A%! Q  U#C+=k]!)LMSTTUs+   A;J?0I  /F1J 	I?)I::I??Jz/stream/{event_id}c                   K   j                         j                  j                  |    }t        di |j	                         d|i}||_        |j                  j                          ddiS wNr   rF  rR  r   )r   _queueevent_ids_to_eventsr0   
model_dumpdatasignalr   )event_idbodyr   eventr&  s       ro   rm  zApp.create_app.<locals>._  s_     NN$++??IE&L):LGLDEJLL9%%s   A*A-c                  K   | j                          d {    	 	 | j                          d {   }t        di |}j                         j                  j
                  |   }t        di |j                         dd i}||_        |j                  j                          | j                  ddi       d {    7 7 7 	# t        $ r Y y w xY wwr9  )acceptreceive_jsonr/   r   r:  r;  r0   r<  r=  r>  r   	send_jsonr   )	websocketr?  r=  r@  rA  body_internalr&  s         ro   websocket_endpointz*App.create_app.<locals>.websocket_endpoint  s     ""$$$!*!7!7!99D&..DNN,33GGQE$7 %//+%59%M "/EJLL$$&#--ui.@AAA  % : B& sU   CCCC CB
C <C=C CC C 	CCCCz/stream/{event_id}/closec                   K   j                         j                  j                  |    }t        j                  |_        |j                  j                          ddiS w)NrF  rR  )r   r:  r;  mathinfrun_timer>  r   )r?  rA  r&  s     ro   rm  zApp.create_app.<locals>._  sJ     NN$++??IE!XXENLL9%%s   AAz9/stream/{session_hash}/{run}/{component_id}/playlist.m3u8c                Z  K   j                         j                  |    j                  |i       j                  |d       }|st        d      S d|j                   d}|j
                  D ]  }|d|d   ddz  }||d	    |d
    dz  }! |j                  r|dz  }t        |d      S w)Nr  r   z9#EXTM3U
#EXT-X-PLAYLIST-TYPE:EVENT
#EXT-X-TARGETDURATION:z*
#EXT-X-VERSION:4
#EXT-X-MEDIA-SEQUENCE:0
z#EXTINF:durationz.3fz,
r}  	extension
z#EXT-X-ENDLIST
zapplication/vnd.apple.mpegurlrn   r   )r   pending_streamsr#  r   max_durationsegmentsended)r  runcomponent_idr   playlistsegmentr&  s         ro   rm  zApp.create_app.<locals>._  s        /S"\4(	  C00TU[UhUhTi  jW  XH!?? Ghwz':3&?sCCwt}ogk.B-C2FFG ||.. -L s   B(B+z>/stream/{session_hash}/{run}/{component_id}/{segment_id}.{ext}c                n  K   |dvrt        dd      S j                         j                  |    j                  |i       j                  |d       }|st        dd      S t	        fd|j
                  D        d       }|t        dd      S |d	k(  rt        |d
   d      S t        |d
   d      S w)N)aactsrX  zUnsupported file extension)r   rn   r  zStream not foundc              3  4   K   | ]  }|d    k(  s|  yw)r}  Nr   )r   s
segment_ids     ro   r   z,App.create_app.<locals>._.<locals>.<genexpr>!  s     P!!D'Z:OAPs   zSegment not foundr\  r=  z	audio/aacrR  z
video/MP2T)r   r   rS  r#  r  rU  )r  rW  rX  r`  extr   rZ  r&  s      `   ro   rm  zApp.create_app.<locals>._  s      -'C9UVV  /S"\4(	  C9KLLPvPRVWGC9LMMe|KPPLQQs   B1B5z9/stream/{session_hash}/{run}/{component_id}/playlist-filec                  K   j                         j                  |    j                  |i       j                  |d       }|st        d      S |j                  sp|j
                  D cg c]  }|d   	 }}j                         j                  |      j                  |d|j                         d {   }|j                  |_        t        |j                        S c c}w 7 /w)Nr  rN  r=  T)	only_filedesired_output_format)r   rS  r#  r   combined_filerU  get_componentcombine_streamrd  r   r   )r  rW  rX  r   r_  stream_datare  r&  s          ro   rm  zApp.create_app.<locals>._+  s        /S"\4(	  C00''28//BQqyBB..*"]<0#^#"&.4.J.J $   (5'9'9$ 4 455 Cs   A&C')C 5A C'5C%60C'z/file/{path:path}c                2   K    | |       d {   S 7 wrs   r   )r   r   r7  s     ro   file_deprecatedz'App.create_app.<locals>.file_deprecatedE  s     dG,,,,s   z/reset/z/resetc                   K   ddiS w)NrR  Tr   )r@  s    ro   reset_iteratorz&App.create_app.<locals>.reset_iteratorI  s      t$$s   z/heartbeat/{session_hash}c                z     t        j                  dd      rdnd fd}t         |       d      S )zClients make a persistent connection to this endpoint to keep the session alive.
            When the client disconnects, the session state is deleted.
            GRADIO_IS_E2E_TESTNg      ?r6  c            
    4  K   t        j                  j                  j                               } 	 	 d t        j                  t        j                              }t        j                  || gt         j
                         d {   \  }}| |v rt        j                         	 z7 !# t         j                  $ r | j                         s| j                          t              }t        j                  t         d j                        }t        g       }j                         j                   j#                         D cg c]#  \  }}t%        d |j&                  D              r|% nc c}}w }	}}|	D ]B  }
j)                  t        j*                  ||j                         j                   |
   |	       D j,                  j.                  v rdj,                  j.                     _        j                         j2                  j4                  j7                  g       D ]X  }j                         j2                  j8                  |   }t:        j<                  |_        |j@                  jC                          Z Y y w xY ww)
NTzdata: ALIVE

)return_whenr  z/heartbeat/rO  )r  r=  r   c              3  2   K   | ]  }|d    dk(  s|  yw)r   unloadNr   )r   ts     ro   r   zFApp.create_app.<locals>.heartbeat.<locals>.iterator.<locals>.<genexpr>y  s     "NQqTX=M1"Ns   r&  r@  
gr_requestfnr   )"r@  create_taskr   waitrA  FIRST_COMPLETEDCancelledErrordoner  rA   r'   r\  r9   r   r0   r   fnsr  r   targetsadd_taskcall_process_apir   session_data	is_closedr:  pending_event_ids_sessionr#  r;  rJ  rK  rL  r>  r   )stop_stream_task	wait_taskr|  rm  r  r   r@  r  depunload_fn_indicesfn_indexr?  rA  r&  background_tasksrB  r   r  rY  s                ro   iteratorz3App.create_app.<locals>.heartbeat.<locals>.iterator[  s`    #*#6#6s~~7J7J7L#M 5// %,$7$7n8U$V	(/&(89(/(?(?) #a ,t3")"8"8":: 4 # #11 */446,335%gxlS$/$<$<$+*4['O&)mm%	
  3)5B 
 +...*:*>*>*D*D*F- &3""Nckk"NN - -) -
 ): 
H -55 + < <$'%)+.#&>>#3#7#7#A*3 6 
 (3+;+;+H+HHTXC,,99,GQ !^^-44NNRR("	/$ %(NN$4$;$;$O$O (%E .2XXEN!LL,,.	/ U*sI   /JAB. 
B,B. *J,B. .B&J(E=<DJJJJrH  rI  )r   r   r   )r  r   r  rY  r  rB  r&  s   ```` @ro   	heartbeatz!App.create_app.<locals>.heartbeatO  s8     &(YY/CT%JTPRN8 8t %XZ<OPPrq   z/run/{api_name}z/run/{api_name}/z/api/{api_name}z/api/{api_name}/c                  K   t        di |j                         d|i}t        j                  
j	                         | |      }
j	                         j
                  s'|j                  rt        dt        j                        t        j                  ||||      }t        j                  |t         d|  
j                        }	 t        j                  
||||       d {   }|S 7 # t        $ ru}t!        j"                  |
j	                         j$                        }	t'        |t(              r|j*                  rt-        j.                          t1        |	d	
      cY d }~S d }~ww xY ww)Nr   r   api_namer@  zcThis API endpoint does not accept direct HTTP POST requests. Please join the queue to use this API.)r+  r   )rw  rY  r   z/api/rO  ru  i  )rn   r   r   )r0   r<  r'   get_fnr   api_openqueuer   r   HTTP_404_NOT_FOUNDcompile_gr_requestr\  r9   r   r  BaseExceptionr   error_payload
show_error
isinstancer4   print_exception	traceback	print_excr   )r  r@  r   rY  rw  rv  r   r  r8  rn   r&  s             ro   predictzApp.create_app.<locals>.predict  sR     'L):LGLD##~~'(B >>#,,# A & 9 9  %77!	J $00(\xj9--I
*;;)'   M ! --eS^^5E5P5PQ!%/53H3H'')## # 	sI   C	E4C3 *C1+C3 /E41C3 3	E1<A*E,&E1'E4,E11E4z/call/{api_name}z/call/{api_name}/c                   K   t        di |j                         ddi}t        j                  j	                         | |      }|j
                  |_         |||       d {   S 7 w)Nsimple_formatTr  r   )r/   r<  r'   r  r   _idr  )r  r@  r   rY  	full_bodyrw  r&  queue_join_helpers         ro   simple_predict_postz+App.create_app.<locals>.simple_predict_post  sc      $Ldoo&7LtLI##~~'(B "$I*9gxHHHHs   A"A,%A*&A,z/queue/joinc                   K   | j                   t        t        j                  d       | ||       d {   S 7 w)NzSession hash not found.r*  )r  r   r   HTTP_400_BAD_REQUEST)r@  r   rY  r  s      ro   
queue_joinz"App.create_app.<locals>.queue_join  sE        (# & ; ;4  +4(CCCCs   5?=?c                  K   j                         }|j                  j                  |j                  j                         |j                  j                  rt        t        j                  d      t        di | j                         d|i} |j                  j                  | ||       d {   \  }}|s1d|v rt        j                  nt        j                  }t        ||      d|iS 7 >w)NzQueue is stopped.r*  r   )r@  r   rY  zQueue is full.r?  r   )r   r:  
server_appset_server_appstoppedr   r   HTTP_503_SERVICE_UNAVAILABLEr0   r<  pushr  )r@  r   rY  r   rR  r?  r   r&  s          ro   r  z)App.create_app.<locals>.queue_join_helper  s     
 ^^%F}}''/,,S1}}$$# & C C.  'L):LGLD&,mm&8&87X '9 ' !GX  (83 7744 
 $HMM))!s   B1C54C35?C5z/cancelc                  K   t        | j                   d| j                   h       d {    j                         }| j                  |j                  j
                  v }| j                  |j                  j                  j                  | j                  i       v }|rL|rJt        i d| j                        }|j                  j
                  | j                     j                  |       | j                  j                  v rej                  4 d {    j                  | j                  = j                  j                  | j                         d d d       d {    ddiS ddiS 7 B7 [7 # 1 d {  7  sw Y   ddiS xY ww)Nrm  T)r  rR  r?  rR  )rN   r  r  r   r:  pending_messages_per_sessionr?  r  r#  rJ   
put_nowaitr   r   r   add)r@  r   session_openevent_runningmessager&  s        ro   cancel_eventz$App.create_app.<locals>.cancel_event  sj    4#4#4"5Qt}}o FGHHH^^%F !!V]]%O%OO  ==::>>t?P?PRTUV  1tdmm ::%%*W%}}-88 > >dmm4**..t}}=> > t$$It$$+ I$> > > > > t$$sX   )FE.C(FE1F=E5F!E3"F1F3F5F
;E><F

Fz/call/{api_name}/{event_id}c                <   K   dd} | ||       d {   S 7 w)Nc                   | j                         }t        | t              r%| j                  rdnd}|d   j	                  d      }njt        | t
              r%| j                  rdnd}|d   j	                  d      }n5t        | t              rd}d }n t        | t              rd}| j                  }ny d| dt        j                  |       d	S )
Ncompleter8  r  r=  
generatingr  r9  r:  r;  )r<  r  rJ   rR  r#  rK   rI   rL   r  r?  ri   )r  rF  rA  r=  s       ro   process_msgz?App.create_app.<locals>.simple_predict_get.<locals>.process_msg  s    ((*g'>?*1//JwEx=,,V4D)AB,3OOLEx=,,V4D)9:'ED)?@#E"??D x

40@/AFFrq   )r  rH   rz   
str | Noner   )r   r?  r  queue_data_helpers      ro   simple_predict_getz*App.create_app.<locals>.simple_predict_get  s$     
G$ +7HkJJJJ   z/queue/datac                <   K   dd} | ||       d {   S 7 w)Nc                z    dt        j                  | j                         t              j	                  d       dS )Ndata: )rg   rw   r;  )rh   ri   r<  rl   rx   r  s    ro   r  z7App.create_app.<locals>.queue_data.<locals>.process_msg8  s3    W-?-?-A3 O V VW^ _``deerq   )r  rH   rz   rl   r   )r   r  r  r  s      ro   
queue_dataz"App.create_app.<locals>.queue_data3  s$     
f +7L+NNNNr  c                h   K   j                         dfd}t         ||       d      S w)Nc               d  K   	 t        j                         }	 | j                          d {   r%j                  j	                  
       d {    y 
j                  j
                  vrt        t        j                  d      d}d}d }	 j                  j
                  
   }|j                         }j                  j                  rt        dd      }|r 	|      }|| t!        |t"              r|j$                  rj                  j&                  
   j)                  |j$                         |j*                  t,        j.                  k(  sB|j*                  t,        j0                  k(  r?t3        j                  j&                  
         d	k(  rt5               } 	|      }|| y 7 7 i# t        $ rZ t        j                  |       d {  7   t        j                         |z
  |kD  rt               }t        j                         }Y ew xY w# t6        $ r}t        t9        |      
      } 	|      }t!        |t        j:                        r<j                  j
                  
= j                  j	                  
       d {  7   || |d }~ww xY ww)Nrq  zSession not found.r*  r6  r7  zServer stopped unexpectedly.F)r  rR  r   r  )r<  r=  r>  r:  clean_eventsr  r   r   r  
get_nowait
EmptyQueuer@  rA  rI   r  rL   r  rJ   r?  r  removerF  r    server_stoppedprocess_completedlenrF   r  rl   r{  )r   rD  rB  rC  r  messagesr  r  r   r  r  s           ro   
sse_streamz=App.create_app.<locals>.queue_data_helper.<locals>.sse_streamD  s{    L%)%6%6%8N!(!8!8!:::"(--"<"<,"<"WWW" )#)==#M#MN #0,2,E,E';# 
 *,%)
"&E'-}}'Q'Q ,(H '/&9&9&;G "==00&<(F(-'G #'27';H'3&. *74K L$+$4$4 & G G$0!""(&)9)9":#*;;-2N2N#N$+KK=3R3R$R(+,2MM,S,S0<-.)*
 ,-)- /A.BG/:7/CH'/';.6$* :W(  * E")--
";;;#002^CnT*:*< 261B1B1DET % 
4 #AG  +73H!!W%;%;<"MMFF|T$mm88l8SSS+&G
s   J0(H# F7#H# F:H# J09H# )F= :C:H# 4J05H# :H# =!H G!=H H# H  H# #	J-,A-J(JJ((J--J0rH  rI  rJ  )r   r   )r   r  r  r  r   r&  s    `` @ro   r  z)App.create_app.<locals>.queue_data_helper=  s6     
 ^^%FM^ %7#. s   ,2c                  K   | j                   j                  d      }t        |t              r^|j	                  d      rLg }i }| j                         4 d {   }|j                         D ]  \  }}t        |t              rt        |      dkD  ryt        |d   t              rft        |      D ]W  \  }}t        |t              r8|j                  }	|j                          d {   }
|j                  |	|
f       N||| d| <   Y t        |t              r8|j                  }	|j                          d {   }
|j                  |	|
f       |||<    d d d       d {    t        t        ||      |d   |d   |d	   
      S 	 | j!                          d {   }t#        |d   |d   |d   |d	   
      S 7 h7 7 7 b# 1 d {  7  sw Y   rxY w7 =# t$        $ r t'        t(        j*                  d      d w xY ww)Nr  zmultipart/form-datar   r   r  )r=  filesrX  r  fn_name)r=  rX  r  r  r=  zInvalid JSON body.r*  )r   r#  r  rl   r  formr  re  r  StarletteUploadFiler  r"  readappendr+   r-   r?  r,   r  r   r   r  )r   content_typer  r=  r  rT  r   r  vr"  contentss              ro   get_item_or_filez(App.create_app.<locals>.get_item_or_file  s     #??..~>L,,1H1H%2 "<<> . .T&*jjl .
U&ud3 #E
Q *585H I(1%(8 ;1#-a1D#E/0zzH56VVX~H$)LL(H1E$F9:DC5!$6; (/BC',~~H-2ZZ\'9H!LL(H)=>(-DI%.. .* /&D>!%n!5!%n!5 O	  !(/D2!&\%).%9%).%9 $Y	 =. 0> (:!. . . .: 0 !  '$*$?$?3    s   AH
GH
BG
%G
&AG
:G;G
H
%G&'H
G! !G"G!  H
G
G
H

GGGH
G! !&HH
z/component_serverz/component_server/c                  K    |        d {   }j                   |j                     }|j                  }||v r||   }nj                         j                  |   }t        ||j                  d       }|t        |dd      st        t        j                  d      t        j                  |      r ||j                         d {   S  ||j                        S 7 7 w)N_is_server_fnFzFunction not found.r*  )r   r  rX  r   r   r  r  r   r   r  inspectiscoroutinefunctionr=  )r   r@  staterX  blockrw  r&  r  s         ro   component_serverz(App.create_app.<locals>.component_server  s      *'22D$$T%6%67E,,Lu$l+(//=d3Bz_e!D# & 9 90  **2.		]**$))}$# 3 +s"   C&C"B;C&C$C&$C&z/queue/status)r3  response_modelc                 \   K    j                         j                  j                         S wrs   )r   r:  
get_statusr&  s   ro   get_queue_statusz(App.create_app.<locals>.get_queue_status  s%      >>#**5577s   ),z/upload_progressc                    K   d	 fd}	 t        j                  t        j                         d       d {    t         ||      d      S 7 # t         j                  t        f$ r t        dd      cY S w xY ww)
Nc                 K   t        j                         }d}	 | j                          d {   rt        j	                         y |rt        j	                         y d}d}	 t        j                        rddi}d}n/t        j                        }d|j                  |j                  d}d	t        j                  |       d
 7 # t        $ r Y y t        $ ro t        j                  |       d {  7   t        j                         |z
  |kD  r4ddi}d	t        j                  |       d
 t        j                         }Y w xY ww)NFTr6  r7  rF  r|  r  )rF  	orig_name
chunk_sizer  r;  r  )r<  r=  r>  file_upload_statusesstop_trackingis_doner  r"  r  r?  ri   r=   r<   r@  rA  )r   rD  r  rB  rC  r  r  	upload_ids          ro   r  z?App.create_app.<locals>.get_upload_progress.<locals>.sse_stream  sD    !%!2!2!4$44666,::9E,::9E%'N!%JA/77	B',foG&*G%9%=%=i%HF'/-3__.4.?.?'G
 !'tzz'':&;4@@+ 6* = ; A%mmJ777,,.?.P',k&:G$*4::g+>*?t"DD-1->->-@NAsM   +EC6E&A'C E	EE E;C><AEEEE   )r   zUpload not foundr  rN  rH  rI  rJ  )r@  wait_forr  
is_trackedTimeoutErrorr   r   )r  r   r  s   `  ro   get_upload_progressz+App.create_app.<locals>.get_upload_progress  s      ADN&&(33I>   %7#.  ((,7 N();MMNs7   A>-A AA A>A &A;8A>:A;;A>z/uploadc           	     *  K   | j                   j                  d      }t        |xs d      \  }}|dk7  rt        dd      	 |rt        j                  |       j                         j                  }||nt        j                  }t        | j                   | j                         dd||r|nd |rt        nd       }|j                          d {   }g }g }g }|j!                  d      D ]]  }t#        |t$              st'        d      |j(                  r5t+        |j(                        j,                  }t/        j0                  |      }ndt3        j4                  d       }t+        j6                        |j8                  j;                         z  }|j=                  dd       	 t?        j@                  tC        tE        |            tG        |            }|jJ                  jM                          	 tO        jP                  |jJ                  j,                  |       |jU                  |       jV                  jY                  |       ` |r|j[                  t\        ||       |S 7 # t        $ r3}	d	|	j                  v rd
nd}
t        |	j                  |
      cY d }	~	S d }	~	ww xY w# tH        $ r}t        dd|       |d }~ww xY w# tR        $ r9 |jU                  |jJ                  j,                         |jU                  |       Y w xY ww)Nr  r      multipart/form-datarX  Invalid content type.r*  i  )	max_files
max_fieldsmax_file_sizer  upload_progressmaximum allowed size  rN  r  z+File is not an instance of GradioUploadFiletmp   T)r  r  zInvalid file name: )/r   r#  r"   r   r  trackr   r  rJ  rK  r>   r   parser@   r  r   getlistr  r?   	TypeErrorr"  r   r  r#  !strip_invalid_filename_charactersr   	token_hexr   shar  r  r   r  r.   rl   r3   r5   r7  closer   renamer  r  upload_file_setr  r  rD   )r   bg_tasksr  content_type_headerr  rm  r  multipart_parserr  exccodeoutput_filesfiles_to_copy	locations	temp_filer  r  r   destr  r&  r   s                       ro   upload_filez#App.create_app.<locals>.upload_file#  s     #*//"5"5n"E23F3L"MOL!55#<STTH(..y9 # 0 > >1>1JPTPXPX#8OONN$"#"/+4i$<E$84$  .3355
 LM#%I!\\'2 1	!)-=>#$QRR%% $Y%7%7 8 = =I'II)TD !2!21!5 67D !6!67)--:Q:Q:SS	t< ??%c)n57G7MD $$&+IIinn1148 ##D)&&**40=1> !!0-  Y 6% H4Cs($GGH, ( '$'2EdV0L  +!(()<)<=$$T*+s   A LBI- I*I- CL*1J,L6*K A
L*I- -	J)6(J$J)L$J))L,	K5KKL?LLLLz/startup-eventsc                    K    j                   sL j                         j                           j                         j                          d {    d _         yy7 w)NTF)r   r   run_startup_eventsrun_extra_startup_eventsr  s   ro   startup_eventsz&App.create_app.<locals>.startup_eventsk  sP     // 335nn&??AAA/3, Bs   AAAAz
/theme.cssc                 N    t         j                         j                  d      S )Nztext/cssrI  )r   r   	theme_cssr  s   ro   r  z!App.create_app.<locals>.theme_csst  s     %S^^%5%?%?JWWrq   z/robots.txtc                 <     j                         j                  ryy)NzUser-agent: *
Disallow: /zUser-agent: *
Disallow: )r   r  r  s   ro   
robots_txtz"App.create_app.<locals>.robots_txty  s    ~~%%32rq   z	/pwa_iconz/pwa_icon/{size}c                  K   j                         }|j                  }|t        d      | t        |      S dd l}|j
                  j                  |      }|j                  | | f      }t        j                         }|j                  |d       |j                  d       t        t        j                  |j                               d      S w)Nr  rN  r   PNG)formatr^   rI  )r   r   r   r   	PIL.ImageImager  resizeioBytesIOsaveseekr   r  )sizer   r   PILimgimg_byte_arrayr&  s         ro   pwa_iconz App.create_app.<locals>.pwa_icon  s      ^^%F!..L##44|#L11))...C**dD\*CZZ\NHH^EH2"$

>..01k s   CCz/manifest.jsonc                    j                   st        d      j                  } t        | t              rt        |       } | 	dddddg}nY| j                  d      rj                  d      ddddg}n0j                  dd	
      ddddj                  dd
      ddddg}t        j                         j                  xs d|dddd      S )Nr  rN  zstatic/img/logo_nosize.svgr   zimage/svg+xml)srcsizesr  purposez.svgr&     )r"  192x192r^   i   512x512Gradioz./
standalone)r  icons	start_urldisplayzapplication/manifest+jsonrR  )pwar   r   r  r   rl   r   url_path_forrc   r   r  )r   r0  r&  r   s     ro   manifest_jsonz%App.create_app.<locals>.manifest_json  s   ::#44!..L,-"<0#  <!& /#(	 &&v.  #//
;!& /#(	  #//
/E!* +#(	  #//
/E!* +#(	 "  NN,22>h"!%+ 7	 	rq   /monitoringc                   K   j                   st        dd      t        j                  | t         dj
                        }| dj                   }t        d| d       t        d	      S w)
Nr  Monitoring is not enabled.r*  r6  rO  /monitoring/z* Monitoring URL: z *zSee console for monitoring URL.)	enable_monitoringr   r'   r\  r9   r   r   r  r   )r   root_urlmonitoring_urlr&  r   s      ro   analytics_loginz'App.create_app.<locals>.analytics_login  s     ++# #,H  #//(\5--H
 !)zc6G6G5HIN&~&6b9: ABBs   A.A1z/monitoring/{key}c                  K   j                   st        dd      t        | j                        rdj                   d}j                  sdddlm} ddlm} t        ||	       |j                  j                          j                         j                  j                  }||d
<   d_        t        |t        j                        S t        dd      w)Nr  r8  r*  r9  z
/dashboardr   )r=  )demo)r   r=  TrQ  zInvalid key.)r:  r   rB   r   r   gradio.monitoring_dashboardr=  r?  mount_gradio_appr:  r5  r   event_analyticsr%   r   r]  )rT  analytics_urlr=  	dashboard	analyticsr&  r   s        ro   analytics_dashboardz+App.create_app.<locals>.analytics_dashboard  s     ++# #,H  *#s/@/@A".s/@/@.A L--@M$S)-H$$**, # 0 7 7 G GI#,DL-1C*'%63H3H  $NKKs   CCz/process_recordingc           
     F  K   	 | j                   j                  d      }t        |xs d      \  }}|dk7  rt        dd      | j                  }t        |d      r|j                         j                  nd }||nt        j                  }t        | j                   | j                         dd	|
      }|j                          d {   }|j!                  d      }
|
rt#        |
d   t$              st        dd      |
d   }i }|j                  d      9|j                  d      (|j                  d      |d<   |j                  d      |d<   |j                  d      }|r"	 t'        j(                  t+        |            |d<   t/        j0                  ddt2              5 }|j4                  j7                  d       t9        j:                  |j4                  |       |j<                  d d d        t>        j@                  st9        jB                  d      tE        ddtG        fd            S t/        jH                  dt2              d   }	 tK        ||       d {   \  }tE        |ddtG        fd            S 7 # t        $ r3}d|j                  v rdnd}	t        |j                  |	      cY d }~S d }~ww xY w# t&        j,                  $ r	 g |d<   Y ]w xY w# 1 sw Y   xY w7 # tL        $ r tE        ddtG        fd            cY S w xY ww) Nr  r   r  rX  r  r*  r   r   
   )r  r  r  r  r  rN  videor   zNo video file providedremove_segment_startremove_segment_endzoom_effectsFz.mp4)deletesuffixdirffmpegr_   zgradio-screen-recording.mp4c                       g      S rs   r   cleanup_files
input_paths   ro   <lambda>z;App.create_app.<locals>.process_recording.<locals>.<lambda>3      mZL6Q rq   )r   r"  r   z_processed.mp4)rN  rO  c                             S rs   r   )rS  
temp_filess   ro   rU  z;App.create_app.<locals>.process_recording.<locals>.<lambda>C  s    mJ6O rq   c                       g      S rs   r   rR  s   ro   rU  z;App.create_app.<locals>.process_recording.<locals>.<lambda>J  rV  rq   )'r   r#  r"   r   r&  r  r   r  rJ  rK  r>   r   r  r@   r  r   r  r  r?   r?  r  rl   r  tempfileNamedTemporaryFileDEFAULT_TEMP_DIRr7  r!  shutilcopyfileobjr  r(   IS_WASMwhichr   r#   mkstemprE   r  )r   r  r  rm  r&  r  r  r  r  r	  video_files
video_fileparamszoom_effects_json
input_fileoutput_pathprocessed_pathrT  rX  rS  s                    @@ro   process_recordingz)App.create_app.<locals>.process_recording  s    H&-oo&9&9.&I#"67J7Pb"Qa#99'C@WXXkk sL1 NN$22 
 2?1JPTPXPX#8OONN$!"/$  .3355
 ,,w/KjQAQ&R#<TUU$QJF/0<HH12>15:P1Q-./3xx8L/M+, $ 8 0-1ZZ<M8N-OF>* ,,V1A -$$Q'"":??J?'__
- !!V\\(%;%C#*:-.QR	  #**'-=K3LV4 .*
 $"*:-.OP	 e 6% H4Cs($GGH, ++ 0-/F>*0- -(.  #*:-.QR	 s   L!CJ
 	J
J
 BL!&!K	 L!#AK(+A'L!K6 #K4$"K6 L!J
 
	K(K;K<L!KL!	K%!L!$K%%L!(K1-L!4K6 6%LL!LL!c           
         | D ]9  }	 |r4t         j                  j                  |      rt        j                  |       ; y # t        $ r$}t        d| dt        |              Y d }~ed }~ww xY w)NzError cleaning up file z: )r   r   r~  unlinkr  r  rl   )r  r7  r  s      ro   rS  z%App.create_app.<locals>.cleanup_filesM  sh     FFt 4		$F ! F3D6CF8DEEFs   6A  	A-	A((A-r   rJ  )r   rK  rz   Optional[str])r-  rl   )r   rK  rz   r   )r   rK  r`  r   )r   rK  r-  rl   )r   rl   rs   )rr  rl   r  zdict[str, Any]rt  r  )r   rK  r-  rl   rt  rl   rr  rl   )r  rl   )r   )r   rK  rr  rl   )
r}  rl   r  zLiteral['client', 'server']r  rl   r  rl   r  rK  )r   rl   )r1  rl   r   rK  )r?  rl   r@  r/   r   rK  )rF  r   r?  rl   )r?  rl   )r  rl   rW  r  rX  r  )
r  rl   rW  r  rX  r  r`  rl   ra  rl   )r   rl   r   rK  )r@  r1   )r  rl   r   rK  r  r   rY  rl   )r  rl   r@  r/   r   rK  rY  rl   )r  rl   r@  r2   r   rK  rY  rl   )r@  r/   r   rK  rY  rl   )r@  r*   )r   rK  r?  rl   )r   rK  r  rl   )r   rK  r  rl   r  z$Callable[[EventMessage], str | None])r   rK  rz   z7Union[ComponentServerJSONBody, ComponentServerBlobBody])r  rl   r   rK  )r   rK  r  r   r  rl  )r"  
int | None)rT  rl   )r   rc   delete_cacherC   r#  r   r   r9   r   r(   r_  add_middlewarer:   
middlewarer   r  r   expects_oauthr8   r  headr   rF  rG   r   include_router):r   
app_kwargsr   r	  ssr_modern  routerr  r.  r0  r2  rL  ra  rg  rm  rv  pagesetrt  rr  r  r  r  r  r	  r  rH  rj  rl  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r&  r5  r=  rF  ri  r   r&  rS  r7  r'  r  r  rs  r  r  r  s:   `                                              @@@@@@@@@@@ro   
create_appzApp.create_appR  s     %2
6G**:l!8NN:t,"
/;"

: L/LZLtL*-&!!!3M^^F#  (   $  D 
G		H		) 
 
	) 
N	#	O	$$+,<$= 	 
% 
$	 
H		I		C 
 
	C 
I		J		7 
  
	7 
M1E0F	G	$	 
H	@ 
(		)	MTY!	V$!	V1J!	V 
 
!	VT ::!cjj&>&> WWY=DEU=V     * 
&	'	 
(		< || 	"G1:DrzD!	" HL	/	/$2	/:D	/8 
#l	3	\	2   01	O	$O	O	 O	 	O	 
3 
4O	b 
(	)	 
*	( 
HGK,@+A	B	G7;+?*@	A	  
B 
C	  
O7;3G2H	I_	 
J_	B 
7;+?*@	A	'+*>)?	@	2 	2 
A 
B	2" 
&	'	- 
(	- 
M	N;	7;	74;	7 ;	7 	;	7
 !;	7 
O;	7z 
&	'	, 
(	, 
	 	9 
!	9 
-W[=Q<R	S	,GK<P;Q	R	 
S 
T	$ 
/w{?S>T	U	.gk>R=S	T>	 
U 
V>	@ 
)	*	& 
+	& 
		.	/	 
0	  
/	0	& 
1	& 
O	P	 
Q	0 
T	U	R	R$'	R7:	RHK	RRU	R 
V	R2 
O	P	6 
Q	62 
'w{7K6L	M	- 
N	- 
Y		X		% 
 
 	% 
/	0
 $$45	E	QE	Q$E	Q .E	Q 	E	Q 
1E	QP 
&gk6J5K	L	'w{7K6L	M	&gk6J5K	L	'w{7K6L	M
 $$45	+	+	+	 %+	 	+	 
N 
M 
N 
M+	Z 
'w{7K6L	M	(8L7M	N
 $$45		I	I#	I %	I 		I 
O 
N	I 
]'+2F1G	H $$45
	D
	D$
	D 
	D 
I
	D	*	*$	* 	*8 
Y		% 
 	%0 
1AU@V	W	K$	K	K 
X	K0 
M1E0F	G	O$	O	O 
H	OY	$Y	Y	 >Y	v3	 $3	 D3	 j 
!+./ 
 

 
 !+./ 
 

	%$	%	

	

	%, 
!+./, 
 


	8


	8 
&	'-	 
(-	^ 
Ygk.B-C	D (,E	 $E	 %E	  %E	  
EE	 N 
%	&	 
'	 
L1B	C	.?	@	X 
A 
D	X 
/@	A	3 
B	3 
		#	$	 
% 
	, 
!	"2	 
#2	h 
gk.B-C	D	C 
E	C 
$	%	L 
&	L, 
)9M8N	OW	$W	 
PW	r	F 	6"
rq   rs   )r   .Callable[[fastapi.Request], str | None] | None)r
  r   )r   rK  r   rl   r   r  r   r  r   rl   r   rl   rz   r   )r   gradio.Blocksrz   None)rz   rz  )NNTF)r   rz  rt  dict[str, Any] | Noner   ry  r	  boolru  r}  rz   r   )r|   r}   r~   __doc__r  r   r   AsyncClientr   r   r   r   r   r   r  rx  __classcell__)r   s   @ro   r   r      s
    H KO #G #J U F '
 '
'
 '
 	'

 '
 '
 
'
 '
R-"
"!
  -1JN CC)C HC 	C
 C 
C Crq   r   c                   |dk(  rt        j                  d      t        j                  |      rt        j                  d      	 t	        t        j                  | |            }|j                         rt        j                  d      |j                         st        j                  d      t        |      S # t        $ r}t        j                  d      |d}~ww xY w)zSafely join the user path to the directory while performing some additional http-related checks,
    e.g. ensuring that the full path exists on the local file system and is not a directory
    r   rX  r  Nr  )fastapir   r'   r%  r   r   r  r5   r'  r~  rl   )r   r   fullpathr  s       ro   rk  rk  ^  s     rz##C((''-##C((0	489 ##C((??##C((x=  0##C(a/0s   B: :	CCCc                B   g }g }| D ]  }t        j                  |      xs d}|j                  d      }|D ]<  }d|v s|j                  |j                  d      d   j                  d      d          > |j                  |d   j                  d      d           ||fS )	Nr   rQ  zvalue (r   )r   r   )r  getdocr,  r  )cls_setdocsettypesclsdoc	doc_lineslines          ro   	get_typesr  q  s    FE 3nnS!'RIIdO	 	EDD TZZ	215;;C@CD	E 	il((-b123 5=rq   T)r   r  r   r   r  r  r   r  r  ru  r  r   r:  r3  i18nc               |   ||dk7  rt        j                  d       d|_        |||_        t	        j
                  |      |_        |j                         |_        |j                          ||_
        ||_        ||_        ||_        |||_        |||_        ||	t!        d      |r:t#        |      s/t%        |d   t&              st%        |d   t(              s	|g|_        n||_        ||_        ||_        |xs g |_        |xs g |_        ||_        t%        |j0                  t(              st!        d      t%        |j2                  t(              st!        d      |
|
|_        t8        j:                  rdn*||n&t=        j>                  dd	      jA                         d
k(  |_!        |jB                  rt<        jD                  jG                  dt8        j:                  rdn	tI                     |_%        ||_&        ||_'        tQ        |jL                  |jN                  |jJ                        \  |_&        |_)        |_'        tT        jW                  |||	|jB                        | jX                  jZ                  t\        j^                  dfd       }|| jX                  _-        | ja                  |       | S )a  Mount a gradio.Blocks to an existing FastAPI application.

    Parameters:
        app: The parent FastAPI application.
        blocks: The blocks object we want to mount to the parent app.
        path: The path at which the gradio application will be mounted, e.g. "/gradio".
        server_name: The server name on which the Gradio app will be run.
        server_port: The port on which the Gradio app will be run.
        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"}`
        auth: If provided, username and password (or list of username-password tuples) required to access the gradio 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 for this gradio app.
        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 gradio app (they will see a 401 Unauthorized response). To be used with external authentication systems like OAuth. Cannot be used with `auth`.
        root_path: The subpath corresponding to the public deployment of this FastAPI 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 in its entirety. Normally, this does not need to provided (even if you are using a custom `path`). However, if you are serving the FastAPI app behind a proxy, the proxy may not provide the full path to the Gradio app in the request headers. In which case, you can provide the root path here.
        allowed_paths: List of complete filepaths or parent directories that this gradio app 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.
        blocked_paths: List of complete filepaths or parent directories that this gradio app 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.
        favicon_path: If a path to a file (.png, .gif, or .ico) is provided, it will be used as the favicon for this gradio app's page.
        show_error: If True, any errors in the gradio app will be displayed in an alert modal and printed in the browser console log. Otherwise, errors will only be visible in the terminal session running the Gradio app.
        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.
        show_api: If False, hides the "Use via API" button on the Gradio interface.
        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.
        node_server_name: The name of the Node server to use for SSR. If None, will use GRADIO_NODE_SERVER_NAME environment variable or search for a node binary in the system.
        i18n: If provided, the i18n instance to use for this gradio app.
        node_port: The port on which the Node server should run. If None, will use GRADIO_NODE_SERVER_PORT environment variable or find a free port.
    Example:
        from fastapi import FastAPI
        import gradio as gr
        app = FastAPI()
        @app.get("/")
        def read_main():
            return {"message": "This is your main app"}
        io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
        app = gr.mount_gradio_app(app, io, path="/gradio")
        # Then run `uvicorn run:app` from the terminal and navigate to http://localhost:8000/gradio.
    r  zThe 'favicon_path' parameter is set but will be ignored because 'path' is not '/'. Please add the favicon directly to your FastAPI app.Fz^You cannot provide both `auth` and `auth_dependency` in mount_gradio_app(). Please choose one.r   z.`allowed_paths` must be a list of directories.z.`blocked_paths` must be a list of directories.GRADIO_SSR_MODEFalsetrueGRADIO_NODE_PATHr   )r   server_port	node_path)rt  r   ru  c                 K    |       4 d {    j                   j                        4 d {    j                         j                          j                         j	                          d {    d  d d d       d {    d d d       d {    y 7 7 p7 .7 # 1 d {  7  sw Y   +xY w7 "# 1 d {  7  sw Y   y xY wwrs   )rv  lifespan_contextr   r  r  )r&  
gradio_appold_lifespans    ro   new_lifespanz&mount_gradio_app.<locals>.new_lifespan
  s     
 	 	 "((99*E  %%'::< ++-FFHHH 	 	 	H   	 	 	 	s   CB#C CB%CA B+8B'9	B+CB)CCC C%C'B+)C+B=	1B42B=	9C CCC	CC)r&  r   )1warningswarndev_moder  r   _parse_file_sizer  get_config_filer  validate_queue_settingsr   r  r   r:  r3  r  r   r   r  tuplere  r   r  r   r  r  r  r   r(   r_  r   r   lowerru  environr#  rO   r  r  r   r7   r  r   rx  rv  r  
contextlibasynccontextmanagermount)r&  r   r   r   r  r  rt  r   r  r   r   r  r  r   r  r  ru  r  r   r:  r3  r  r  r  r  s                          @@ro   rA  rA  ~  s   x DCKC	

 FO" 11-@F**,FM
""$#F$F$F0F

#O7l
 	
 	47E*47D)f&F&F(.BF(.BF"Ff**D1IJJf**D1IJJ$  	 # ,g6<<>&H O ::>>j&8&8mo
 #3$"33",, ** 	G!4f6F '	   J ::..L## $ #/CJJIIdJJrq   )z	theme.cssz
robots.txtr&  zmanifest.jsonra  rg  ri  r  staticassetszfavicon.ico
gradio_api
monitoring)r   r.   r   r3   rz   rl   )r  z
list[type])r  i  NN).r&  fastapi.FastAPIr   rz  r   rl   r   rl   r  r  r  bool | Nonert  r|  r   z9Callable | tuple[str, str] | list[tuple[str, str]] | Noner  r  r   ry  r   r  r  list[str] | Noner  r  r   r  r  r}  r  zstr | int | Noneru  r  r  r  r   rm  r:  r  r3  r  r  zI18n | Nonerz   r  )r~  
__future__r   r@  r  r  importlib.resources	importlibr  r  r?  rJ  r  r   r   r  r<  r  r  collections.abcr   r   pathlibr   r  r   r  typingr   r	   r
   r   r   r   r  r   r   rh   r   r   r   r   r   r   fastapi.responsesr   r   r   r   r   r   fastapi.securityr   fastapi.templatingr   fastapi.websocketsr   r   gradio_clientr   r#  gradio_client.documentationr   gradio_client.utilsr    jinja2.exceptionsr!   python_multipart.multipartr"   starlette.backgroundr#   starlette.datastructuresr$   r  starlette.responsesr%   rS   r&   r'   r(   gradio.contextr)   r(  r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   gradio.exceptionsr4   r5   gradio.i18nr6   gradio.node_serverr7   gradio.oauthr8   gradio.route_utilsr9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   gradio.screen_recording_utilsrE   gradio.server_messagesrF   rG   rH   rI   rJ   rK   rL   gradio.state_holderrM   gradio.utilsrN   rO   rP   rQ   gradio.blocksrR   r]  rZ  init	resourcesr  joinpathas_posixSTATIC_TEMPLATE_LIBr  rj  r  r  r  r#  rl   
gettempdirr\  rc   r   rT   envfiltersr  LimitsTimeoutr   r  r   rk  r  rA  r  r   rq   ro   <module>r     s  U #      	    	  
    3  %        7 . = / 0 - . ; / F 0  B B "   6  &    D   ,  #   	 h'00=FFH  h'X)*XZ	 h'X)*XZ	 
  ::>>"34 				(*9 
?\ ?& &9:	$,	  j !			5<<"$ EMM$
 *+ H' H`4&
 

 ! (,X GK#FJ &*&*#&* #' %)/X	XX X 	X
 X X &X DX X DX X $X $X X  !X" $#X$ %X& !'X( )X* #+X, 
-X. /X0 1X Xvrq   