o
    ni                     @   s   d dl Z d dlZd dlZd dlmZmZ d dlZed Ze e	Z
dddZdefdd	Zdefd
dZdefddZdefddZG dd dZddededee fddZdS )    N)LiteralOptional)pythonipythonjupyterrunc                 C   s   d|  dS )zReturns the HTML for a button used to reveal the element following it.

    The element immediately after the button must have `display: none`.
    z`<button onClick="this.nextSibling.style.display='block';this.style.display='none';">Display W&B z	</button> )whatr   r   S/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/wandb/sdk/lib/ipython.pytoggle_button   s   r   returnc                  C   s   dt jvrdS zddlm}  |  d u rW dS W n
 ty!   Y dS w |  jdi p+i dd pA|  jdi p;i dd }d	|  jv sQd
|vsQdt jv rSdS d
S )NIPythonr   r   )get_ipythonIPKernelAppconnection_file ColabKernelAppterminalr   spyderr   )	sysmodulesr   r   ImportErrorconfiggetlower
__module__)r   ip_kernel_app_connection_filer   r   r
   _get_python_type   s.   


r   c                   C   
   t  dkS )z,Returns True if we're in a Jupyter notebook.r   r   r   r   r   r
   
in_jupyter;      
r    c                   C   r   )z9Returns True if we're running in IPython in the terminal.r   r   r   r   r   r
   
in_ipython@   r!   r"   c                   C   s
   t  dkS )z4Returns True if we're running in Jupyter or IPython.r   r   r   r   r   r
   in_notebookE   r!   r#   c                   @   s8   e Zd ZdZdd Zdededdfdd	Zdd
dZdS )ProgressWidgetz<A simple wrapper to render a nice progress bar with a label.c                 C   sX   ddl m} || _|| _|j||d| _| | _| j| j| jg| _	d| _
d| _d S )Nr   )displayminmaxF)r   r%   _ipython_displaywidgetsFloatProgress	_progressLabel_labelVBox_widget
_displayed	_disabled)selfr*   r'   r(   r%   r   r   r
   __init__M   s   

zProgressWidget.__init__valuelabelr   Nc              
   C   s   | j rd S z|| j_|| j_| jsd| _| j| j W d S W d S  ty@ } zd| _ t	
| td W Y d }~d S d }~ww )NTz;Unable to render progress bar, see the user log for details)r2   r,   r5   r.   r1   r)   r%   r0   	Exceptionlogger	exceptionwandbtermwarn)r3   r5   r6   er   r   r
   updateY   s"   
zProgressWidget.updatec                 C   s   | j s| jsd S | j  d S )N)r2   r1   r0   close)r3   r   r   r
   r>   i   s   zProgressWidget.close)r   N)	__name__r   __qualname____doc__r4   floatstrr=   r>   r   r   r   r
   r$   J   s
    r$         ?r'   r(   c              	   C   s   t jd}z@|du r*t  td ddlm} W d   n1 s%w   Y  t|ds1J t|ds8J t|ds?J t	|| |d	W S  t
tfyR   Y dS w )
z?Return an ipywidget progress bar or None if we can't import it.
ipywidgetsNignorer   )r*   r/   r-   r+   r&   )r:   util
get_modulewarningscatch_warningssimplefilterIPython.htmlr*   hasattrr$   r   AssertionError)r'   r(   r*   r   r   r
   jupyter_progress_baro   s   

rO   )r   )r   rD   )loggingr   rI   typingr   r   r:   
PythonType	getLoggerr?   r8   r   r   boolr    r"   r#   r$   rB   rO   r   r   r   r
   <module>   s    

" %