o
    2h(                     @   s^   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 edG dd dZ
dS )    N)backend)keras_export)io_utilszkeras.utils.Progbarc                   @   sH   e Zd ZdZ					dddZdd	d
ZdddZdd Zdd ZdS )Progbara_  Displays a progress bar.

    Args:
        target: Total number of steps expected, None if unknown.
        width: Progress bar width on screen.
        verbose: Verbosity mode, 0 (silent), 1 (verbose), 2 (semi-verbose)
        stateful_metrics: Iterable of string names of metrics that should *not*
            be averaged over time. Metrics in this list will be displayed as-is.
            All others will be averaged by the progbar before display.
        interval: Minimum visual progress update interval (in seconds).
        unit_name: Display name for step counts (usually "step" or "sample").
          皙?Nstepc                 C   s   || _ || _|| _|| _|| _|rt|| _nt | _ttj	dr&tj	
 p4dtjv p4dtjv p4dtjv | _d| _i | _g | _t | _d| _| j| _d | _d| _d S )Nisatty	ipykernelposixPYCHARM_HOSTEDr   )targetwidthverboseinterval	unit_namesetstateful_metricshasattrsysstdoutr
   modulesosenviron_dynamic_display_seen_so_far_values_values_ordertime_start_last_update_time_at_epoch_start_time_after_first_step_prev_total_width)selfr   r   r   r   r   r    r&   R/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/utils/progbar.py__init__   s.   	

zProgbar.__init__c              
   C   s  |du r| j du rd}n|| j k}|pg }|D ]U\}}|| jvr&| j| || jvre|r5|dg| j|< qt|| j d}|| jvrL|| |g| j|< q| j| d  || 7  < | j| d  |7  < q|dg| j|< q|| _d}d}t }	| ||	}
| j	dkr|	| j
 | jk r|sdS | jr|d| j 7 }|d7 }n|d7 }| j durtt| j d }d	t| d
 || j f }d| d}|d7 }t|| j  }t| j| }|dkr|dd|  d 7 }|d7 }|dd| j|   d 7 }|d7 }nd| }||7 }| j durC|sC|
| j |  }|dkr(d|d |d d |d f }n|dkr8d|d |d f }nd| }d| d}n
d|	| j dd}|d7 }|| |
| j7 }| jD ]U}|d| d7 }t| j| trttj| j| d td| j| d  }t|}t|dkr|d|d 7 }q]|d|d!7 }q]|d| j|  7 }q]||7 }t|t| | }| j|kr|d| j|  7 }|r|d7 }tj |dd" || _d}n| j	d#krj|rjtt| j d }d	t| d
 || j f }| d|	| j dd$}|d%| |
| j 7 }| jD ]:}|d| d7 }ttj| j| d td| j| d  }|dkrO|d|d 7 }q|d|d!7 }q|d7 }||7 }tj |dd" d}|	| _
dS )&a  Updates the progress bar.

        Args:
            current: Index of current step.
            values: List of tuples: `(name, value_for_last_step)`. If `name` is
                in `stateful_metrics`, `value_for_last_step` will be displayed
                as-is. Else, an average of the metric over time will be
                displayed.
            finalize: Whether this is the last update for the progress bar. If
                `None`, defaults to `current >= self.target`.
        NFr   r    
%zd/%dz[1mz[0m    z[32mu   ━z[0m	   z[37mz%7d/Unknowni  z%d:%02d:%02d<   z%d:%02dz%dsz [1m.0fzs[0mz - :MbP? z.4fz.4e)
line_break   sz -)!r   r   appendr   r   maxr   r   _estimate_step_durationr   r!   r   r   r$   intmathlog10strfloatr   r    _format_timer   
isinstancelistr   convert_to_numpynumpymeanabslenr   	print_msg)r%   currentvaluesfinalizekv
value_basemessagespecial_char_lennowtime_per_unit	numdigitsbarprog
prog_widtheta
eta_formatinfoavgtotal_widthcountr&   r&   r'   update>   s   











 
 

zProgbar.updatec                 C   s   |  | j| | d S N)r]   r   )r%   nrJ   r&   r&   r'   add   s   zProgbar.addc                 C   sr   d}|dks
|dkr|d|dd| 7 }|S |dkr*|d|d dd	| 7 }|S |d|d
 dd| 7 }|S )a  format a given duration to display to the user.

        Given the duration, this function formats it in either milliseconds
        or seconds and displays the unit (i.e. ms/step or s/epoch).

        Args:
            time_per_unit: the duration to display
            unit_name: the name of the unit to display

        Returns:
            A string with the correctly formatted duration and units
        r)   r   r   r4   r1   zs/r3   g     @@zms/g    .Azus/r&   )r%   rR   r   	formattedr&   r&   r'   r@      s   zProgbar._format_timec                 C   sN   |r%| j dur|dkr|| j  |d  }n|| j | }|dkr#|| _ |S dS )a  Estimate the duration of a single step.

        Given the step number `current` and the corresponding time `now` this
        function returns an estimate for how long a single step takes. If this
        is called before one step has been completed (i.e. `current == 0`) then
        zero is given as an estimate. The duration estimate ignores the duration
        of the (assumed to be non-representative) first step for estimates when
        more steps are available (i.e. `current>1`).

        Args:
            current: Index of current step.
            now: The current time.

        Returns: Estimate of the duration of a single step.
        Nr   r   )r#   r    )r%   rI   rQ   rR   r&   r&   r'   r:      s   zProgbar._estimate_step_duration)r   r   r   Nr	   )NNr^   )	__name__
__module____qualname____doc__r(   r]   r`   r@   r:   r&   r&   r&   r'   r      s    

$ 
r   )r<   r   r   r   	keras.srcr   keras.src.api_exportr   keras.src.utilsr   r   r&   r&   r&   r'   <module>   s    