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  __magic_name__  (		__a    ):





   """simple docstring"""




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



    """simple docstring"""



    super()._init_()

    _UpperCamelCase:     Optional[int]							= StableDiffusionPipeline.from_pretrained(_lowercase							)
    _UpperCamelCase:     Union[str, Any]							= StableDiffusionPipeline.from_pretrained(_lowercase							)
    _UpperCamelCase:     List[Any]							= StableDiffusionPipeline.from_pretrained(_lowercase							)
    _UpperCamelCase:     Optional[int]							= StableDiffusionPipeline(
        vae=_lowercase		,  text_encoder=_lowercase		,  tokenizer=_lowercase		,  unet=_lowercase		,  scheduler=_lowercase		,  safety_checker=_lowercase		,  feature_extractor=_lowercase		,  requires_safety_checker=_lowercase		,  )

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



   @property
   def   lowerCAmelCase						(	self					:  Dict							):



    """simple docstring"""



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



   def   lowerCAmelCase						(	self					:  List[str]		,  _lowercase					:  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
     _UpperCamelCase:     Dict							= self.unet.config.attention_head_dim // 2
    self.unet.set_attention_slice(_lowercase							)



   def   lowerCAmelCase						(	self					:  Tuple							):



    """simple docstring"""



    self.enable_attention_slicing(_lowercase							)



   @torch.no_grad()
   def   lowerCAmelCase						(	self					:  Dict		,  _lowercase					:  Union[str, List[str]]		,  _lowercase					:  int = 512		,  _lowercase					:  int = 512		,  _lowercase					:  int = 50		,  _lowercase					:  float = 7.5		,  _lowercase					:  Optional[Union[str, List[str]]] = None		,  _lowercase					:  Optional[int] = 1		,  _lowercase					:  float = 0.0		,  _lowercase					:  Optional[torch.Generator] = None		,  _lowercase					:  Optional[torch.FloatTensor] = None		,  _lowercase					:  Optional[str] = "pil"		,  _lowercase					:  bool = True		,  _lowercase					:  Optional[Callable[[int, int, torch.FloatTensor], None]] = None		,  _lowercase					:  int = 1		,  **_lowercase					:  Tuple		,  ):



    """simple docstring"""



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



   @torch.no_grad()
   def   lowerCAmelCase						(	self					:  Tuple		,  _lowercase					:  Union[str, List[str]]		,  _lowercase					:  int = 512		,  _lowercase					:  int = 512		,  _lowercase					:  int = 50		,  _lowercase					:  float = 7.5		,  _lowercase					:  Optional[Union[str, List[str]]] = None		,  _lowercase					:  Optional[int] = 1		,  _lowercase					:  float = 0.0		,  _lowercase					:  Optional[torch.Generator] = None		,  _lowercase					:  Optional[torch.FloatTensor] = None		,  _lowercase					:  Optional[str] = "pil"		,  _lowercase					:  bool = True		,  _lowercase					:  Optional[Callable[[int, int, torch.FloatTensor], None]] = None		,  _lowercase					:  int = 1		,  **_lowercase					:  Optional[int]		,  ):



    """simple docstring"""



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



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



    """simple docstring"""



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



   @torch.no_grad()
   def   lowerCAmelCase						(	self					:  Tuple		,  _lowercase					:  Union[str, List[str]]		,  _lowercase					:  int = 512		,  _lowercase					:  int = 512		,  _lowercase					:  int = 50		,  _lowercase					:  float = 7.5		,  _lowercase					:  Optional[Union[str, List[str]]] = None		,  _lowercase					:  Optional[int] = 1		,  _lowercase					:  float = 0.0		,  _lowercase					:  Optional[torch.Generator] = None		,  _lowercase					:  Optional[torch.FloatTensor] = None		,  _lowercase					:  Optional[str] = "pil"		,  _lowercase					:  bool = True		,  _lowercase					:  Optional[Callable[[int, int, torch.FloatTensor], None]] = None		,  _lowercase					:  int = 1		,  **_lowercase					:  Dict		,  ):



    """simple docstring"""



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



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



    """simple docstring"""



    _UpperCamelCase:     List[Any]							= '''cuda''' if torch.cuda.is_available() else '''cpu'''
    self.to(_lowercase							)

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

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

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

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

    # 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]]							)
def       lowerCAmelCase_     (		lowercase:							float		)    ->				float:







 '''simple docstring'''

 if edge <= 0 or not isinstance(lowercase  ,					lowercase		):
  raise ValueError('''Length must be a positive.'''		)
 return 3 * ((25 + 10 * (5 ** (1 / 2))) ** (1 / 2)) * (edge**2)




def       lowerCAmelCase_     (		lowercase:							float		)    ->				float:







 '''simple docstring'''

 if edge <= 0 or not isinstance(lowercase  ,					lowercase		):
  raise ValueError('''Length must be a positive.'''		)
 return ((15 + (7 * (5 ** (1 / 2)))) / 4) * (edge**3)


if __name__ == "__main__":
  import doctest

  doctest.testmod()