




UpperCamelCase__            =     [0.485, 0.456, 0.406]
UpperCamelCase__            =     [0.229, 0.224, 0.225]
UpperCamelCase__            =     [0.5, 0.5, 0.5]
UpperCamelCase__            =     [0.5, 0.5, 0.5]
UpperCamelCase__            =     [0.48145466, 0.4578275, 0.40821073]
UpperCamelCase__            =     [0.26862954, 0.26130258, 0.27577711]










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


UpperCamelCase__            =     logging.get_logger(__name__)  # pylint: disable=invalid-name
class      a__       (   snake_case__ ):
						_a				:       Tuple   =       ["""safety_checker""", """feature_extractor"""]






						def __init__(  self						,     _A						,     _A						,     _A						,     _A						,     _A						,     _A						,     _A						,     _A = 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 							__SCREAMING_SNAKE_CASE(  self     ):




											"""simple docstring"""



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






						def 							__SCREAMING_SNAKE_CASE(  self						,     _A = "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 							__SCREAMING_SNAKE_CASE(  self     ):




											"""simple docstring"""



											self.enable_attention_slicing(_A     )






						@torch.no_grad()
						def 							__SCREAMING_SNAKE_CASE(  self						,     _A						,     _A						,     _A						,     _A = 0.8						,     _A = 5_0						,     _A = 7.5						,     _A = None						,     _A = 1						,     _A = 0.0						,     _A = None						,     _A = "pil"						,     _A = True						,     _A = None						,     _A = 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 							__SCREAMING_SNAKE_CASE(  self						,     _A						,     _A						,     _A = 0.8						,     _A = 5_0						,     _A = 7.5						,     _A = None						,     _A = 1						,     _A = 0.0						,     _A = None						,     _A = "pil"						,     _A = True						,     _A = None						,     _A = 1						,     **_A						,     ):




											"""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 							__SCREAMING_SNAKE_CASE(  self						,     _A						,     _A = 5_1_2						,     _A = 5_1_2						,     _A = 5_0						,     _A = 7.5						,     _A = None						,     _A = 1						,     _A = 0.0						,     _A = None						,     _A = None						,     _A = "pil"						,     _A = True						,     _A = None						,     _A = 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						,     )




