
    ;3h	                         	 d dl mZmZ d dlmZmZmZ 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y# e$ r Y 0w xY w)    )needs_local_scoperegister_cell_magic)argumentmagic_argumentsparse_argstringN)App)BaseReloaderc                       e Zd ZdZd Zd Zy)CellIdTrackerzyDetermines the most recently run cell in the notebook.

    Needed to keep track of which demo the user is updating.
    c                 l    |j                   j                  d| j                         || _        d| _        y )Npre_run_cell )eventsregisterr   shellcurrent_cell)selfipythons     R/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/ipython_ext.py__init__zCellIdTracker.__init__   s+    0A0AB
!#    c                 &    |j                   | _        y 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.returnc                 P    t         |           t        |      | _        i | _        y r   )superr   r   _cell_tracker_running)r   r   	__class__s     r   r   zJupyterReloader.__init__!   s"    *73.0r   c                 .    | j                   j                  S r   )r'   r   r   s    r   r   zJupyterReloader.current_cell&   s    !!...r   c                     | 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*   s5      ''344  ''333r   c                 4    | j                   | j                     S r   r(   r   r+   s    r   r-   zJupyterReloader.running_demo0   s    }}T..//r   c                 2    | j                   | j                  v S r   )r   r(   r+   s    r   demo_trackedzJupyterReloader.demo_tracked4   s      DMM11r   democ                 6    || j                   | j                  <   y 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#      sj    R1
 / / 4S 4 4
 0 02d 20")) 0r   r#   c           	          t        |       t               t        ddd      t        ddddd	
      t        t        fd                                   y )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                     }j                         s.|j	                  |j
                         j                  |       yj                  |       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>   su     vt,T4""4>>2$$&KKdjjK)NN4   &((111r   )r#   r   r   r   r   )r   rN   rO   s    @@r   load_ipython_extensionrP   ;   sc    w'HmV2STH 2   U 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      sS   	 XW   %* *0l 0:2i  		s   = AA