o
    e[                     @   s   d 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	Z	ddl	m
Z
 e Zdd Zdd Zed	kr?e  dS 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, to use variable names other than "demo"
    N)Path)utilsc                     s  t jdd  } t| dkrtdt| dks| d dr!d}n| d }d|v r4|dd }td | d }t|  d| | d	| d
| d| d| d| dg}t	 fdd|D sotd| d t
|}tj|}|dd}|dd}tj|d }tttj}d}d}	g }
t| r|
| |d| d7 }|	d7 }	|j}t| r|
| |	dkr|d7 }|d| d7 }t|d  t jdt  ||dd |
D |fS )N   r   zNo file specified.--demo.z
WARNING: As of Gradio 3.41.0, the parameter after the file path must be the name of the Gradio demo, not the FastAPI app. In most cases, this just means you should remove '.app' after the name of your demo, e.g. 'demo.app' -> 'demo'.zwith gr\.Blocks\(\) as z = gr\.Blocksz = gr\.Interfacez = gr\.ChatInterfacez = gr\.Seriesz = gr\.Parallesz = gr\.TabbedInterfacec                 3   s    | ]	}t | V  qd S )N)research).0pZapp_text =D:\Projects\ConvertPro\env\Lib\site-packages\gradio/reload.py	<genexpr>1   s    z _setup_config.<locals>.<genexpr>z6
Warning: Cannot statically find a gradio demo called z. Reload work may fail./\z	Watching:z '',
c                 S   s   g | ]}t |qS r   )str)r
   sr   r   r   
<listcomp>S   s    z!_setup_config.<locals>.<listcomp>)sysargvlen
ValueError
startswithsplitprintr   	read_textanyr   abspathospathnormpathreplacesplitextinspectgetfilegradioparentr   stripappendinsertgetcwd)args	demo_nameZoriginal_pathpatternsZabs_original_pathr#   filenameZgradio_foldermessageZmessage_change_countZwatching_dirsZ
abs_parentr   r   r   _setup_config   s^   




r4   c                  C   s   t  \} }}}tjdd  }t|dks|d dr!|dd  n|dd  }tjd|g| ttj	d
|| |dd}|  d S )Nr   r      pythonr   )ZGRADIO_WATCH_DIRSZGRADIO_WATCH_FILEZGRADIO_WATCH_DEMO_NAME)env)r4   r   r   r   r   
subprocessPopendictr"   environjoinwait)r2   r#   Z
watch_dirsr0   r/   
extra_argspopenr   r   r   mainV   s   2
	r@   __main__)__doc__r'   r"   r   r8   r   	threadingpathlibr   r)   r   localZreload_threadr4   r@   __name__r   r   r   r   <module>   s     @
