



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

import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker


_snake_case		=  "CompVis/stable-diffusion-v1-1"
_snake_case		=  "CompVis/stable-diffusion-v1-2"
_snake_case		=  "CompVis/stable-diffusion-v1-3"
_snake_case		=  "CompVis/stable-diffusion-v1-4"



class   UpperCAmelCase_    (       a):







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

														'''simple docstring'''

														super()._init_()

														_lowerCAmelCase     :							List[Any]    =    StableDiffusionPipeline.from_pretrained(__a)
														_lowerCAmelCase     :							List[Any]    =    StableDiffusionPipeline.from_pretrained(__a)
														_lowerCAmelCase     :							str    =    StableDiffusionPipeline.from_pretrained(__a)
														_lowerCAmelCase     :							str    =    StableDiffusionPipeline(
														    vae=__a,			text_encoder=__a,			tokenizer=__a,			unet=__a,			scheduler=__a,			safety_checker=__a,			feature_extractor=__a,			requires_safety_checker=__a,			)

														self.register_modules(pipelinea=self.pipea,			pipelinea=self.pipea,			pipelinea=self.pipea,			pipelinea=self.pipea)







							@property
							def    snake_case__      (   self):

														'''simple docstring'''

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







							def    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     :							Union[str, Any]    =    self.unet.config.attention_head_dim // 2
														self.unet.set_attention_slice(__a)







							def    snake_case__      (   self):

														'''simple docstring'''

														self.enable_attention_slicing(__a)







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

														'''simple docstring'''

														return self.pipea(
														    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,			**__a,			)







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

														'''simple docstring'''

														return self.pipea(
														    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,			**__a,			)







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

														'''simple docstring'''

														return self.pipea(
														    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,			**__a,			)







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

														'''simple docstring'''

														return self.pipea(
														    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,			**__a,			)







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

														'''simple docstring'''

														_lowerCAmelCase     :							Tuple    =    "cuda" if torch.cuda.is_available() else "cpu"
														self.to(__a)

														# Checks if the height and width are divisible by 8 or not
														if height % 8 != 0 or width % 8 != 0:
																					raise ValueError(f"`height` and `width` must be divisible by 8 but are {height} and {width}.")

														# Get first result from Stable Diffusion Checkpoint v1.1
														_lowerCAmelCase     :							Any    =    self.textaimg_sda_a(
														    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,			**__a,			)

														# Get first result from Stable Diffusion Checkpoint v1.2
														_lowerCAmelCase     :							int    =    self.textaimg_sda_a(
														    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,			**__a,			)

														# Get first result from Stable Diffusion Checkpoint v1.3
														_lowerCAmelCase     :							str    =    self.textaimg_sda_a(
														    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,			**__a,			)

														# Get first result from Stable Diffusion Checkpoint v1.4
														_lowerCAmelCase     :							Union[str, Any]    =    self.textaimg_sda_a(
														    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,			**__a,			)

														# Get all result images into a single list and pass it via StableDiffusionPipelineOutput for final result
														return StableDiffusionPipelineOutput([resa[0], resa[0], resa[0], resa[0]])





from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
						if not (is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.25.0")):
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						from ...utils.dummy_torch_and_transformers_objects import (
						    VersatileDiffusionDualGuidedPipeline,
						    VersatileDiffusionImageVariationPipeline,
						    VersatileDiffusionPipeline,
						    VersatileDiffusionTextToImagePipeline,
						)
else:
						from .modeling_text_unet import UNetFlatConditionModel
						from .pipeline_versatile_diffusion import VersatileDiffusionPipeline
						from .pipeline_versatile_diffusion_dual_guided import VersatileDiffusionDualGuidedPipeline
						from .pipeline_versatile_diffusion_image_variation import VersatileDiffusionImageVariationPipeline
						from .pipeline_versatile_diffusion_text_to_image import VersatileDiffusionTextToImagePipeline
