
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

from tqdm import auto as tqdm_lib


__UpperCAmelCase   						=     threading.Lock()
__UpperCAmelCase   						=     None

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

__UpperCAmelCase   						=     logging.WARNING

__UpperCAmelCase   						=     True


def  A__ (       ):
   SCREAMING_SNAKE_CASE_	=      os.getenv('''DIFFUSERS_VERBOSITY''',  _SCREAMING_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 DIFFUSERS_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
      SCREAMING_SNAKE_CASE_	=      logging.StreamHandler()  # Set sys.stderr as stream.
      SCREAMING_SNAKE_CASE_	=      sys.stderr.flush

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


def  A__ (       ):
   global _default_handler

   with _lock:
      if not _default_handler:
         return

      SCREAMING_SNAKE_CASE_	=      _get_library_root_logger()
      library_root_logger.removeHandler(_default_handler						)
      library_root_logger.setLevel(logging.NOTSET						)
      SCREAMING_SNAKE_CASE_	=      None


def  A__ (       ):
   return log_levels


def  A__ (       __lowerCamelCase = None						):


   if name is None:
      SCREAMING_SNAKE_CASE_	=      _get_library_name()

   _configure_library_root_logger()
   return logging.getLogger(_SCREAMING_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(_SCREAMING_SNAKE_CASE						)


def  A__ (       ):
   return set_verbosity(_SCREAMING_SNAKE_CASE						)


def  A__ (       ):
   return set_verbosity(_SCREAMING_SNAKE_CASE						)


def  A__ (       ):
   return set_verbosity(_SCREAMING_SNAKE_CASE						)


def  A__ (       ):
   return set_verbosity(_SCREAMING_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(_SCREAMING_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(_SCREAMING_SNAKE_CASE						)


def  A__ (       ):
   _configure_library_root_logger()
   SCREAMING_SNAKE_CASE_	=      False


def  A__ (       ):
   _configure_library_root_logger()
   SCREAMING_SNAKE_CASE_	=      True


def  A__ (       ):
   SCREAMING_SNAKE_CASE_	=      _get_library_root_logger().handlers

   for handler in handlers:
      SCREAMING_SNAKE_CASE_	=      logging.Formatter('''[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s'''						)
      handler.setFormatter(_SCREAMING_SNAKE_CASE						)


def  A__ (       ):
   SCREAMING_SNAKE_CASE_	=      _get_library_root_logger().handlers

   for handler in handlers:
      handler.setFormatter(_SCREAMING_SNAKE_CASE						)


def  A__ (       self,  *__lowerCamelCase,  **__lowerCamelCase						):
   SCREAMING_SNAKE_CASE_	=      os.getenv('''DIFFUSERS_NO_ADVISORY_WARNINGS''',  _SCREAMING_SNAKE_CASE						)
   if no_advisory_warnings:
      return
   self.warning(*_SCREAMING_SNAKE_CASE,  **_SCREAMING_SNAKE_CASE						)


__UpperCAmelCase   						=     warning_advice





class 				UpperCamelCase__		:






       """simple docstring"""


       def __init__(							self ,     *_A ,     **_A	)				->				str:  # pylint: disable=unused-argument
          SCREAMING_SNAKE_CASE_	=      args[0] if args else None



       def __iter__(							self	)				->				Union[str, Any]:
          return iter(self._iterator	)



       def __getattr__(							self ,     _A	)				->				List[str]:

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

          return empty_fn



       def __enter__(							self	)				->				List[str]:
          return self




       def __exit__(							self ,     _A ,     _A ,     _A	)				->				Union[str, Any]:
          return







class 				UpperCamelCase__		:






       """simple docstring"""


       def __call__(							self ,     *_A ,     **_A	)				->				int:
          if _tqdm_active:
             return tqdm_lib.tqdm(*_A ,     **_A	)
          else:
             return EmptyTqdm(*_A ,     **_A	)



       def     _UpperCamelCase	(							self ,     *_A ,     **_A	)				->				Dict:
          SCREAMING_SNAKE_CASE_	=      None
          if _tqdm_active:
             return tqdm_lib.tqdm.set_lock(*_A ,     **_A	)




       def     _UpperCamelCase	(							self	)				->				Optional[Any]:
          if _tqdm_active:
             return tqdm_lib.tqdm.get_lock()







__UpperCAmelCase   						=     _tqdm_cls()


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


def  A__ (       ):
   global _tqdm_active
   SCREAMING_SNAKE_CASE_	=      True





def  A__ (       ):
   global _tqdm_active
   SCREAMING_SNAKE_CASE_	=      False





from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


UpperCamelCase__	:   Union[str, Any]								=     logging.get_logger(__name__)



class    __snake_case	(     lowerCAmelCase__							):
  __lowerCAmelCase  :						Tuple    			=	['pixel_values']

  def __init__(       self    ,		_A = True    ,		_A = None    ,		_A = PILImageResampling.BILINEAR    ,		_A = True    ,		_A = 1 / 255    ,		_A = True    ,		_A = None    ,		_A = None    ,		**_A    ,		):
      super().__init__(**_A)
      SCREAMING_SNAKE_CASE_						=    size if size is not None else {'height': 224, 'width': 224}
      SCREAMING_SNAKE_CASE_						=    get_size_dict(_A)
      SCREAMING_SNAKE_CASE_						=    do_resize
      SCREAMING_SNAKE_CASE_						=    do_rescale
      SCREAMING_SNAKE_CASE_						=    do_normalize
      SCREAMING_SNAKE_CASE_						=    size
      SCREAMING_SNAKE_CASE_						=    resample
      SCREAMING_SNAKE_CASE_						=    rescale_factor
      SCREAMING_SNAKE_CASE_						=    image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
      SCREAMING_SNAKE_CASE_						=    image_std if image_std is not None else IMAGENET_STANDARD_STD

  def     lowerCAmelCase__  (       self    ,		_A    ,		_A    ,		_A = PILImageResampling.BILINEAR    ,		_A = None    ,		**_A    ,		):
      SCREAMING_SNAKE_CASE_						=    get_size_dict(_A)
      if "height" not in size or "width" not in size:
          raise ValueError(f"""The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}""")
      return resize(
          _A    ,		size=(size['height'], size['width'])    ,		resample=_A    ,		data_format=_A    ,		**_A)

  def     lowerCAmelCase__  (       self    ,		_A    ,		_A    ,		_A = None    ,		**_A):
      return rescale(_A    ,		scale=_A    ,		data_format=_A    ,		**_A)

  def     lowerCAmelCase__  (       self    ,		_A    ,		_A    ,		_A    ,		_A = None    ,		**_A    ,		):
      return normalize(_A    ,		mean=_A    ,		std=_A    ,		data_format=_A    ,		**_A)


  def     lowerCAmelCase__  (       self    ,		_A    ,		_A = None    ,		_A = None    ,		_A = None    ,		_A = None    ,		_A = None    ,		_A = None    ,		_A = None    ,		_A = None    ,		_A = None    ,		_A = ChannelDimension.FIRST    ,		**_A    ,		):
      SCREAMING_SNAKE_CASE_						=    do_resize if do_resize is not None else self.do_resize
      SCREAMING_SNAKE_CASE_						=    do_rescale if do_rescale is not None else self.do_rescale
      SCREAMING_SNAKE_CASE_						=    do_normalize if do_normalize is not None else self.do_normalize
      SCREAMING_SNAKE_CASE_						=    resample if resample is not None else self.resample
      SCREAMING_SNAKE_CASE_						=    rescale_factor if rescale_factor is not None else self.rescale_factor
      SCREAMING_SNAKE_CASE_						=    image_mean if image_mean is not None else self.image_mean
      SCREAMING_SNAKE_CASE_						=    image_std if image_std is not None else self.image_std

      SCREAMING_SNAKE_CASE_						=    size if size is not None else self.size
      SCREAMING_SNAKE_CASE_						=    get_size_dict(_A)

      SCREAMING_SNAKE_CASE_						=    make_list_of_images(_A)

      if not valid_images(_A):
          raise ValueError(
              'Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '
              'torch.Tensor, tf.Tensor or jax.ndarray.')

      if do_resize and size is None:
          raise ValueError('Size must be specified if do_resize is True.')

      if do_rescale and rescale_factor is None:
          raise ValueError('Rescale factor must be specified if do_rescale is True.')

      # All transformations expect numpy arrays.
      SCREAMING_SNAKE_CASE_						=    [to_numpy_array(_A) for image in images]

      if do_resize:
          SCREAMING_SNAKE_CASE_						=    [self.resize(image=_A    ,		size=_A    ,		resample=_A) for image in images]

      if do_rescale:
          SCREAMING_SNAKE_CASE_						=    [self.rescale(image=_A    ,		scale=_A) for image in images]

      if do_normalize:
          SCREAMING_SNAKE_CASE_						=    [self.normalize(image=_A    ,		mean=_A    ,		std=_A) for image in images]

      SCREAMING_SNAKE_CASE_						=    [to_channel_dimension_format(_A    ,		_A) for image in images]

      SCREAMING_SNAKE_CASE_						=    {'pixel_values': images}
      return BatchFeature(data=_A    ,		tensor_type=_A)


