
    FgJ                    |   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
  S SKrS SKJr  S SKJr  S SKJr  S SKJrJr  \
(       a   \" \R,                  " S	S
5      5      r\" \R,                  " SS5      5      r\R,                  " SS5      r\" \R,                  " SS5      5      r\(       a"  \R,                  " SS5      R9                  S5      O/ r\R,                  " SS5      r\R,                  " SS5      r\R,                  " SS5      r  " S S\RB                  5      r!     S             SS jjr"g)    )annotationsN)partial)TYPE_CHECKING)Config)ServerFailedToStartError)App)SourceFileReloaderwatchfnGRADIO_SERVER_PORT7860GRADIO_NUM_PORTS100GRADIO_SERVER_NAMEz	127.0.0.1GRADIO_WATCH_DIRS ,GRADIO_WATCH_MODULE_NAMEappGRADIO_WATCH_DEMO_NAMEdemoGRADIO_WATCH_DEMO_PATHc                  N   ^  \ rS rSr S     SU 4S jjjrS rS rS rSrU =r	$ )	Server$   c                   > UR                   U l        [        TU ]  U5        X l        U R                  (       a:  [
        R                  " 5       U l        [        [        U R                  5      U l
        g g N)r   running_appsuper__init__reloader	threadingEventeventr   r
   watch)selfconfigr    	__class__s      c/Users/admin/workspace/ai/PDFMathTranslate/myenv/lib/python3.13/site-packages/gradio/http_server.pyr   Server.__init__%   sO     "::  =="*DJ $--8DJ     c                    g r    r%   s    r(   install_signal_handlersServer.install_signal_handlers/   s    r*   c                   [         R                  " U R                  SS9U l        U R                  (       a>  [         R                  " U R
                  SS9U l        U R                  R                  5         U R                  R                  5         [        R                  " 5       nU R                  (       dQ  [        R                  " S5        [        R                  " 5       U-
  S:  a  [        S5      eU R                  (       d  MP  g g )NT)targetdaemongMbP?   z@Server failed to start. Please check that the port is available.)r!   Threadrunthreadr    r$   watch_threadstarttimestartedsleepr   )r%   r8   s     r(   run_in_threadServer.run_in_thread2   s    &&dhhtD== ) 0 0

4 PD##%		,,JJtyy{U"Q&.V  ,,,r*   c                    SU l         U R                  (       a4  U R                  R                  5         U R                  R	                  5         U R
                  R	                  SS9  g )NTr3   )timeout)should_exitr    stopr7   joinr6   r-   s    r(   closeServer.close@   sH    ==MM ""$#r*   )r#   r    r   r@   r6   r$   r7   r   )r&   r   r    zSourceFileReloader | NonereturnNone)
__name__
__module____qualname____firstlineno__r   r.   r<   rC   __static_attributes____classcell__)r'   s   @r(   r   r   $   s<    DH99(A9	9 9$ $r*   r   c                   Ub  Uc  [        S5      eU=(       d    [        nUS:X  a  SOUnUR                  S5      (       a  UR                  S5      (       a  USS nOUnUb  U/O[	        [
        [
        [        -   5      nU H  n	 [        R                  " 5       n
U
R                  [        R                  [        R                  S5        U
R                  [        U	45        U
R                  5         [        R                  " U U	US	UUUS
9nSn[        (       aC  [!        U [        ["        [$        [&        R(                  " 5       [*        [,        R.                  S   S9n[1        XS9nUR3                  5           O&   [5        S[9        U5       S[;        U5       S35      eUb
  SU SU	 S3nO	SU SU	 S3nXX4$ ! [4        [6        4 a     GMH  f = f)a  Launches a local server running the provided Interface
Parameters:
    app: the FastAPI app object to run
    server_name: to make app accessible on local network, set this to "0.0.0.0". Can be set by environment variable GRADIO_SERVER_NAME.
    server_port: will start gradio app on this port (if available). Can be set by environment variable GRADIO_SERVER_PORT.
    auth: If provided, username and password (or list of username-password tuples) required to access the Blocks. Can also provide function that takes username and password and returns True if valid login.
    ssl_keyfile: If a path to a file is provided, will use this as the private key file to create a local server running on https.
    ssl_certfile: If a path to a file is provided, will use this as the signed certificate for https. Needs to be provided if ssl_keyfile is provided.
    ssl_keyfile_password: If a password is provided, will use this with the ssl certificate for https.

Returns:
    server_name: the name of the server (default is "localhost")
    port: the port number the server is running on
    path_to_local_server: the complete address that the local server can be accessed at
    server: the server object that is a subclass of uvicorn.Server (used to close the server)
Nz9ssl_certfile must be provided if ssl_keyfile is provided.z0.0.0.0	localhost[]   warning)r   porthost	log_levelssl_keyfilessl_certfilessl_keyfile_password__main__)r   
watch_dirswatch_module_name	demo_name
stop_event	demo_filewatch_module)r&   r    z!Cannot find empty port in range: -z. You can specify a different port by setting the GRADIO_SERVER_PORT environment variable or passing the `server_port` parameter to `launch()`.zhttps://:/zhttp://)
ValueErrorLOCALHOST_NAME
startswithendswithrangeINITIAL_PORT_VALUETRY_NUM_PORTSsocket
setsockopt
SOL_SOCKETSO_REUSEADDRbindrC   uvicornr   r   r	   r   r   r!   r"   r   sysmodulesr   r<   OSErrorr   minmax)r   server_nameserver_portrW   rX   rY   url_host_namerU   server_portsrT   sr&   r    serverpath_to_local_servers                  r(   start_serverr}   H   s   0 <#7TUU/K#.)#;KM
 c""{';';C'@'@1R  " 
%'9M'IJ  %	 ALL**F,?,?C FFND)*GGI ^^#')%9F H  -0&>4(04!$Z!8 6=F  "I P /L0A/B!CDUCV  Wf  g
 	
 !)-$qA!(qa@2:: 12 		s   C.F66G
G)NNNNN)r   r   rv   
str | Nonerw   z
int | NonerW   r~   rX   r~   rY   r~   rE   ztuple[str, int, str, Server])#
__future__r   osrk   rq   r!   r9   	functoolsr   typingr   rp   uvicorn.configr   gradio.exceptionsr   gradio.routesr   gradio.utilsr	   r
   intgetenvri   rj   re   boolshould_watchsplitr   r   r   r   r   r}   r,   r*   r(   <module>r      sT   " 	  
       ! 6  4 #7@A BII0%89/=BII12675ABII!2&,,S1r  99%?G #;VD #;R@ !$W^^ !$L #""#'+];	];]; ]; 	];
 ]; %]; "];r*   