

'''simple docstring'''


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


lowerCAmelCase__						:       int										=						"""CompVis/stable-diffusion-v1-1"""
lowerCAmelCase__						:       Any										=						"""CompVis/stable-diffusion-v1-2"""
lowerCAmelCase__						:       Dict										=						"""CompVis/stable-diffusion-v1-3"""
lowerCAmelCase__						:       Any										=						"""CompVis/stable-diffusion-v1-4"""




class     a			(				SCREAMING_SNAKE_CASE       ):






						"""simple docstring"""




						def __init__(							self					:      Optional[Any]			,			snake_case_					:      AutoencoderKL			,			snake_case_					:      CLIPTextModel			,			snake_case_					:      CLIPTokenizer			,			snake_case_					:      UNetaDConditionModel			,			snake_case_					:      Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]			,			snake_case_					:      StableDiffusionSafetyChecker			,			snake_case_					:      CLIPImageProcessor			,			snake_case_					:      bool = True			,			):



								'''simple docstring'''



								super()._init_()

								snake_case__						:       Union[str, Any]       						=  StableDiffusionPipeline.from_pretrained(snake_case_  )
								snake_case__						:       Dict       						=  StableDiffusionPipeline.from_pretrained(snake_case_  )
								snake_case__						:       List[Any]       						=  StableDiffusionPipeline.from_pretrained(snake_case_  )
								snake_case__						:       List[Any]       						=  StableDiffusionPipeline(
								    vae=snake_case_			,			text_encoder=snake_case_			,			tokenizer=snake_case_			,			unet=snake_case_			,			scheduler=snake_case_			,			safety_checker=snake_case_			,			feature_extractor=snake_case_			,			requires_safety_checker=snake_case_			,			)

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







						@property
						def       __magic_name__							(							self					:      Tuple  ):



								'''simple docstring'''



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







						def       __magic_name__							(							self					:      List[Any]			,			snake_case_					:      Optional[Union[str, int]] = "auto"  ):



								'''simple docstring'''



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







						def       __magic_name__							(							self					:      Union[str, Any]  ):



								'''simple docstring'''



								self.enable_attention_slicing(snake_case_  )







						@torch.no_grad()
						def       __magic_name__							(							self					:      Optional[Any]			,			snake_case_					:      Union[str, List[str]]			,			snake_case_					:      int = 5_1_2			,			snake_case_					:      int = 5_1_2			,			snake_case_					:      int = 5_0			,			snake_case_					:      float = 7.5			,			snake_case_					:      Optional[Union[str, List[str]]] = None			,			snake_case_					:      Optional[int] = 1			,			snake_case_					:      float = 0.0			,			snake_case_					:      Optional[torch.Generator] = None			,			snake_case_					:      Optional[torch.FloatTensor] = None			,			snake_case_					:      Optional[str] = "pil"			,			snake_case_					:      bool = True			,			snake_case_					:      Optional[Callable[[int, int, torch.FloatTensor], None]] = None			,			snake_case_					:      int = 1			,			**snake_case_					:      str			,			):



								'''simple docstring'''



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







						@torch.no_grad()
						def       __magic_name__							(							self					:      Union[str, Any]			,			snake_case_					:      Union[str, List[str]]			,			snake_case_					:      int = 5_1_2			,			snake_case_					:      int = 5_1_2			,			snake_case_					:      int = 5_0			,			snake_case_					:      float = 7.5			,			snake_case_					:      Optional[Union[str, List[str]]] = None			,			snake_case_					:      Optional[int] = 1			,			snake_case_					:      float = 0.0			,			snake_case_					:      Optional[torch.Generator] = None			,			snake_case_					:      Optional[torch.FloatTensor] = None			,			snake_case_					:      Optional[str] = "pil"			,			snake_case_					:      bool = True			,			snake_case_					:      Optional[Callable[[int, int, torch.FloatTensor], None]] = None			,			snake_case_					:      int = 1			,			**snake_case_					:      Tuple			,			):



								'''simple docstring'''



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







						@torch.no_grad()
						def       __magic_name__							(							self					:      Union[str, Any]			,			snake_case_					:      Union[str, List[str]]			,			snake_case_					:      int = 5_1_2			,			snake_case_					:      int = 5_1_2			,			snake_case_					:      int = 5_0			,			snake_case_					:      float = 7.5			,			snake_case_					:      Optional[Union[str, List[str]]] = None			,			snake_case_					:      Optional[int] = 1			,			snake_case_					:      float = 0.0			,			snake_case_					:      Optional[torch.Generator] = None			,			snake_case_					:      Optional[torch.FloatTensor] = None			,			snake_case_					:      Optional[str] = "pil"			,			snake_case_					:      bool = True			,			snake_case_					:      Optional[Callable[[int, int, torch.FloatTensor], None]] = None			,			snake_case_					:      int = 1			,			**snake_case_					:      Tuple			,			):



								'''simple docstring'''



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







						@torch.no_grad()
						def       __magic_name__							(							self					:      List[Any]			,			snake_case_					:      Union[str, List[str]]			,			snake_case_					:      int = 5_1_2			,			snake_case_					:      int = 5_1_2			,			snake_case_					:      int = 5_0			,			snake_case_					:      float = 7.5			,			snake_case_					:      Optional[Union[str, List[str]]] = None			,			snake_case_					:      Optional[int] = 1			,			snake_case_					:      float = 0.0			,			snake_case_					:      Optional[torch.Generator] = None			,			snake_case_					:      Optional[torch.FloatTensor] = None			,			snake_case_					:      Optional[str] = "pil"			,			snake_case_					:      bool = True			,			snake_case_					:      Optional[Callable[[int, int, torch.FloatTensor], None]] = None			,			snake_case_					:      int = 1			,			**snake_case_					:      Tuple			,			):



								'''simple docstring'''



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







						@torch.no_grad()
						def       __magic_name__							(							self					:      Union[str, Any]			,			snake_case_					:      Union[str, List[str]]			,			snake_case_					:      int = 5_1_2			,			snake_case_					:      int = 5_1_2			,			snake_case_					:      int = 5_0			,			snake_case_					:      float = 7.5			,			snake_case_					:      Optional[Union[str, List[str]]] = None			,			snake_case_					:      Optional[int] = 1			,			snake_case_					:      float = 0.0			,			snake_case_					:      Optional[torch.Generator] = None			,			snake_case_					:      Optional[torch.FloatTensor] = None			,			snake_case_					:      Optional[str] = "pil"			,			snake_case_					:      bool = True			,			snake_case_					:      Optional[Callable[[int, int, torch.FloatTensor], None]] = None			,			snake_case_					:      int = 1			,			**snake_case_					:      List[Any]			,			):



								'''simple docstring'''



								snake_case__						:       Dict       						=  '''cuda''' if torch.cuda.is_available() else '''cpu'''
								self.to(snake_case_  )

								# 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
								snake_case__						:       Tuple       						=  self.textaimg_sda_a(
								    prompt=snake_case_			,			height=snake_case_			,			width=snake_case_			,			num_inference_steps=snake_case_			,			guidance_scale=snake_case_			,			negative_prompt=snake_case_			,			num_images_per_prompt=snake_case_			,			eta=snake_case_			,			generator=snake_case_			,			latents=snake_case_			,			output_type=snake_case_			,			return_dict=snake_case_			,			callback=snake_case_			,			callback_steps=snake_case_			,			**snake_case_			,			)

								# Get first result from Stable Diffusion Checkpoint v1.2
								snake_case__						:       Tuple       						=  self.textaimg_sda_a(
								    prompt=snake_case_			,			height=snake_case_			,			width=snake_case_			,			num_inference_steps=snake_case_			,			guidance_scale=snake_case_			,			negative_prompt=snake_case_			,			num_images_per_prompt=snake_case_			,			eta=snake_case_			,			generator=snake_case_			,			latents=snake_case_			,			output_type=snake_case_			,			return_dict=snake_case_			,			callback=snake_case_			,			callback_steps=snake_case_			,			**snake_case_			,			)

								# Get first result from Stable Diffusion Checkpoint v1.3
								snake_case__						:       Optional[int]       						=  self.textaimg_sda_a(
								    prompt=snake_case_			,			height=snake_case_			,			width=snake_case_			,			num_inference_steps=snake_case_			,			guidance_scale=snake_case_			,			negative_prompt=snake_case_			,			num_images_per_prompt=snake_case_			,			eta=snake_case_			,			generator=snake_case_			,			latents=snake_case_			,			output_type=snake_case_			,			return_dict=snake_case_			,			callback=snake_case_			,			callback_steps=snake_case_			,			**snake_case_			,			)

								# Get first result from Stable Diffusion Checkpoint v1.4
								snake_case__						:       List[Any]       						=  self.textaimg_sda_a(
								    prompt=snake_case_			,			height=snake_case_			,			width=snake_case_			,			num_inference_steps=snake_case_			,			guidance_scale=snake_case_			,			negative_prompt=snake_case_			,			num_images_per_prompt=snake_case_			,			eta=snake_case_			,			generator=snake_case_			,			latents=snake_case_			,			output_type=snake_case_			,			return_dict=snake_case_			,			callback=snake_case_			,			callback_steps=snake_case_			,			**snake_case_			,			)

								# 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]]  )






'''simple docstring'''


import warnings

from diffusers import StableDiffusionImgaImgPipeline  # noqa F401


warnings.warn(
    """The `image_to_image.py` script is outdated. Please use directly `from diffusers import"""
    """ StableDiffusionImg2ImgPipeline` instead."""
)



