
    U[i                       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mZ d dl	m
Z
 d dlmZm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mZ er
 ed
e      Z e ej<                  dd            Z e ej<                  dd            Z  ej<                  dd      Z! ej<                  dd      jE                         Z# e$ ej<                  dd            Z%e%r" ej<                  dd      jM                  d      ng Z' ej<                  dd      Z( ej<                  dd      Z) ej<                  dd      Z* G d dejV                        Z+	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ,y)     )annotationsN)Callable)partial)TYPE_CHECKINGTypeVar)Config)ServerFailedToStartError)App)ServerReloaderSourceFileReloaderSpacesReloader	get_spacewatchfnwatchfn_spaces_ServerReloaderT)boundGRADIO_SERVER_PORT7860GRADIO_NUM_PORTS100GRADIO_SERVER_NAMEz	127.0.0.1GRADIO_HOT_RELOADfalseGRADIO_WATCH_DIRS ,GRADIO_WATCH_MODULE_NAMEappGRADIO_WATCH_DEMO_NAMEGRADIO_WATCH_DEMO_PATHc                  F     e Zd Zdef	 	 	 	 	 	 	 d fdZd Zd Zd Z xZS )ServerNc                    |j                   | _        t        |   |       || _        | j                  r5t        j                         | _        t        || j                        | _	        y y N)
r   running_appsuper__init__reloader	threadingEventeventr   watch)selfconfigr(   r   	__class__s       `/var/www/html/chatbot/Makanify-Chatbot-3/venv/lib/python3.12/site-packages/gradio/http_server.pyr'   zServer.__init__/   sQ     "::  =="*DJ $--8DJ     c                     y r$    r-   s    r0   install_signal_handlerszServer.install_signal_handlers<   s    r1   c                   t        j                  | j                  d      | _        | j                  r@t        j                  | j
                  d      | _        | j                  j                          | j                  j                          t        j                         }| j                  sHt        j                  d       t        j                         |z
  dkD  rt        d      | j                  sGy y )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-   r>   s     r0   run_in_threadzServer.run_in_thread?   s    &&dhhtD== ) 0 0

4 PD##%		,,JJtyy{U"Q&.V  ,,r1   c                    d| _         | j                  r4| j                  j                          | j                  j	                          | j
                  j	                  d       y )NTr9   )timeout)should_exitr(   stopr=   joinr<   r4   s    r0   closezServer.closeM   sH    ==MM ""$#r1   )r.   r   r(   z_ServerReloaderT | Noner   z"Callable[[_ServerReloaderT], None]returnNone)	__name__
__module____qualname__r   r'   r5   rB   rH   __classcell__)r/   s   @r0   r"   r"   .   sE     -16=	99 *9 4	9
 
9$r1   r"   c                h   ||t        d      |xs t        }|dk(  rdn|}|j                  d      r|j                  d      r|dd }n|}||gnt	        t
        t
        t        z         }|D ]l  }		 t        j                         }
|
j                  t        j                  t        j                  d       |
j                  t        |	f       |
j                          t        j                  | |	|d|||	      }t               Nt!        | t"        t$        t'        j(                         t*        j,                  d
         }t/        ||t0              }nzt"        rht3        | t"        t4        t$        t'        j(                         t6        t*        j,                  d
   t9        j:                  dd            }t/        ||      }nt/        |      }|j=                           n% t?        dtC        |       dtE        |       d      |
d| d|	 d}n	d| d|	 d}||	||fS # t>        t@        f$ r Y w xY w)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)
    z9ssl_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	demo_name
stop_eventwatch_module)r.   r(   r   GRADIO_WATCH_ENCODINGzutf-8)r   r]   watch_module_namer^   r_   	demo_filer`   encoding)r.   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bindrH   uvicornr   r   r   r   r   r)   r*   sysmodulesr"   r   r   r   r    osgetenvrB   OSErrorr	   minmax)r   server_nameserver_portrY   rZ   r[   url_host_namerW   server_portsrV   sr.   r(   serverpath_to_local_servers                  r0   start_serverr   U   sI   0 <#7TUU/K#.)#;KM
 c"{';';C'@1R  " 
%'9M'IJ   7
2	 ALL**F,?,?C FFND)*GGI ^^#')%9F {&)04(0!$Z!8  !Hn #-0&>4(04!$Z!8YY'>H	  vAv.  "c7
j /L0A/B!CDUCV  Wf  g
 	
 !)-$qA!(qa@2F:: 12 		s   4E(HH10H1)NNNNN)r   r
   r|   
str | Noner}   z
int | NonerY   r   rZ   r   r[   r   rI   ztuple[str, int, str, Server])-
__future__r   rw   ro   ru   r)   r?   collections.abcr   	functoolsr   typingr   r   rt   uvicorn.configr   gradio.exceptionsr	   gradio.routesr
   gradio.utilsr   r   r   r   r   r   r   intrx   rm   rn   ri   lowerr   boolshould_watchsplitr   r   r   r    r"   r   r3   r1   r0   <module>r      s   " 	  
   $  )  ! 6   1H #7@A IBII0%89/=BII17;AAC IBII12675AIBII!2&,,S1r  %299%?G "#;R@ "#;R@ $$W^^ $$R #""#'+j;	j;j; j; 	j;
 j; %j; "j;r1   