
    wi                        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	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j        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"
    )annotationsN)Path)print)utilsdemoutf-8F	demo_pathr   	demo_namestradditional_watch_dirslist[str] | Noneencodingwatch_libraryboolc                   t          |           }|                    |          d| | d| d| d| dg}t          fd|D                       st          d| d	           t	          j        |          }|                                r'|                    t          j                              }n|}t          |j
        |j        z                                t          j        j        d
          }	t          t!          j        t$                              j
        }
d}d}g }t          |
                                          r%|r#|                    |
           |d|
 dz  }|dz  }|j
        }t          |                                          r)|                    |           |dk    r|dz  }|d| dz  }t          j                                                    }t          |                                          r-||vr)|                    |           |dk    r|dz  }|d| dz  }|pg D ]<}t          |          |vr)|                    |           |dk    r|dz  }|d| dz  }=t          |dz              t,          j                            dt          j                               |	|d |D             |fS )N)r   zwith (?:gr\.)?Blocks\(.*\) as z = gr\.Blocksz = gr\.Interfacez = gr\.ChatInterfacez = gr\.TabbedInterfacec              3  Z   K   | ]%}t          j        |t           j                   V  &dS ))flagsN)researchDOTALL).0papp_texts     j/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/gradio/cli/commands/reload.py	<genexpr>z _setup_config.<locals>.<genexpr>.   s6      II1ryHBI666IIIIII    zC
[bold red]Warning[/]: Cannot statically find a gradio demo called z. Reload work may fail..z	Watching:r   z ''   ,
c                ,    g | ]}t          |          S  )r   )r   ss     r   
<listcomp>z!_setup_config.<locals>.<listcomp>b   s    +J+J+JqCFF+J+J+Jr   )r   	read_textanyr   r   abspathis_absoluterelative_tocwdr   parentstemreplaceospathsepinspectgetfilegradiostripappendabsolutesysinsertgetcwd)r	   r
   r   r   r   original_pathpatternsabs_original_pathrelpathmodule_namegradio_foldermessagemessage_change_countwatching_dirs
abs_parentabs_currentwdr   s                    @r   _setup_configrG      s6    OOM&&&99H 	6)55$$$'''+++---H IIIIIIIII 
$S\ $ $ $	
 	
 	

 m44  ""  ++DHJJ77gnw|344<<RW[#NNK00118MGM
=!! "m "]+++(((((!")J
: &Z(((1$$sNG%
%%%%(**%%''K
; 'K}$D$D[)))1$$sNG&&&&&#)r " "88=((  $$$#q((3zBzzz!G	'D. HOOAry{{###)+J+JM+J+J+JIUUr   
watch_dirsc           	        t          | ||||          \  }}}}t          t          j        d                    |          ||t          |          |          }dt          j        v rt          j        d         |d<   t          j        t          j	        d|g|          }	|	
                                /	 |	                                 d S # t          t          f$ r Y d S w xY wd S )Nr    )GRADIO_WATCH_DIRSGRADIO_WATCH_MODULE_NAMEGRADIO_WATCH_DEMO_NAMEGRADIO_WATCH_DEMO_PATHGRADIO_WATCH_ENCODINGGRADIO_VIBE_MODEz-u)env)rG   dictr/   environjoinr   
subprocessPopenr8   
executablepollwaitKeyboardInterruptOSError)
r	   r
   rH   r   r   r?   r0   watch_sourcesenv_varspopens
             r   mainr^   e   s    3@9j(M3 3/K}i 

((=11!,("4yy&  H RZ''')z2D'E#$	t$  E zz||	JJLLLLL!7+ 	 	 	DD	 s   3C	 	CC__main__)r   Nr   F)
r	   r   r
   r   r   r   r   r   r   r   )
r	   r   r
   r   rH   r   r   r   r   r   )__doc__
__future__r   r2   r/   r   rT   r8   	threadingpathlibr   typerrichr   r4   r   localreload_threadrG   r^   __name__runr#   r   r   <module>rj      s8    # " " " " "  				 				     



                        	!!
 .2FV FV FV FV FVV #'" " " " "J zEIdOOOOO r   