a
    d
                     @   sz   d 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
Z
ddl
mZmZ dd Zd	d
 Zedkrve  dS )a#  

Contains the functions that run when `gradio` is called from the command line. Specifically, allows

$ gradio app.py, to run app.py in reload mode where any changes in the app.py file or Gradio library reloads the demo.
$ gradio app.py my_demo.app, to use variable names other than "demo"
    N)Path)Config)ChangeReload)
networkingutilsc                  C   s  t jdd  } t| dkr"tdt| dks<| d drBd}n| d }d|vrZtd | d }t|}tj	
|}|dd}|d	d}tj	|d }tttj}ttjtjtj }td
tj d| d | d| }d}	d}
g }t| r(|| |	d| d7 }	|
d7 }
|j}t| rh|| |
dkrX|	d7 }	|	d| d7 }	t|	d  t j	dt  t|d|d|dS )N   r   zNo file specified.z--zdemo.app.z
WARNING: As of Gradio 3.31, the parameter after the file path must be the name of the FastAPI app, not the Gradio demo. In most cases, this just means you should add '.app' after the name of your demo, e.g. 'demo' -> 'demo.app'./\z'
Launching in *reload mode* on: http://:z (Press CTRL+C to quit)
z	Watching:z '',
Twarning)reloadportZ	log_levelZreload_dirs)sysargvlen
ValueError
startswithprintr   abspathospathnormpathreplacesplitextr   inspectgetfilegradioparentr   Zget_first_available_portZINITIAL_PORT_VALUEZTRY_NUM_PORTSZLOCALHOST_NAMEstrstripappendinsertgetcwdr   )argsZ	demo_nameZoriginal_pathZabs_original_pathr   filenameZgradio_folderr   Z
gradio_appmessageZmessage_change_countZwatching_dirsZ
abs_parent r*   V/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/gradio/reload.py_setup_config   s^    




r,   c                  C   s2   t  } t| }|  }t| |j|gd  d S )N)targetZsockets)r,   r   ServerZbind_socketr   run)configserversockr*   r*   r+   mainR   s    
r3   __main__)__doc__r   r   r   pathlibr   Zuvicornr   Zuvicorn.supervisorsr   r    r   r   r,   r3   __name__r*   r*   r*   r+   <module>   s   >