
    Pi	                         	 d dl mZmZ d dlmZmZmZ n# e$ r Y nw xY wd dlZ	d dl
mZ d dlmZ  G d d          Z G d d	e          Zd
 ZdS )    )needs_local_scoperegister_cell_magic)argumentmagic_argumentsparse_argstringN)App)BaseReloaderc                       e Zd ZdZd Zd ZdS )CellIdTrackerzyDetermines the most recently run cell in the notebook.

    Needed to keep track of which demo the user is updating.
    c                 b    |j                             d| j                   || _        d| _        d S )Npre_run_cell )eventsregisterr   shellcurrent_cell)selfipythons     f/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/gradio/ipython_ext.py__init__zCellIdTracker.__init__   s2    0ABBB
!#    c                     |j         | _        d S N)cell_id_current_cell)r   infos     r   r   zCellIdTracker.pre_run_cell   s    !\r   N)__name__
__module____qualname____doc__r   r    r   r   r   r      s<         
$ $ $
* * * * *r   r   c                        e Zd ZdZd fdZed             Zedefd            Zed             Z	de
fdZd	ej        fd
Z xZS )JupyterReloaderzHSwap a running blocks class in a notebook with the latest cell contents.returnNc                 ~    t                                                       t          |          | _        i | _        d S r   )superr   r   _cell_tracker_running)r   r   	__class__s     r   r   zJupyterReloader.__init__!   s4    *733.0r   c                     | j         j        S r   )r'   r   r   s    r   r   zJupyterReloader.current_cell&   s    !..r   c                 Z    | j         j        st          d          | j         j        j        S )NzServer not running)running_demoserverRuntimeErrorrunning_appr+   s    r   r0   zJupyterReloader.running_app*   s.     ' 	53444 '33r   c                 &    | j         | j                 S r   r(   r   r+   s    r   r-   zJupyterReloader.running_demo0   s    }T.//r   c                     | j         | j        v S r   )r   r(   r+   s    r   demo_trackedzJupyterReloader.demo_tracked4   s     DM11r   democ                 $    || j         | j        <   d S r   r2   )r   r5   s     r   trackzJupyterReloader.track7   s    +/d'(((r   )r$   N)r   r   r   r    r   propertyr   r   r0   r-   boolr4   grBlocksr7   __classcell__)r)   s   @r   r#   r#      s        RR1 1 1 1 1 1
 / / X/ 4S 4 4 4 X4
 0 0 X02d 2 2 2 20") 0 0 0 0 0 0 0 0r   r#   c           	          t          |           t                      t          ddd          t          ddddd	
          t          t          fd                                                            d S )Nz--demo-namer5   zName of gradio blocks instance.)defaulthelpz--shareFT?z9Whether to launch with sharing. Will slow down reloading.)r>   constnargsr?   c                 .   t          |           }t          |d|           ||j                 }                                s2|                    |j                                       |           dS                     |           j        j	        S )z/Launch a demo defined in a cell in reload mode.N)share)
r   exec	demo_namer4   launchrD   r7   swap_blocksr-   artifact)linecelllocal_nsargsr5   blocksreloaders        r   rN   z&load_ipython_extension.<locals>.blocks>   s     vt,,T4""""4>2$$&& 	2KKdjK)))NN4       &&&(11r   )r#   r   r   r   r   )r   rN   rO   s    @@r   load_ipython_extensionrP   ;   s    w''HmV2STTTH   2 2 2 2 2    UT 2 2 2r   )IPython.core.magicr   r   IPython.core.magic_argumentsr   r   r   ImportErrorgradior:   gradio.routesr   gradio.utilsr	   r   r#   rP   r!   r   r   <module>rW      s  	        XWWWWWWWWWW 	 	 	D	           % % % % % %* * * * * * * *0 0 0 0 0l 0 0 0:2 2 2 2 2s    