





import functools
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


SCREAMING_SNAKE_CASE__       :			Optional[Any]			      =						threading.Lock()
SCREAMING_SNAKE_CASE__       :			Tuple			      =						None

SCREAMING_SNAKE_CASE__       :			Tuple			      =						{
    """debug""": logging.DEBUG,
    """info""": logging.INFO,
    """warning""": logging.WARNING,
    """error""": logging.ERROR,
    """critical""": logging.CRITICAL,
}

SCREAMING_SNAKE_CASE__       :			int			      =						logging.WARNING

SCREAMING_SNAKE_CASE__       :			str			      =						True






def       _A  (      ):
			a__	:						Union[str, Any]      		=  os.getenv("TRANSFORMERS_VERBOSITY"							, snake_case__   )
			if env_level_str:
						if env_level_str in log_levels:
									return log_levels[env_level_str]
						else:
									logging.getLogger().warning(
									    F"""Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, """
									    F"""has to be one of: { ", ".join(log_levels.keys()   ) }"""   )
			return _default_log_level






def       _A  (      ):
			return __name__.split("."   )[0]






def       _A  (      ):
			return logging.getLogger(_get_library_name()   )






def       _A  (      ):
			global _default_handler

			with _lock:
						if _default_handler:
									# This library has already configured the library root logger.
									return
						a__	:						Union[str, Any]      		=  logging.StreamHandler()  # Set sys.stderr as stream.
						a__	:						List[Any]      		=  sys.stderr.flush

						# Apply our default configuration to the library root logger.
						a__	:						Any      		=  _get_library_root_logger()
						library_root_logger.addHandler(_default_handler   )
						library_root_logger.setLevel(_get_default_logging_level()   )
						a__	:						str      		=  False






def       _A  (      ):
			global _default_handler

			with _lock:
						if not _default_handler:
									return

						a__	:						List[Any]      		=  _get_library_root_logger()
						library_root_logger.removeHandler(_default_handler   )
						library_root_logger.setLevel(logging.NOTSET   )
						a__	:						Tuple      		=  None






def       _A  (      ):
			return log_levels






def       _A  (      lowerCamelCase = None   ):

			if name is None:
						a__	:						Dict      		=  _get_library_name()

			_configure_library_root_logger()
			return logging.getLogger(snake_case__   )






def       _A  (      ):
			_configure_library_root_logger()
			return _get_library_root_logger().getEffectiveLevel()






def       _A  (      lowerCamelCase   ):
			_configure_library_root_logger()
			_get_library_root_logger().setLevel(snake_case__   )






def       _A  (      ):
			return set_verbosity(snake_case__   )






def       _A  (      ):
			return set_verbosity(snake_case__   )






def       _A  (      ):
			return set_verbosity(snake_case__   )






def       _A  (      ):
			return set_verbosity(snake_case__   )






def       _A  (      ):
			_configure_library_root_logger()

			assert _default_handler is not None
			_get_library_root_logger().removeHandler(_default_handler   )






def       _A  (      ):
			_configure_library_root_logger()

			assert _default_handler is not None
			_get_library_root_logger().addHandler(_default_handler   )






def       _A  (      lowerCamelCase   ):
			_configure_library_root_logger()

			assert handler is not None
			_get_library_root_logger().addHandler(snake_case__   )






def       _A  (      lowerCamelCase   ):
			_configure_library_root_logger()

			assert handler is not None and handler not in _get_library_root_logger().handlers
			_get_library_root_logger().removeHandler(snake_case__   )






def       _A  (      ):
			_configure_library_root_logger()
			a__	:						Union[str, Any]      		=  False






def       _A  (      ):
			_configure_library_root_logger()
			a__	:						List[Any]      		=  True






def       _A  (      ):
			a__	:						List[str]      		=  _get_library_root_logger().handlers

			for handler in handlers:
						a__	:						Tuple      		=  logging.Formatter("[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s"   )
						handler.setFormatter(snake_case__   )






def       _A  (      ):
			a__	:						Optional[int]      		=  _get_library_root_logger().handlers

			for handler in handlers:
						handler.setFormatter(snake_case__   )






def       _A  (      self							, *lowerCamelCase							, **lowerCamelCase   ):
			a__	:						str      		=  os.getenv("TRANSFORMERS_NO_ADVISORY_WARNINGS"							, snake_case__   )
			if no_advisory_warnings:
						return
			self.warning(*snake_case__							, **snake_case__   )


