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


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




class     a__      (   UpperCAmelCase__ ):






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





         """simple docstring"""



         super()._init_()

         __lowerCamelCase		=  StableDiffusionPipeline.from_pretrained(a    )
         __lowerCamelCase		=  StableDiffusionPipeline.from_pretrained(a    )
         __lowerCamelCase		=  StableDiffusionPipeline.from_pretrained(a    )
         __lowerCamelCase		=  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    SCREAMING_SNAKE_CASE__   ( self		:		Dict    ):





         """simple docstring"""



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






     def    SCREAMING_SNAKE_CASE__   ( self		:		List[Any]  ,				a		:		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
             __lowerCamelCase		=  self.unet.config.attention_head_dim // 2
         self.unet.set_attention_slice(a    )






     def    SCREAMING_SNAKE_CASE__   ( self		:		List[Any]    ):





         """simple docstring"""



         self.enable_attention_slicing(a    )






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





         """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    SCREAMING_SNAKE_CASE__   ( self		:		List[str]  ,				a		:		Union[str, List[str]]  ,				a		:		int = 5_12  ,				a		:		int = 5_12  ,				a		:		int = 50  ,				a		:		float = 7.5  ,				a		:		Optional[Union[str, List[str]]] = None  ,				a		:		Optional[int] = 1  ,				a		:		float = 0.0  ,				a		:		Optional[torch.Generator] = None  ,				a		:		Optional[torch.FloatTensor] = None  ,				a		:		Optional[str] = "pil"  ,				a		:		bool = True  ,				a		:		Optional[Callable[[int, int, torch.FloatTensor], None]] = None  ,				a		:		int = 1  ,				**a		:		Tuple  ,				):





         """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    SCREAMING_SNAKE_CASE__   ( self		:		List[str]  ,				a		:		Union[str, List[str]]  ,				a		:		int = 5_12  ,				a		:		int = 5_12  ,				a		:		int = 50  ,				a		:		float = 7.5  ,				a		:		Optional[Union[str, List[str]]] = None  ,				a		:		Optional[int] = 1  ,				a		:		float = 0.0  ,				a		:		Optional[torch.Generator] = None  ,				a		:		Optional[torch.FloatTensor] = None  ,				a		:		Optional[str] = "pil"  ,				a		:		bool = True  ,				a		:		Optional[Callable[[int, int, torch.FloatTensor], None]] = None  ,				a		:		int = 1  ,				**a		:		str  ,				):





         """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    SCREAMING_SNAKE_CASE__   ( self		:		Optional[Any]  ,				a		:		Union[str, List[str]]  ,				a		:		int = 5_12  ,				a		:		int = 5_12  ,				a		:		int = 50  ,				a		:		float = 7.5  ,				a		:		Optional[Union[str, List[str]]] = None  ,				a		:		Optional[int] = 1  ,				a		:		float = 0.0  ,				a		:		Optional[torch.Generator] = None  ,				a		:		Optional[torch.FloatTensor] = None  ,				a		:		Optional[str] = "pil"  ,				a		:		bool = True  ,				a		:		Optional[Callable[[int, int, torch.FloatTensor], None]] = None  ,				a		:		int = 1  ,				**a		:		Tuple  ,				):





         """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    SCREAMING_SNAKE_CASE__   ( self		:		Optional[int]  ,				a		:		Union[str, List[str]]  ,				a		:		int = 5_12  ,				a		:		int = 5_12  ,				a		:		int = 50  ,				a		:		float = 7.5  ,				a		:		Optional[Union[str, List[str]]] = None  ,				a		:		Optional[int] = 1  ,				a		:		float = 0.0  ,				a		:		Optional[torch.Generator] = None  ,				a		:		Optional[torch.FloatTensor] = None  ,				a		:		Optional[str] = "pil"  ,				a		:		bool = True  ,				a		:		Optional[Callable[[int, int, torch.FloatTensor], None]] = None  ,				a		:		int = 1  ,				**a		:		str  ,				):





         """simple docstring"""



         __lowerCamelCase		=  '''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		=  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		=  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		=  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		=  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]]    )


_lowerCamelCase					   ={
    "joule": 1.0,
    "kilojoule": 1_0_0_0,
    "megajoule": 1_0_0_0_0_0_0,
    "gigajoule": 1_0_0_0_0_0_0_0_0_0,
    "wattsecond": 1.0,
    "watthour": 3_6_0_0,
    "kilowatthour": 3_6_0_0_0_0_0,
    "newtonmeter": 1.0,
    "calorie_nutr": 4_1_8_6.8,
    "kilocalorie_nutr": 4_1_8_6_8_0_0.0_0,
    "electronvolt": 1.6_0_2_1_7_6_6_3_4E-1_9,
    "britishthermalunit_it": 1_0_5_5.0_5_5_8_5,
    "footpound": 1.355818,
}





def     _a					(						lowerCamelCase,	lowerCamelCase,	lowerCamelCase							):
 if to_type not in ENERGY_CONVERSION or from_type not in ENERGY_CONVERSION:
  lowerCamelCase		:	Dict							=      (
      F'''Incorrect \'from_type\' or \'to_type\' value: {from_type!r}, {to_type!r}\n'''
      F'''Valid values are: {", ".join(lowerCamelCase							)}'''
  )
  raise ValueError(lowerCamelCase							)
 return value * ENERGY_CONVERSION[from_type] / ENERGY_CONVERSION[to_type]


if __name__ == "__main__":
      import doctest

      doctest.testmod()




