o
    h0                     @   s^  U d Z ddlZddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZ ddlmZ ddlmZ e Zdaeej ed< ejejej
ejejejdZejZe  a d	d
 Z!de"fddZ#dej$fddZ%dIddZ&dIddZ'dd Z(dd ZdJdee" dej$fddZ)de*fddZ+de*ddfddZ,d d! Z-d"d# Z.d$d% Z/d&d' Z0dId(d)Z1dId*d+Z2d,ejddfd-d.Z3d,ejddfd/d0Z4dId1d2Z5dId3d4Z6dId5d6Z7dId7d8Z8d9d: Z9e9ej$_9e:dd;d< Z;e;ej$_;e:dd=d> Z<e<ej$_<G d?d@ d@Z=G dAdB dBZ>e> Zde?fdCdDZ@dEdF ZAdGdH ZBdS )KzLogging utilities.    N)CRITICALDEBUGERRORFATALINFONOTSETWARNWARNING)captureWarnings)Optional)auto_default_handler)detaildebuginfowarningerrorcriticalc               	   C   sH   t dd} | r"| tv rt|  S t d|  ddt   tS )z
    If TRANSFORMERS_VERBOSITY env var is set to one of the valid choices return that as the new default level. If it is
    not - fall back to `_default_log_level`
    TRANSFORMERS_VERBOSITYNz&Unknown option TRANSFORMERS_VERBOSITY=z, has to be one of: z, )	osgetenv
log_levelslogging	getLoggerr   joinkeys_default_log_level)env_level_str r   n/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/transformers/utils/logging.py_get_default_logging_level7   s   r    returnc                   C   s   t dd S )N.r   )__name__splitr   r   r   r   _get_library_nameH   s   r%   c                   C   s   t t S N)r   r   r%   r   r   r   r   _get_library_root_loggerL   s   r'   c                  C   s   t ` tr	 W d    d S t atjd u rttjdt_tjj	t_	t
 } | t | t  tdd dkrCtd}t| tdd uoRtd dv }|rWdnd| _W d    d S 1 sew   Y  d S )	Nwr   r   zB[%(levelname)s|%(pathname)s:%(lineno)s] %(asctime)s >> %(message)sCI>   1ONYESTRUETF)_lockr   r   StreamHandlersysstderropenr   devnullflushr'   
addHandlersetLevelr    r   	FormattersetFormatterupper	propagate)library_root_logger	formatteris_cir   r   r   _configure_library_root_loggerP   s"   




 "r>   c                  C   s`   t $ ts	 W d    d S t } | t | tj d aW d    d S 1 s)w   Y  d S r&   )r.   r   r'   removeHandlerr6   r   r   )r;   r   r   r   _reset_library_root_loggerk   s   
"r@   c                   C   s   t S r&   )r   r   r   r   r   get_log_levels_dictx      rA   c                 C   s2   t d}|js|t |t j t|  dS )a   
    Calls the `captureWarnings` method from the logging library to enable management of the warnings emitted by the
    `warnings` library.

    Read more about this method here:
    https://docs.python.org/3/library/logging.html#integration-with-the-warnings-module

    All warnings will be logged through the `py.warnings` logger.

    Careful: this method also adds a handler to this logger if it does not already have one, and updates the logging
    level of that logger to the library's root logger.
    zpy.warningsN)
get_loggerhandlersr5   r   r6   r'   level_captureWarnings)captureloggerr   r   r   r
   |   s
   
r
   namec                 C   s   | du rt  } t  t| S )z
    Return a logger with the specified name.

    This function is not supposed to be directly accessed unless you are writing a custom transformers module.
    N)r%   r>   r   r   )rI   r   r   r   rC      s   
rC   c                   C   s   t   t  S )u  
    Return the current level for the 🤗 Transformers's root logger as an int.

    Returns:
        `int`: The logging level.

    <Tip>

    🤗 Transformers has following logging levels:

    - 50: `transformers.logging.CRITICAL` or `transformers.logging.FATAL`
    - 40: `transformers.logging.ERROR`
    - 30: `transformers.logging.WARNING` or `transformers.logging.WARN`
    - 20: `transformers.logging.INFO`
    - 10: `transformers.logging.DEBUG`

    </Tip>)r>   r'   getEffectiveLevelr   r   r   r   get_verbosity   s   
