


"""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


lowercase_     :   List[str]							 =       logging.get_logger(__name__)  # pylint: disable=invalid-name







class       __a	(   __snake_case       ):
				lowerCamelCase    :					int 					=['safety_checker', 'feature_extractor']







				def __init__(   self			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase = True			,  ):

					'''simple docstring'''






					super().__init__()
					if hasattr(scheduler.config			,  '''steps_offset'''      ) and scheduler.config.steps_offset != 1:
						lowerCAmelCase_			       = (
						    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'''			,  A_			,  standard_warn=A_      )
						lowerCAmelCase_			       = dict(scheduler.config      )
						lowerCAmelCase_			       = 1
						lowerCAmelCase_			       = FrozenDict(A_      )

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







				@property
				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					return {k: getattr(self			,  A_      ) for k in self.config.keys() if not k.startswith('''_'''      )}







				def     lowerCamelCase_    (   self			,  UpperCAmelCase = "auto"      ):

					'''simple docstring'''






					if slice_size == "auto":
						# half the attention head size is usually a good trade-off between
						# speed and memory
						lowerCAmelCase_			       = self.unet.config.attention_head_dim // 2
					self.unet.set_attention_slice(A_      )







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					self.enable_attention_slicing(A_      )







				@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			,  ):

					'''simple docstring'''






					return StableDiffusionInpaintPipelineLegacy(**self.components      )(
					    prompt=A_			,  image=A_			,  mask_image=A_			,  strength=A_			,  num_inference_steps=A_			,  guidance_scale=A_			,  negative_prompt=A_			,  num_images_per_prompt=A_			,  eta=A_			,  generator=A_			,  output_type=A_			,  return_dict=A_			,  callback=A_			,  )







				@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			,  ):

					'''simple docstring'''






					return StableDiffusionImgaImgPipeline(**self.components      )(
					    prompt=A_			,  image=A_			,  strength=A_			,  num_inference_steps=A_			,  guidance_scale=A_			,  negative_prompt=A_			,  num_images_per_prompt=A_			,  eta=A_			,  generator=A_			,  output_type=A_			,  return_dict=A_			,  callback=A_			,  callback_steps=A_			,  )







				@torch.no_grad()
				def     lowerCamelCase_    (   self			,  UpperCAmelCase			,  UpperCAmelCase = 512			,  UpperCAmelCase = 512			,  UpperCAmelCase = 50			,  UpperCAmelCase = 7.5			,  UpperCAmelCase = None			,  UpperCAmelCase = 1			,  UpperCAmelCase = 0.0			,  UpperCAmelCase = None			,  UpperCAmelCase = None			,  UpperCAmelCase = "pil"			,  UpperCAmelCase = True			,  UpperCAmelCase = None			,  UpperCAmelCase = 1			,  ):

					'''simple docstring'''






					return StableDiffusionPipeline(**self.components      )(
					    prompt=A_			,  height=A_			,  width=A_			,  num_inference_steps=A_			,  guidance_scale=A_			,  negative_prompt=A_			,  num_images_per_prompt=A_			,  eta=A_			,  generator=A_			,  latents=A_			,  output_type=A_			,  return_dict=A_			,  callback=A_			,  callback_steps=A_			,  )



"""simple docstring"""



lowercase_							 =       [0.485, 0.456, 0.406]
lowercase_							 =       [0.229, 0.224, 0.225]
lowercase_							 =       [0.5, 0.5, 0.5]
lowercase_							 =       [0.5, 0.5, 0.5]
lowercase_							 =       [0.4814_5466, 0.457_8275, 0.4082_1073]
lowercase_							 =       [0.2686_2954, 0.2613_0258, 0.2757_7711]