






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 		lowercase_					(	lowercase   ):






      '''simple docstring'''




      def __init__(      self      :						Tuple ,					__UpperCAmelCase      :						AutoencoderKL ,					__UpperCAmelCase      :						CLIPTextModel ,					__UpperCAmelCase      :						CLIPTokenizer ,					__UpperCAmelCase      :						UNetaDConditionModel ,					__UpperCAmelCase      :						Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler] ,					__UpperCAmelCase      :						StableDiffusionSafetyChecker ,					__UpperCAmelCase      :						CLIPImageProcessor ,					__UpperCAmelCase      :						bool = True ,					)    ->List[str]:




       """simple docstring"""


       super()._init_()

       a		  =      StableDiffusionPipeline.from_pretrained(__UpperCAmelCase  )
       a		  =      StableDiffusionPipeline.from_pretrained(__UpperCAmelCase  )
       a		  =      StableDiffusionPipeline.from_pretrained(__UpperCAmelCase  )
       a		  =      StableDiffusionPipeline(
           vae=__UpperCAmelCase ,					text_encoder=__UpperCAmelCase ,					tokenizer=__UpperCAmelCase ,					unet=__UpperCAmelCase ,					scheduler=__UpperCAmelCase ,					safety_checker=__UpperCAmelCase ,					feature_extractor=__UpperCAmelCase ,					requires_safety_checker=__UpperCAmelCase ,					)

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







      @property
      def       __lowerCAmelCase					(      self      :						str  )    ->Dict[str, Any]:




       """simple docstring"""


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







      def       __lowerCAmelCase					(      self      :						str ,					__UpperCAmelCase      :						Optional[Union[str, int]] = "auto"  )    ->int:




       """simple docstring"""


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







      def       __lowerCAmelCase					(      self      :						Optional[int]  )    ->Tuple:




       """simple docstring"""


       self.enable_attention_slicing(__UpperCAmelCase  )







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




       """simple docstring"""


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







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




       """simple docstring"""


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







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




       """simple docstring"""


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







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




       """simple docstring"""


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







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




       """simple docstring"""


       a		  =      '''cuda''' if torch.cuda.is_available() else '''cpu'''
       self.to(__UpperCAmelCase  )

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

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

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

       # Get first result from Stable Diffusion Checkpoint v1.4
       a		  =      self.textaimg_sda_a(
           prompt=__UpperCAmelCase ,					height=__UpperCAmelCase ,					width=__UpperCAmelCase ,					num_inference_steps=__UpperCAmelCase ,					guidance_scale=__UpperCAmelCase ,					negative_prompt=__UpperCAmelCase ,					num_images_per_prompt=__UpperCAmelCase ,					eta=__UpperCAmelCase ,					generator=__UpperCAmelCase ,					latents=__UpperCAmelCase ,					output_type=__UpperCAmelCase ,					return_dict=__UpperCAmelCase ,					callback=__UpperCAmelCase ,					callback_steps=__UpperCAmelCase ,					**__UpperCAmelCase ,					)

       # 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 						_a    (      a :int )							->			bool:
 a		  =      n ** (1 / 3)
 return (val * val * val) == n


if __name__ == "__main__":
     print(perfect_cube(27))
     print(perfect_cube(4))