SCREAMING_SNAKE_CASE__       :			Optional[int]			      =						warning_advice






@functools.lru_cache(snake_case__   )
def       _A  (      self							, *lowerCamelCase							, **lowerCamelCase   ):
			self.warning(*snake_case__							, **snake_case__   )


SCREAMING_SNAKE_CASE__       :			List[Any]			      =						warning_once







class   __lowerCAmelCase			:





			def __init__( self					,			*snake_case					,			**snake_case      )				->  Dict:  # pylint: disable=unused-argument
						"""simple docstring"""





						a__	:						Union[str, Any]      		=  args[0] if args else None





			def __iter__( self      )				->  Union[str, Any]:
						"""simple docstring"""





						return iter(self._iterator      )





			def __getattr__( self					,			snake_case      )				->  str:
						"""simple docstring"""





						def empty_fn(*snake_case					,			**snake_case      ):  # pylint: disable=unused-argument
									return

						return empty_fn





			def __enter__( self      )				->  Union[str, Any]:
						"""simple docstring"""





						return self





			def __exit__( self					,			snake_case					,			snake_case					,			snake_case      )				->  Tuple:
						"""simple docstring"""





						return







class   __lowerCAmelCase			:





			def __call__( self					,			*snake_case					,			**snake_case      )				->  List[str]:
						"""simple docstring"""





						if _tqdm_active:
									return tqdm_lib.tqdm(*A_					,			**A_      )
						else:
									return EmptyTqdm(*A_					,			**A_      )





			def 	_snake_case ( self					,			*snake_case					,			**snake_case      )				->  Any:
						"""simple docstring"""





						a__	:						Tuple      		=  None
						if _tqdm_active:
									return tqdm_lib.tqdm.set_lock(*A_					,			**A_      )





			def 	_snake_case ( self      )				->  List[Any]:
						"""simple docstring"""





						if _tqdm_active:
									return tqdm_lib.tqdm.get_lock()







SCREAMING_SNAKE_CASE__       :			Union[str, Any]			      =						_tqdm_cls()






def       _A  (      ):
			global _tqdm_active
			return bool(_tqdm_active   )






def       _A  (      ):
			global _tqdm_active
			a__	:						Optional[Any]      		=  True
			hf_hub_utils.enable_progress_bars()






def       _A  (      ):
			global _tqdm_active
			a__	:						Any      		=  False
			hf_hub_utils.disable_progress_bars()








import PIL.Image
import PIL.ImageOps
from packaging import version
from PIL import Image


if version.parse(version.parse(PIL.__version__).base_version) >= version.parse("""9.1.0"""):
  SCREAMING_SNAKE_CASE__       :			int			      =						{
      """linear""": PIL.Image.Resampling.BILINEAR,
      """bilinear""": PIL.Image.Resampling.BILINEAR,
      """bicubic""": PIL.Image.Resampling.BICUBIC,
      """lanczos""": PIL.Image.Resampling.LANCZOS,
      """nearest""": PIL.Image.Resampling.NEAREST,
  }
else:
  SCREAMING_SNAKE_CASE__       :			Dict			      =						{
      """linear""": PIL.Image.LINEAR,
      """bilinear""": PIL.Image.BILINEAR,
      """bicubic""": PIL.Image.BICUBIC,
      """lanczos""": PIL.Image.LANCZOS,
      """nearest""": PIL.Image.NEAREST,
  }






def       _A  (      lowerCamelCase   ):
   a__	:						Optional[int]      		=  (images / 2 + 0.5).clamp(0							, 1   )
   a__	:						List[Any]      		=  images.cpu().permute(0							, 2							, 3							, 1   ).float().numpy()
   a__	:						int      		=  numpy_to_pil(lowerCamelCase   )
   return images






def       _A  (      lowerCamelCase   ):
   if images.ndim == 3:
      a__	:						Tuple      		=  images[None, ...]
   a__	:						Dict      		=  (images * 255).round().astype("uint8"   )
   if images.shape[-1] == 1:
      # special case for grayscale (single channel) images
      a__	:						str      		=  [Image.fromarray(image.squeeze()							, mode="L"   ) for image in images]
   else:
      a__	:						List[Any]      		=  [Image.fromarray(lowerCamelCase   ) for image in images]

   return pil_images

