o
    ۷i	                     @   s   zd dl mZmZ d dlmZmZmZ W n	 ey   Y nw d dlZ	d dl
mZ d dlmZ G dd dZG dd	 d	eZd
d ZdS )    )needs_local_scoperegister_cell_magic)argumentmagic_argumentsparse_argstringN)App)BaseReloaderc                   @   s    e Zd ZdZdd Zd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                 C   s    |j d| j || _d| _d S )Npre_run_cell )eventsregisterr
   shellcurrent_cellselfipython r   H/home/ubuntu/vllm_env/lib/python3.10/site-packages/gradio/ipython_ext.py__init__   s   
zCellIdTracker.__init__c                 C   s   |j | _d S N)cell_id_current_cell)r   infor   r   r   r
         zCellIdTracker.pre_run_cellN)__name__
__module____qualname____doc__r   r
   r   r   r   r   r	      s    r	   c                       sj   e Zd ZdZd fddZedd Zedefdd	Zed
d Z	de
fddZdejfddZ  ZS )JupyterReloaderzHSwap a running blocks class in a notebook with the latest cell contents.returnNc                    s   t    t|| _i | _d S r   )superr   r	   _cell_tracker_runningr   	__class__r   r   r   !   s   


zJupyterReloader.__init__c                 C   s   | j jS r   )r"   r   r   r   r   r   r   &   s   zJupyterReloader.current_cellc                 C   s   | j jstd| j jjS )NzServer not running)running_demoserverRuntimeErrorrunning_appr&   r   r   r   r*   *   s   
zJupyterReloader.running_appc                 C   s   | j | j S r   r#   r   r&   r   r   r   r'   0   s   zJupyterReloader.running_democ                 C   s   | j | jv S r   )r   r#   r&   r   r   r   demo_tracked4   r   zJupyterReloader.demo_trackeddemoc                 C   s   || j | j< d S r   r+   )r   r-   r   r   r   track7   s   zJupyterReloader.track)r    N)r   r   r   r   r   propertyr   r   r*   r'   boolr,   grBlocksr.   __classcell__r   r   r$   r   r      s    

r   c              	      sH   t | t tddddtddddd	d
tt fdd d S )Nz--demo-namer-   zName of gradio blocks instance.)defaulthelpz--shareFT?z9Whether to launch with sharing. Will slow down reloading.)r4   constnargsr5   c                    sV   t  | }t|d| ||j } s"|j|jd | dS | jj	S )z/Launch a demo defined in a cell in reload mode.N)share)
r   exec	demo_namer,   launchr9   r.   swap_blocksr'   artifact)linecelllocal_nsargsr-   blocksreloaderr   r   rD   >   s   


z&load_ipython_extension.<locals>.blocks)r   r   r   r   r   )r   r   rC   r   load_ipython_extension;   s   rF   )IPython.core.magicr   r   IPython.core.magic_argumentsr   r   r   ImportErrorgradior1   gradio.routesr   gradio.utilsr   r	   r   rF   r   r   r   r   <module>   s    