
    ;3hR                       d Z 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
mZ ddlmZ ddlZddlmZ ddlZddlmZ  e	j&                         Z	 	 	 d	 	 	 	 	 	 	 ddZ	 	 	 d	 	 	 	 	 	 	 dd	Zed
k(  r ej0                  e       yy)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"
    )annotationsN)Path)Optional)print)utilsc                   t        |       }|j                  |      d| | d| d| d| dg}t        fd|D              st        d| d	       t	        j
                  |      }|j                         r$|j                  t        j                               }n|}t        |j                  |j                  z        j                  t        j                  j                  d
      }t        t!        j"                  t$                    j                  d}	d}
g }t              j'                         rGt        fdt)        j*                         D              }|s|j-                         |	d dz  }	|
dz  }
|j                  }t        |      j'                         r$|j-                  |       |
dk(  r|	dz  }	|	d| dz  }	t        j                         j/                         }t        |      j'                         r$|j-                  |       |
dk(  r|	dz  }	|	d| dz  }	|xs g D ]4  }t        |      |vs|j-                  |       |
dk(  r|	dz  }	|	d| dz  }	6 t        |	dz          t0        j                  j3                  dt        j4                                |||D cg c]  }t        |       c}|fS c c}w )N)encodingzwith (?:gr\.)?Blocks\(.*\) as z = gr\.Blocksz = gr\.Interfacez = gr\.ChatInterfacez = gr\.TabbedInterfacec              3  j   K   | ]*  }t        j                  |t         j                          , yw))flagsN)researchDOTALL).0papp_texts     Z/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/cli/commands/reload.py	<genexpr>z _setup_config.<locals>.<genexpr>/   s%     I1ryyHBII66Is   03zC
[bold red]Warning[/]: Cannot statically find a gradio demo called z. Reload work may fail..z	Watching:r   c              3  J   K   | ]  }t        j                  |        y w)N)r   is_in_or_equal)r   dgradio_folders     r   r   z _setup_config.<locals>.<genexpr>D   s#      
78E  2
s    #z ''   ,
)r   	read_textanyr   r   abspathis_absoluterelative_tocwdstrparentstemreplaceospathsepinspectgetfilegradiostripsitegetsitepackagesappendabsolutesysinsertgetcwd)	demo_path	demo_nameadditional_watch_dirsr	   original_pathpatternsabs_original_pathrelpathmodule_namemessagemessage_change_countwatching_dirspackage_install
abs_parentabs_currentwdsr   r   s                    @@r   _setup_configrE      s    OM&&&9H *)5+^$+&'+*++,-H IIIRS\R] ^$ $	

 m4  "++DHHJ7gnnw||34<<RWW[[#NK0188MGM
=! 
<@<P<P<R
 
   /M?!,,G A% "))J
:Z(1$sNGR
|1%%((*%%'K
;[)1$sNGR}A&&#)r "8=(  $#q(3B4qz!G" 
'D. HHOOAryy{#)M+JqCF+JIUU+Js   +Kc                P   t        | |||      \  }}}}t        j                  t        j                  d|gt        t        j                  dj                  |      ||t        |                  }|j                         	 |j                          y y # t        t        f$ r Y y w xY w)Nz-ur   )GRADIO_WATCH_DIRSGRADIO_WATCH_MODULE_NAMEGRADIO_WATCH_DEMO_NAMEGRADIO_WATCH_DEMO_PATH)env)rE   
subprocessPopenr2   
executabledictr'   environjoinr#   pollwaitKeyboardInterruptOSError)r5   r6   
watch_dirsr	   r<   r(   watch_sourcespopens           r   mainrY   j   s     3@9j(3/K}i 	t$JJ!hh}5%0#,#&t9
	E zz|	JJL  "7+ 		s   B B%$B%__main__)demoNzutf-8)r5   r   r6   r#   r7   zlist[str] | Noner	   r#   )r5   r   r6   r#   rV   zOptional[list[str]]r	   r#   )__doc__
__future__r   r*   r'   r   r.   rL   r2   	threadingpathlibr   typingr   typerrichr   r,   r   localreload_threadrE   rY   __name__run     r   <module>ri      s    #  	 	   
       	!
 .2	IVIVIV ,IV 	IV\ &*	 $ 	< zEIIdO rh   