
"""simple docstring"""




from typing import Any, Callable, Dict, List, Optional, Union

import PIL.Image
import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionImgaImgPipeline,
    StableDiffusionInpaintPipelineLegacy,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.configuration_utils import FrozenDict
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
from diffusers.utils import deprecate, logging


A__   :						str 							=     logging.get_logger(__name__)  # pylint: disable=invalid-name







class 	_lowercase    (							lowerCAmelCase_					):


     '''simple docstring'''





     _A		    =				['safety_checker', 'feature_extractor']



     def __init__(   self			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase = True			,      )->       List[Any]:
          super().__init__()
          if hasattr(scheduler.config			,      "steps_offset"	) and scheduler.config.steps_offset != 1:
               UpperCAmelCase__				:			str							=    (
                   F"The configuration file of this scheduler: {scheduler} is outdated. `steps_offset`"
                   F" should be set to 1 instead of {scheduler.config.steps_offset}. Please make sure "
                   "to update the config accordingly as leaving `steps_offset` might led to incorrect results"
                   " in future versions. If you have downloaded this checkpoint from the Hugging Face Hub,"
                   " it would be very nice if you could open a Pull request for the `scheduler/scheduler_config.json`"
                   " file"
               )
               deprecate("steps_offset!=1"			,      "1.0.0"			,      __UpperCamelCase			,      standard_warn=__UpperCamelCase	)
               UpperCAmelCase__				:			int							=    dict(scheduler.config	)
               UpperCAmelCase__				:			Optional[int]							=    1
               UpperCAmelCase__				:			int							=    FrozenDict(__UpperCamelCase	)

          self.register_modules(
              vae=__UpperCamelCase			,      text_encoder=__UpperCamelCase			,      tokenizer=__UpperCamelCase			,      unet=__UpperCamelCase			,      scheduler=__UpperCamelCase			,      safety_checker=__UpperCamelCase			,      feature_extractor=__UpperCamelCase			,      )
          self.register_to_config(requires_safety_checker=__UpperCamelCase	)



     @property
     def 			lowerCAmelCase__							(   self	)->       Dict[str, Any]:
          return {k: getattr(self			,      __UpperCamelCase	) for k in self.config.keys() if not k.startswith("_"	)}



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase = "auto"	)->       Dict:
          if slice_size == "auto":
               # half the attention head size is usually a good trade-off between
               # speed and memory
               UpperCAmelCase__				:			List[Any]							=    self.unet.config.attention_head_dim // 2
          self.unet.set_attention_slice(__UpperCamelCase	)



     def 			lowerCAmelCase__							(   self	)->       int:
          self.enable_attention_slicing(__UpperCamelCase	)



     @torch.no_grad()
     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase = 0.8			,      __UpperCamelCase = 50			,      __UpperCamelCase = 7.5			,      __UpperCamelCase = None			,      __UpperCamelCase = 1			,      __UpperCamelCase = 0.0			,      __UpperCamelCase = None			,      __UpperCamelCase = "pil"			,      __UpperCamelCase = True			,      __UpperCamelCase = None			,      __UpperCamelCase = 1			,      )->       Tuple:
          # For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
          return StableDiffusionInpaintPipelineLegacy(**self.components	)(
              prompt=__UpperCamelCase			,      image=__UpperCamelCase			,      mask_image=__UpperCamelCase			,      strength=__UpperCamelCase			,      num_inference_steps=__UpperCamelCase			,      guidance_scale=__UpperCamelCase			,      negative_prompt=__UpperCamelCase			,      num_images_per_prompt=__UpperCamelCase			,      eta=__UpperCamelCase			,      generator=__UpperCamelCase			,      output_type=__UpperCamelCase			,      return_dict=__UpperCamelCase			,      callback=__UpperCamelCase			,      )



     @torch.no_grad()
     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase = 0.8			,      __UpperCamelCase = 50			,      __UpperCamelCase = 7.5			,      __UpperCamelCase = None			,      __UpperCamelCase = 1			,      __UpperCamelCase = 0.0			,      __UpperCamelCase = None			,      __UpperCamelCase = "pil"			,      __UpperCamelCase = True			,      __UpperCamelCase = None			,      __UpperCamelCase = 1			,      **__UpperCamelCase			,      )->       Optional[Any]:
          # For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
          return StableDiffusionImgaImgPipeline(**self.components	)(
              prompt=__UpperCamelCase			,      image=__UpperCamelCase			,      strength=__UpperCamelCase			,      num_inference_steps=__UpperCamelCase			,      guidance_scale=__UpperCamelCase			,      negative_prompt=__UpperCamelCase			,      num_images_per_prompt=__UpperCamelCase			,      eta=__UpperCamelCase			,      generator=__UpperCamelCase			,      output_type=__UpperCamelCase			,      return_dict=__UpperCamelCase			,      callback=__UpperCamelCase			,      callback_steps=__UpperCamelCase			,      )



     @torch.no_grad()
     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase			,      __UpperCamelCase = 5_12			,      __UpperCamelCase = 5_12			,      __UpperCamelCase = 50			,      __UpperCamelCase = 7.5			,      __UpperCamelCase = None			,      __UpperCamelCase = 1			,      __UpperCamelCase = 0.0			,      __UpperCamelCase = None			,      __UpperCamelCase = None			,      __UpperCamelCase = "pil"			,      __UpperCamelCase = True			,      __UpperCamelCase = None			,      __UpperCamelCase = 1			,      )->       Union[str, Any]:
          # For more information on how this function https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionPipeline
          return StableDiffusionPipeline(**self.components	)(
              prompt=__UpperCamelCase			,      height=__UpperCamelCase			,      width=__UpperCamelCase			,      num_inference_steps=__UpperCamelCase			,      guidance_scale=__UpperCamelCase			,      negative_prompt=__UpperCamelCase			,      num_images_per_prompt=__UpperCamelCase			,      eta=__UpperCamelCase			,      generator=__UpperCamelCase			,      latents=__UpperCamelCase			,      output_type=__UpperCamelCase			,      return_dict=__UpperCamelCase			,      callback=__UpperCamelCase			,      callback_steps=__UpperCamelCase			,      )





