
    l0jj                       d Z ddlmZ ddlZddlZej        dk    rddlmZ n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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 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'm(Z( ddl)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z<m=Z= ddl>m?Z? ddl@Z@ddlAmBZB ddl@mCZCmDZDmEZE ddlFmGZG ddlHmIZImJZJ ddlKmLZL ddlMmNZN ddlOmPZP ddlQmRZRmSZS ddlTmUZU ddlVmWZWmXZXmYZY  e
jZ                      ed          [                    d          \                                Z] ed          [                    ddd           \                                Z^ ed          [                    ddd!          \                                Z_ ed          [                    d"          `                                Za G d# d$e.          Zbd% Zc e3e]&          Zdecedje        jf        d'<    ejg                    Zh G d( d)e#          Zid<d.Zjd=d1Zk e6d2            e5            	 	 d>d?d;            ZldS )@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)   	   )files)TimeoutError)defaultdict)Path)AnyDictListOptionalType)DependsFastAPIFileHTTPException
UploadFile	WebSocketstatus)CORSMiddleware)FileResponseHTMLResponseJSONResponsePlainTextResponse)OAuth2PasswordRequestForm)Jinja2Templates)documentset_documentation_group)TemplateNotFound)BackgroundTask)RedirectResponseStreamingResponse)WebSocketState)route_utilsutils
wasm_utils)Context)PredictBody	ResetBody)warn_deprecation)Error)attach_oauth)
EstimationEvent)Request)cancel_tasksrun_coro_in_backgroundset_task_namegradio	templatesfrontendstaticassetszversion.txtc                  J    e Zd ZdZedd            ZddZedd	            Zd
S )ORJSONResponsezapplication/jsoncontentr
   returnbytesc                h    t          j        | t           j        t           j        z  t                    S )N)optiondefault)orjsondumpsOPT_SERIALIZE_NUMPYOPT_PASSTHROUGH_DATETIMEstrr:   s    P/home/wildlama/miniconda3/envs/lam/lib/python3.11/site-packages/gradio/routes.py_renderzORJSONResponse._renderF   s/    |-0OO
 
 
 	
    c                6    t                               |          S N)r9   rG   )selfr:   s     rF   renderzORJSONResponse.renderN   s    %%g...rH   rD   c                \    t                               |                               d          S )Nzutf-8)r9   rG   decoderE   s    rF   _render_strzORJSONResponse._render_strQ   s$    %%g..55g>>>rH   N)r:   r
   r;   r<   )r:   r
   r;   rD   )__name__
__module____qualname__
media_typestaticmethodrG   rL   rO    rH   rF   r9   r9   C   sk        #J
 
 
 \
/ / / / ? ? ? \? ? ?rH   r9   c                    t          j        t                              |                               dd                              dd                              dd                              dd                    S )	N<z\u003c>z\u003e&z\u0026'z\u0027)
markupsafeMarkupr9   rO   replace)values    rF   toorjsonr_   V   sd    ""5))	i	 	 	i	 	 	i	 	 	i	 	   rH   )	directoryr_   c                  T     e Zd ZdZ fdZddZddZd	 Ze	 ddd            Z	 xZ
S )Appz
    FastAPI App Wrapper
    c                T   i | _         d | _        d | _        i | _        t	          t
                    | _        t	          t                    | _        t          j
                    | _        t          j        d          | _        d| _        t           j                            d          p/t'          t)          t+          j                              dz            | _        d | _        |                    dd            |                    dd             t5                      j        di | d S )N    FGRADIO_TEMP_DIRr3   docs_url	redoc_urlrU   )tokensauthblocksstate_holderr   dict	iteratorssetiterators_to_resetr%   safe_get_locklocksecretstoken_urlsafequeue_tokenstartup_events_triggeredosenvirongetrD   r	   tempfile