rK   	verbosityc                 C   s   t   t |  dS )u  
    Set the verbosity level for the 🤗 Transformers's root logger.

    Args:
        verbosity (`int`):
            Logging level, e.g., one of:

            - `transformers.logging.CRITICAL` or `transformers.logging.FATAL`
            - `transformers.logging.ERROR`
            - `transformers.logging.WARNING` or `transformers.logging.WARN`
            - `transformers.logging.INFO`
            - `transformers.logging.DEBUG`
    N)r>   r'   r6   )rL   r   r   r   set_verbosity   s   rM   c                   C      t tS )z&Set the verbosity to the `INFO` level.)rM   r   r   r   r   r   set_verbosity_info      rO   c                   C   rN   )z)Set the verbosity to the `WARNING` level.)rM   r	   r   r   r   r   set_verbosity_warning   rP   rQ   c                   C   rN   )z'Set the verbosity to the `DEBUG` level.)rM   r   r   r   r   r   set_verbosity_debug   rP   rR   c                   C   rN   )z'Set the verbosity to the `ERROR` level.)rM   r   r   r   r   r   set_verbosity_error   rP   rS   c                   C   "   t   tdus	J t t dS )zJDisable the default handler of the HuggingFace Transformers's root logger.N)r>   r   r'   r?   r   r   r   r   disable_default_handler      rU   c                   C   rT   )zIEnable the default handler of the HuggingFace Transformers's root logger.N)r>   r   r'   r5   r   r   r   r   enable_default_handler   rV   rW   handlerc                 C   s"   t   | dus	J t |  dS )z=adds a handler to the HuggingFace Transformers's root logger.N)r>   r'   r5   rX   r   r   r   add_handler   rV   rZ   c                 C   s.   t   | dur| t jvsJ t |  dS )zFremoves given handler from the HuggingFace Transformers's root logger.N)r>   r'   rD   r?   rY   r   r   r   remove_handler   s   r[   c                   C      t   dt _dS )zk
    Disable propagation of the library log outputs. Note that log propagation is disabled by default.
    FNr>   r'   r:   r   r   r   r   disable_propagation  s   r^   c                   C   r\   )z
    Enable propagation of the library log outputs. Please disable the HuggingFace Transformers's default handler to
    prevent double logging if the root logger has been configured.
    TNr]   r   r   r   r   enable_propagation  s   r_   c                  C   s*   t  j} | D ]}td}|| qdS )a  
    Enable explicit formatting for every HuggingFace Transformers's logger. The explicit formatter is as follows:
    ```
        [LEVELNAME|FILENAME|LINE NUMBER] TIME >> MESSAGE
    ```
    All handlers currently bound to the root logger are affected by this method.
    zB[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)sN)r'   rD   r   r7   r8   )rD   rX   r<   r   r   r   enable_explicit_format  s
   
r`   c                  C   s    t  j} | D ]}|d qdS )z
    Resets the formatting for HuggingFace Transformers's loggers.

    All handlers currently bound to the root logger are affected by this method.
    N)r'   rD   r8   )rD   rX   r   r   r   reset_format%  s   ra   c                 O   s(   t dd}|r
dS | j|i | dS )z
    This method is identical to `logger.warning()`, but if env var TRANSFORMERS_NO_ADVISORY_WARNINGS=1 is set, this
    warning will not be printed
    !TRANSFORMERS_NO_ADVISORY_WARNINGSFN)r   r   r   )selfargskwargsno_advisory_warningsr   r   r   warning_advice1  s   rg   c                 O      | j |i | dS )a  
    This method is identical to `logger.warning()`, but will emit the warning with the same message only once

    Note: The cache is for the function arguments, so 2 different callers using the same arguments will hit the cache.
    The assumption here is that all warning messages are unique across the code. If they aren't then need to switch to
    another type of cache that includes the caller frame information in the hashing function.
    N)r   rc   rd   re   r   r   r   warning_once?     	rj   c                 O   rh   )a  
    This method is identical to `logger.info()`, but will emit the info with the same message only once

    Note: The cache is for the function arguments, so 2 different callers using the same arguments will hit the cache.
    The assumption here is that all warning messages are unique across the code. If they aren't then need to switch to
    another type of cache that includes the caller frame information in the hashing function.
    N)r   ri   r   r   r   	info_onceN  rk   rl   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )	EmptyTqdmz%Dummy tqdm which doesn't do anything.c                 O   s   |r	|d | _ d S d | _ d S )Nr   )	_iteratorri   r   r   r   __init__`  s   zEmptyTqdm.__init__c                 C   s
   t | jS r&   )iterrn   rc   r   r   r   __iter__c  s   
zEmptyTqdm.__iter__c                 C   s   dd }|S )zReturn empty function.c                  _      d S r&   r   )rd   re   r   r   r   empty_fni  rB   z'EmptyTqdm.__getattr__.<locals>.empty_fnr   )rc   _rt   r   r   r   __getattr__f  s   zEmptyTqdm.__getattr__c                 C   s   | S r&   r   rq   r   r   r   	__enter__n  rB   zEmptyTqdm.__enter__c                 C   rs   r&   r   )rc   type_value	tracebackr   r   r   __exit__q  rB   zEmptyTqdm.__exit__N)	r#   
__module____qualname____doc__ro   rr   rv   rw   r{   r   r   r   r   rm   ]  s    rm   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )	_tqdm_clsc                 O   s"   t r
tj|i |S t|i |S r&   )_tqdm_activetqdm_libtqdmrm   ri   r   r   r   __call__v  s   z_tqdm_cls.__call__c                 O   s    d | _ trtjj|i |S d S r&   )r.   r   r   r   set_lockri   r   r   r   r   |  s   z_tqdm_cls.set_lockc                 C   s   t rtj S d S r&   )r   r   r   get_lockrq   r   r   r   r     s   
z_tqdm_cls.get_lockN)r#   r|   r}   r   r   r   r   r   r   r   r   u  s    r   c                   C   rN   )zCReturn a boolean indicating whether tqdm progress bars are enabled.)boolr   r   r   r   r   is_progress_bar_enabled  s   r   c                   C      da t  dS )zEnable tqdm progress bar.TN)r   hf_hub_utilsenable_progress_barsr   r   r   r   enable_progress_bar     r   c                   C   r   )zDisable tqdm progress bar.FN)r   r   disable_progress_barsr   r   r   r   disable_progress_bar  r   r   )r!   Nr&   )Cr~   	functoolsr   r   r0   	threadingr   r   r   r   r   r   r   r	   r
   rF   typingr   huggingface_hub.utilsutilsr   r   r   r   Lockr.   r   Handler__annotations__r   r   are_progress_bars_disabledr   r    strr%   Loggerr'   r>   r@   rA   rC   intrK   rM   rO   rQ   rR   rS   rU   rW   rZ   r[   r^   r_   r`   ra   rg   	lru_cacherj   rl   rm   r   r   r   r   r   r   r   r   r   <module>   st   (
	




			
	
	