"""simple docstring"""




import enum
import inspect
import warnings
from functools import wraps
from typing import Callable, Optional

from .logging import get_logger


A__   :						Optional[Any] 							=     set()
A__   :						List[str] 							=     get_logger(__name__)



def 				a__			(					lowerCAmelCase						:							Optional[str] = None		):






     '''simple docstring'''

     def decorator(lowerCAmelCase						:							Callable		):
          global _emitted_deprecation_warnings

          if inspect.isclass(lowerCAmelCase		):
               UpperCAmelCase__				:			Any							=    deprecated_class_or_function.__init__
               UpperCAmelCase__				:			Optional[int]							=    deprecated_class_or_function.__name__
          else:
               UpperCAmelCase__				:			str							=    deprecated_class_or_function
               UpperCAmelCase__				:			List[Any]							=    deprecated_function.__name__
               # Support deprecating __init__ class method: class name instead
               UpperCAmelCase__				:			List[str]							=    name if name != "__init__" else deprecated_function.__qualname__.split("."		)[-2]

          UpperCAmelCase__				:			Optional[Any]							=    (
              F"{name} is deprecated and will be removed in the next major version of datasets." + F" {help_message}"
              if help_message
              else ""
          )

          @wraps(lowerCAmelCase		)
          def wrapper(*lowerCAmelCase						:							int							,     **lowerCAmelCase						:							str		):
               UpperCAmelCase__				:			List[str]							=    hash(lowerCAmelCase		)
               if func_hash not in _emitted_deprecation_warnings:
                    warnings.warn(lowerCAmelCase							,     category=lowerCAmelCase							,     stacklevel=2		)
                    _emitted_deprecation_warnings.add(lowerCAmelCase		)
               return deprecated_function(*lowerCAmelCase							,     **lowerCAmelCase		)

          UpperCAmelCase__				:			List[str]							=    "deprecated"

          if inspect.isclass(lowerCAmelCase		):
               UpperCAmelCase__				:			List[str]							=    wrapper
               return deprecated_class_or_function
          else:
               return wrapper

     return decorator







class 	_lowercase    (							enum.EnumMeta					):


     '''simple docstring'''





     def __getattribute__(   cls			,      __UpperCamelCase	)->       Optional[Any]:
          UpperCAmelCase__				:			Optional[int]							=    super().__getattribute__(__UpperCamelCase	)
          if isinstance(__UpperCamelCase			,      enum.Enum	) and obj._on_access:
               obj._on_access()
          return obj



     def __getitem__(   cls			,      __UpperCamelCase	)->       Optional[int]:
          UpperCAmelCase__				:			Union[str, Any]							=    super().__getitem__(__UpperCamelCase	)
          if member._on_access:
               member._on_access()
          return member



     def __call__(   cls			,      __UpperCamelCase			,      __UpperCamelCase=None			,      *, __UpperCamelCase=None			,      __UpperCamelCase=None			,      __UpperCamelCase=None			,      __UpperCamelCase=1	)->       Dict:
          UpperCAmelCase__				:			Optional[int]							=    super().__call__(__UpperCamelCase			,      __UpperCamelCase			,      module=__UpperCamelCase			,      qualname=__UpperCamelCase			,      type=__UpperCamelCase			,      start=__UpperCamelCase	)
          if isinstance(__UpperCamelCase			,      enum.Enum	) and obj._on_access:
               obj._on_access()
          return obj







class 	_lowercase    (							enum.Enum						, metaclass=lowerCAmelCase_					):


     '''simple docstring'''





     def __new__(   cls			,      __UpperCamelCase	)->       Union[str, Any]:
          UpperCAmelCase__				:			int							=    object.__new__(cls	)
          UpperCAmelCase__				:			int							=    value
          UpperCAmelCase__				:			Optional[int]							=    member.deprecate
          return member



     @property
     def 			lowerCAmelCase__							(   self	)->       Union[str, Any]:
          return ""



     def 			lowerCAmelCase__							(   self	)->       int:
          UpperCAmelCase__				:			Tuple							=    F" {self.help_message}" if self.help_message else ""
          warnings.warn(
              F"'{self.__objclass__.__name__}' is deprecated and will be removed in the next major version of datasets."
              + help_message			,      __UpperCamelCase			,      stacklevel=3			,      )