gettempdiruploaded_file_dirchange_event
setdefaultsuper__init__)rK   kwargs	__class__s     rF   r   zApp.__init__k   s   	,0$T**"-c"2"2'))	"044(-%!#0A!B!B "
c$&&''(2G
 G
 59 	*d++++t,,,""6"""""rH   rj   gradio.Blocksr;   Nonec                    |j         }|)t          |          sd |D             | _         n|| _         nd | _         || _        t          j                    | _        |j        | _        i | _        |j        | _        d S )Nc                ,    i | ]}|d          |d         S )r      rU   ).0accounts     rF   
<dictcomp>z%App.configure_app.<locals>.<dictcomp>   s"    HHHWQZHHHrH   )	ri   callablerj   rv   getcwdcwdfavicon_pathrh   	root_path)rK   rj   ri   s      rF   configure_appzApp.configure_app   sx    {D>> !HH4HHH		 		DI9;;"/)rH   c                <    | j         t          d          | j         S )Nz+No Blocks has been configured for this app.)rj   
ValueError)rK   s    rF   
get_blockszApp.get_blocks   s!    ;JKKK{rH   c                `   t          j        |          | j        sJ t          fd| j        j        D                       }|st          d          j                            d          }i }t          j	        |rdt          j	         |d<   t                              d|          }|S )Nc              3  \   K   | ]&}j         t          j        |          j         k    V  'd S rJ   )hosthttpxURL)r   rooturls     rF   	<genexpr>z*App.build_proxy_request.<locals>.<genexpr>   sF       
 
15CH	$,,
 
 
 
 
 
rH   zThis URL cannot be proxied.z	.hf.spacezBearer AuthorizationGETheaders)r   r   rj   any	root_urlsPermissionErrorr   endswithr'   hf_tokenclientbuild_request)rK   url_pathis_safe_url	is_hf_urlr   rp_reqr   s         @rF   build_proxy_requestzApp.build_proxy_request   s    i!!{{  
 
 
 
9=9N
 
 
 
 
  	A!"?@@@H%%k22	'I''C1A'C'CGO$%%eS'%BBrH   N
app_kwargsDict[str, Any] | Nonec           	        |pi }t           j        s|                    dt                     t	          ddi |                    |            t           j        s!                    t          dgdgdg                               d                              d          defd
                        }                    d                              d          t          |          fdffd                        }dgd}                    d                              d          dhfd                        }                    d                              d          dhfd                        }diddifd
                    d          difd            }                    d                              d          t                      fdjfd"                        }j        j        j        rt                                         d#t           $                              d#t           $          t          |          fdkfd%                        }	                    d&t          |          g'                              d(t          |          g'          dldmfd,                        }
                    d-t          |          g'                              d.t          |          g'          dnfd/                        }                    d0          dod2                                d3          dod4            }                    d5          fd6            }                    d7t          |          g'                              d7t          |          g'          dpfd9                        }                    d:t          |          g'                              d:t          |          g'          dqfd<                                            d=t          |          g'          drfdB            }                    dCt          |          g'          dsfdD            }                    dE                              dF          dtfdI                        }                    dJt          |          g'                              dKt          |          g'                              dLt          |          g'                              dMt          |          g'          t          |          fdufdQ                                                }
                    dR          t          |          fdvfdT            }                    dUt          |          gt"          V          fdW            }                    dXt          |          g'          t%          dY          fdwfd\            }                    d]                              d^          fd_                        }                    d`t(          $          fda            }                    dbt(          $          fdc            }S )xNdefault_response_class*)allow_originsallow_methodsallow_headersz/userz/user/requestfastapi.Requestr;   Optional[str]c                    | j                             d          p| j                             d          }j                            |          S Naccess-tokenaccess-token-unsecurecookiesrx   rh   r   tokenapps     rF   get_current_userz(App.create_app.<locals>.get_current_user   sL     O''77 7?;N;N'< <E :>>%(((rH   z/login_checkz/login_check/userrD   c                P    j         | d S t          t          j        d          )NzNot authenticatedstatus_codedetail)ri   r   r   HTTP_401_UNAUTHORIZED)r   r   s    rF   login_checkz#App.create_app.<locals>.login_check   s7     x4#3"8AT   rH   	websocketr   c                r   K   | j                             d          p| j                             d          }|S r   )r   rx   )r   r   s     rF   ws_login_checkz&App.create_app.<locals>.ws_login_check   s@      %)).99 Y=N=R=R'> >E LrH   z/tokenz/token/rl   c                r    | j                             d          }|j                            |          dS )Nr   )r   r   r   r   s     rF   	get_tokenz!App.create_app.<locals>.get_token   s6     O''77E"CJNN5,A,ABBBrH   z/app_idz/app_id/c                :    d                                 j        iS )Napp_id)r   r   )r   r   s    rF   r   zApp.create_app.<locals>.app_id   s     cnn..566rH   c                t   K   	 |                      d           d {V  t          j        d           d {V  6)NTPINGr   )	send_textasynciosleep)r   s    rF   send_ping_periodicallyz.App.create_app.<locals>.send_ping_periodically   sX      '))&111111111mA&&&&&&&&&'rH   c                   K   j         sJ 	 j                                         r4|                     d           d {V  j                                          t	          j        d           d {V  h)NTCHANGEg?)r|   is_setr   clearr   r   )r   r   s    rF   listen_for_changesz*App.create_app.<locals>.listen_for_changes   s      ####)#**,, -#--h777777777$**,,,mC(((((((((	)rH   z/dev/reloadc                  K   |                                   d {V  t          j         |                     }t          j         |                     }||h}|                    |j                   |                    |j                   t          j        ||gt          j                   d {V \  }}|D ]}|                                 t          d |D                       r| 	                                 d {V  d S d S )N)return_whenc              3  d   K   | ]+}t          |                                t                    V  ,d S rJ   )
isinstance	exception	Exception)r   tasks     rF   r   z9App.create_app.<locals>.notify_changes.<locals>.<genexpr>   s6      LLt:dnn..	::LLLLLLrH   )
acceptr   create_taskadd_done_callbackremovewaitFIRST_COMPLETEDcancelr   close)	r   pingnotifytasksdonependingr   r   r   s	          rF   notify_changesz&App.create_app.<locals>.notify_changes   sN     ""$$$$$$$$$&'='=i'H'HIID(););I)F)FGGF6NE""5<000$$U\222"),v#3# # #      MD'
    LLtLLLLL (oo'''''''''''( (rH   z/loginz/login/	form_datar   c                ,   | j                                         | j        }}j        t	          dt
          j                  S t          j                  s|j        v rj        |         |k    s/t          j                  rj                            ||          rdt          j
        d          }|j        |<   t          ddi          }|                    d|ddd	           |                    d
|d           |S t          dd          )N/r   r      successTrE   r   none)keyr^   httponlysamesitesecurer   )r   r^   r     zIncorrect credentials.r   )usernamestrippasswordri   r!   r   HTTP_302_FOUNDr   __call__rr   rs   rh   r   
set_cookier   )r   r   r   r   responser   s        rF   loginzApp.create_app.<locals>.login   s:    "+!3!9!9!;!;Y=OhHx'CV=RSSSSSX&&V((HX&(2238$$ 3),):):8X)N)N 3-b11$,
5!'D0ABBB##&!# $    ##/ut $     #<TUUUUrH   r   )response_classc                   t          j        dd                                           }| j                            dd          }j        |                                j        }||d<   n#d|j                                        j        |d}	 |j	        rdnd	}t                              || |d
          S # t          $ r,}|j	        rt          d          |t          d          |d }~ww xY w)Nzapplication/javascriptz.jsr    r   T)auth_requiredauth_messagespace_idr   zfrontend/share.htmlzfrontend/index.html)r   configzqDid 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   scoperx   ri   r  r  r  sharer4   TemplateResponser   r   )r   r   rj   r   r  templateerrr   s          rF   mainzApp.create_app.<locals>.main#  s=    7???^^%%F))+r::Ix4#3))0!*v &*$*$7 # 0 0 9%	 -3\T))?T  !11 '6::   $ 
 
 
< 	$R  
 %M  
s   (B; ;
C1'C,,C1z/info/)dependenciesz/infoT	serializeboolc                v                                     j        }t          j                            ||           S rJ   )r   r  r3   rj   get_api_info)r  r  r   s     rF   api_infoz App.create_app.<locals>.api_infoI  s/     ^^%%,F=--fi@@@rH   z/config/z/configc                z    | j                             dd          }                                j        }||d<   |S )Nr   r  r   )r  rx   r   r  )r   r   r  r   s      rF   
get_configz"App.create_app.<locals>.get_configO  s<      ))+r::I^^%%,F&F6NMrH   z/static/{path:path}pathc                J    t          t          |           }t          |          S rJ   )	safe_joinSTATIC_PATH_LIBr   )r  static_files     rF   static_resourcez'App.create_app.<locals>.static_resourceW  s    #OT::K,,,rH   z/assets/{path:path}c                J    t          t          |           }t          |          S rJ   )r  BUILD_PATH_LIBr   )r  
build_files     rF   build_resourcez&App.create_app.<locals>.build_resource\  s    ">488J
+++rH   z/favicon.icoc                 |   K                                    } | j         d          S t          | j                  S )Nzimg/logo.svg)r   r   r   )rj   r   r  s    rF   faviconzApp.create_app.<locals>.favicona  s@      ^^%%F"*&~666#F$7888rH   z/proxy={url_path:path}r   c                ^  K   	                      |           }n1# t          $ r$}t          dt          |                    |d }~ww xY wt                              |d           d {V }t          |                                |j        |j	        t          |j                            S )Nr   r   T)stream)r   r   
background)r   r   r   rD   r   sendr"   	aiter_rawr   r   r    aclose)r   r   r  rp_respr   s       rF   reverse_proxyz%App.create_app.<locals>.reverse_proxyi  s      O00::" O O O#CHHEEE3NO"KKtK<<<<<<<<G$!!###/)'.99	   s    
A	AA	z/file={path_or_url:path}path_or_urlc                8  K                                    }t          j        |           rt          | t          j                  S t          j        |           t          fd|j        D                       }t          d j	        D                       }
                                }|s|s|rt          dd|  d          t          j        j                  }t                     t                      j        |j         v }t          fd|j        D                       }t          j        j                  }	|s|s|s|	st          dd|  d                                          st          dd	|  d          |j                            d
d                                          }
|
                    d          rd|
v r|
dd          }
|
                    d          \  }}|                                r|                                rot7          |          }t7          |          }t9          j        t9          j        ||          t?          |j                  tA          j!                            }|S tE          ddi          S )Nr   c              3  B   K   | ]}t          j        |          V  d S rJ   r%   is_in_or_equal)r   blocked_pathabs_paths     rF   r   z/App.create_app.<locals>.file.<locals>.<genexpr>  D          $X|<<     rH   c              3  @   K   | ]}|                     d           V  dS ).N)
startswith)r   parts     rF   r   z/App.create_app.<locals>.file.<locals>.<genexpr>  s.      MMdT__S11MMMMMMrH     zFile not allowed: r6  c              3  B   K   | ]}t          j        |          V  d S rJ   r0  )r   allowed_pathr3  s     rF   r   z/App.create_app.<locals>.file.<locals>.<genexpr>  r4  rH     zFile not found: Ranger  zbytes=-   )stat_resultzAccept-Rangesr<   r   )#r   r%   validate_urlr!   r   r   abspathr   blocked_pathspartsis_dirr   r1  r   rD   rn   uniontemp_file_setsallowed_pathsr{   existsr   rx   r   r7  split	isnumericintranged_responseRangedFileResponse	OpenRangerl   rv   statr   )r-  r   rj   in_blocklist
is_dotfilerE  
in_app_dircreated_by_appin_allowlistwas_uploaded	range_valstartendr   r3  r   s                 @rF   filezApp.create_app.<locals>.filey  s      ^^%%F!+.. '#1F    }[11H    $*$8    L MMhnMMMMMJ__&&F Nz NV N#C)Lk)L)L)LMMM-h@@J ]]kceek6;P.QQN    $*$8    L !/#:OPPL N. NL NL N#C)Lk)L)L)LMMM??$$ L#C)JK)J)J)JKKK++GR88>>@@I##H-- $#2B2B%abbM	&__S11
s??$$ 	$ 	$JJEc((C.A '1%==W_--$&GH$5$5	     H $O?G2LMMMMrH   z+/stream/{session_hash}/{run}/{component_id}session_hashrunrL  component_idc                   K                                    j        |                              |i                               |d           t          dd          fd}t	           |                      S )Nr<  zStream not found.c               3     K   d} d}d}	 t                    dk    r"||k    rd S || z  }t          j        |            6d}                    d          }|d S |V  U)Ng{Gz?x   r   )lentimer   pop)check_stream_ratemax_wait_time	wait_timenext_streamr&  s       rF   stream_wrapperz6App.create_app.<locals>.stream.<locals>.stream_wrapper  s      $(! #	&6{{a''$}44"F!%66	
#4555  !I"(**Q--K"*%%%%&rH   )r   pending_streamsrx   r   r"   )r[  r\  r]  r   rh  r&  r   s        @rF   r&  zApp.create_app.<locals>.stream  s          /S"\4((	  ~#C)<===& & & & &" %^^%5%5666rH   z/file/{path:path}c                ,   K    | |           d {V S rJ   rU   )r  r   rZ  s     rF   file_deprecatedz'App.create_app.<locals>.file_deprecated  s+      dG,,,,,,,,,rH   z/reset/z/resetbodyr)   c                  K   | j         j        vrddiS j        4 d {V  d j        | j                  | j        <   j        | j                                      | j                   d d d           d {V  n# 1 d {V swxY w Y   ddiS )Nr   FT)r[  rm   rq   fn_indexro   add)rl  r   s    rF   reset_iteratorz&App.create_app.<locals>.reset_iterator  sB       55!5))x M M M M M M M MBFd/0?&t'89==dmLLLM M M M M M M M M M M M M M M M M M M M M M M M M M M t$$s   AA::
BBz/run/{api_name}z/run/{api_name}/z/api/{api_name}z/api/{api_name}/api_namer(   r   c                X  K   t          j        	| |          }	                                j        sA	                                                    |          rt          t          j                  t          j        	||||          }	 t          j	        	|||           d {V }n|# t          $ ro}	                                j        pt          |t                    }t          j                     t!          d|rt#          |          nd id          cY d }~S d }~ww xY w|S )N)r   rq  rl  )r   )fn_index_inferredr   r   )r   rl  
gr_requestrs  errori  )r:   r   )r$   infer_fn_indexr   api_openqueue_enabled_for_fnr   r   HTTP_404_NOT_FOUNDcompile_gr_requestcall_process_apiBaseException
show_errorr   r+   	traceback	print_excr   rD   )
rq  rl  r   r   rs  rt  outputru  r}  r   s
            rF   predictzApp.create_app.<locals>.predict  s      !, :(! ! ! >>##, 1A1A1V1V!2 2  $ & 9    %7"3!  J*;)&7	            !    ^^--8TJue<T<T
#%%%#$J&Hc%jjjDI #         Ms   B. .
D'8A$D"D'"D'z/queue/joinr   c                  K                                    }j        *|(|                     t          j                   d {V  d S |j        j        |j                                       |                                  d {V  	 t          j
        |                     ddi          d           d {V  n# t          $ r Y d S w xY w	 t          j
        |                                 d           d {V }n# t          $ r Y d S w xY wt          | |d         |d                   }j                            |          |_        |d         |_        |j        |j                                     dd	          rt+          |j         d
|j         h           d {V  |j                            |j        |j                   d {V  |j        j                            |           t3          |j        j        |gd          }t7          ||j        |j        d           n|j                            |          }|?|j                            |ddi           d {V  |                                 d {V  d S |j                                        }|j                             |||           d {V  	 t          j!        d           d {V  | j"        tF          j$        k    rd S 2)N)codemsg	send_hash   )timeoutr[  rn  everyr   _F)batch
queue_fullTr   )%r   ri   r   r   WS_1008_POLICY_VIOLATION_queue
server_appset_server_appr   r   wait_for	send_jsonAsyncTimeOutErrorreceive_jsonr.   rh   rx   r   r[  r  rn  r0   reset_iteratorscontinuous_tasksappendr1   process_eventsr2   pushsend_message
disconnectget_estimationsend_estimationr   application_stater#   DISCONNECTED)	r   r   rj   session_infoeventr   rank
estimationr   s	           rF   
join_queuez"App.create_app.<locals>.join_queue  s     
 ^^%%Fx#oo6+JoKKKKKKKKK}'/,,S111""$$$$$$$$$&''(<==q           %   %,%5**,,a& & &             %    <7j9Q E !Z^^E22EN!-n!=E "5>266wBB M"u'9$L$LEN$L$L#MNNNNNNNNNm33E4FWWWWWWWWW.55e<<<-M05'5  dE$6eTTTTT}))%00< -44UUL<QRRRRRRRRR**,,,,,,,,,F#]99;;
m33E:tLLLLLLLLLmA&&&&&&&&&..2MMMFs$   
1B< <
C
	C
.C= =
D
Dz/queue/status)r  response_modelc                 ^   K                                     j                                        S rJ   )r   r  r  r   s   rF   get_queue_statusz(App.create_app.<locals>.get_queue_statusF  s(       >>##*99;;;rH   z/upload.r   List[UploadFile]c                   K   g }t          j                    }| D ]6}|                    |                    |j                   d {V            7|S rJ   )r3   r   r  save_uploaded_filer{   )r   output_filesfile_manager
input_filer   s       rF   upload_filez#App.create_app.<locals>.upload_fileN  s       L!;==L#  
##&99"C$9          
  rH   startupz/startup-eventsc                 x   K    j         s/                                                                  d _         dS dS )NTF)ru   r   startup_eventsr  s   rF   r  z&App.create_app.<locals>.startup_events\  sB       /   //111/3,t5rH   z
/theme.cssc                 T    t                                           j        d          S )Nztext/css)rS   )r   r   	theme_cssr  s   rF   r  z!App.create_app.<locals>.theme_csse  s#    $S^^%5%5%?JWWWWrH   z/robots.txtc                 >                                      j        rdS dS )NzUser-agent: *
Disallow: /zUser-agent: *
Disallow: )r   r  r  s   rF   
robots_txtz"App.create_app.<locals>.robots_txti  s$    ~~% 33322rH   rU   )r   r   r;   r   )r   rD   )r   r   r;   r   )r   r   r;   rl   )r   r   )r   r   )r   r   r   rD   )T)r  r  )r   r   )r  rD   )r   rD   )r-  rD   r   r   )r[  rD   r\  rL  r]  rL  r   r   )r  rD   r   r   )rl  r)   )rq  rD   rl  r(   r   r   r   rD   )r   r   r   r   )r   r  )r&   IS_WASMr}   r9   rb   r   add_middlewarer   rx   r   r   postrj   expects_oauthr,   headr   r-   r   on_eventr   )rj   r   r   r   r   r   r   r   r  r  r  r  r"  r$  r,  r&  rk  rp  r  r  r  r  r  r  r  r   rZ  r   r   r  s                            @@@@@rF   
create_appzApp.create_app   s$	     %2
! 	L!!":NKKKJ&!!!! 	"e"e"e	     
						) 	) 	) 	) 	) 
	 
		) 
	 	 		!	!$+,<$=$= 	 	 	 	 	 	 
"	! 
!	 		 	 	 	 
						C 	C 	C 	C 	C 
	 
		C 
						7 	7 	7 	7 	7 
	 
		7	' 	' 	' 	'
	) 	) 	) 	) 	) 	) 
}	%	%	( 	( 	( 	( 	( 	( 
&	%	(& 
(			)		9@ 	V 	V 	V 	V 	V 	V 
	 
		V@ :!cj&>! 
#l	3	3	\	2	27>?O7P7P "	 "	 "	 "	 "	 "	 
3	2 
4	3"	H 
)=)=(>	?	?	(<(<'=	>	>	A 	A 	A 	A 	A 	A 
?	> 
@	?	A 
7;+?+?*@	A	A	'+*>*>)?	@	@	 	 	 	 	 
A	@ 
B	A	 
&	'	'	- 	- 	- 
(	'	- 
&	'	'	, 	, 	, 
(	'	, 
	 	 	9 	9 	9 	9 	9 
!	 	9 
*'+:N:N9O	P	P	)9M9M8N	O	O	 	 	 	 	 
P	O 
Q	P	 
,GK<P<P;Q	R	R	+7;;O;O:P	Q	Q/	N /	N /	N /	N /	N 
R	Q 
S	R/	Nb 
9!+../ 
 

 

	7 	7 	7 	7 	7	

 

	7> 
$GK4H4H3I	J	J	- 	- 	- 	- 	- 
K	J	- 
)			(			% 	% 	% 	% 	% 
	 
		% 
#7;3G3G2H	I	I	$GK4H4H3I	J	J	#7;3G3G2H	I	I	$GK4H4H3I	J	J
 $$455	'	 '	 '	 '	 '	 '	 
K	J 
J	I 
K	J 
J	I'	R 
}	%	% $+>#:#:8	 8	 8	 8	 8	 8	 
&	%8	t 
!+../% 
 

 


	< 	< 	< 	<

 


	< 
)7;+?+?*@	A	A&*3ii	  	  	  	  	  	  
B	A	  
i	 	 	"	#	#	 	 	 	 
$	# 
!	 	 
.?	@	@	X 	X 	X 	X 
A	@	X 
/@	A	A	3 	3 	3 	3 
B	A	3 
rH   )rj   r   r;   r   )r;   r   rJ   )rj   r   r   r   r;   rb   )rP   rQ   rR   __doc__r   r   r   r   rT   r  __classcell__)r   s   @rF   rb   rb   f   s         # # # # #(* * * *    
  " CGJ J J J \J J J J JrH   rb   r`   rD   r  r;   c                V   d t           j        j        t           j        j        fD             }|dk    rt	          d          t          j        |          t           j                            |           }t          fd|D                       sYt           j        	                              s:dk    s4
                    d          st           j                            |          rt	          d          t           j                            |          st	          dd	          |S )
ztSafely path to a base directory to avoid escaping the base directory.
    Borrowed from: werkzeug.security.safe_joinc                "    g | ]}||dk    
|S )Nr   rU   )r   seps     rF   
<listcomp>zsafe_join.<locals>.<listcomp>{  s)       CSVJJJJJrH   r  r   c              3      K   | ]}|v V  	d S rJ   rU   )r   r  filenames     rF   r   zsafe_join.<locals>.<genexpr>  s'      44C8O444444rH   z..z../r9  r<  zFile not found)rv   r  r  altsepr   	posixpathnormpathjoinr   isabsr7  isdirrI  )r`   r  _os_alt_sepsfullpathr  s       @rF   r  r  x  s    RW^4  L rzzC   !$''Hw||Ix00H4444|44444!7==""! tu%% 7==""  C   7>>(## 3C!1222OrH   cls_set
List[Type]c                z   g }g }| D ]}t          j        |          pd}|                    d          }|D ]M}d|v rG|                    |                    d          d                             d          d                    N|                    |d                             d          d                    ||fS )	Nr  
zvalue (r   )r   :)inspectgetdocrJ  r  )r  docsettypesclsdoc	doc_lineslines          rF   	get_typesr    s    FE 3 3nS!!'RIIdOO	 	E 	EDD  TZZ	2215;;C@@CDDDil((--b122225=rH   routesr   fastapi.FastAPIrj   r   gradio_api_url
str | Noner   dict[str, Any] | Nonec                6   d|_         |                                |_        |                                 t                              ||          |t          d           |                     d          fd            }|                     |           | 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.
        gradio_api_url: Deprecated and has no effect.
        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"}`
    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.
    F)r   Nz0gradio_api_url is deprecated and has not effect.r  c                    K                                     j        r(                                                                   d S d S rJ   )r   enable_queuer  )
gradio_apps   rF   start_queuez%mount_gradio_app.<locals>.start_queue  sL        ""/ 	5!!##2244444	5 	5rH   )	dev_modeget_config_filer  validate_queue_settingsrb   r  r*   r  mount)r   rj   r  r  r   r  r  s         @rF   mount_gradio_appr    s    6 FO**,,FM
""$$$:>>J!KLLL\\)5 5 5 5 5 IIdJJrH   )r`   rD   r  rD   r;   rD   )r  r  )NN)r   r  rj   r   r  rD   r  r  r   r  r;   r  )mr  
__future__r   r   sysversion_infoimportlib.resourcesr   importlib_resourcesr  r	  rv   r  rr   ry   	threadingrb  r~  r   r  collectionsr   pathlibr	   typingr
   r   r   r   r   fastapir   r[   r@   r   r   r   r   r   r   r   fastapi.middleware.corsr   fastapi.responsesr   r   r   r   fastapi.securityr   fastapi.templatingr   gradio_client.documentationr   r   jinja2.exceptionsr   starlette.backgroundr    starlette.responsesr!   r"   starlette.websocketsr#   r3   gradio.ranged_responserM  r$   r%   r&   gradio.contextr'   gradio.data_classesr(   r)   gradio.deprecationr*   gradio.exceptionsr+   gradio.oauthr,   gradio.queueingr-   r.   gradio.route_utilsr/   gradio.utilsr0   r1   r2   initjoinpathas_posixSTATIC_TEMPLATE_LIBr  r   	read_textVERSIONr9   r_   r4   envfiltersAsyncClientr   rb   r  r  r  rU   rH   rF   <module>r     s  U U # " " " " "  



v)))))))))))))      				                5 5 5 5 5 5 # # # # # #       2 2 2 2 2 2 2 2 2 2 2 2 2 2        X X X X X X X X X X X X X X X X X X 2 2 2 2 2 2            7 6 6 6 6 6 . . . . . . I I I I I I I I . . . . . . / / / / / / C C C C C C C C / / / / / /  0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 " " " " " " 6 6 6 6 6 6 6 6 / / / / / / # # # # # # % % % % % % - - - - - - - - & & & & & & L L L L L L L L L L 	   eHoo..{;;DDFF %//**;
HMMVVXXx))+z8LLUUWW
%//
"
"=
1
1
;
;
=
=? ? ? ? ?\ ? ? ?&   O&9:::	$,	 j !				J J J J J' J J Jd   6
 
 
 
   ! ! ! 

 "&(,( ( ( ( ( ( (rH   