


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


A   :					Dict	=      "CompVis/stable-diffusion-v1-1"
A   :					Optional[Any]	=      "CompVis/stable-diffusion-v1-2"
A   :					int	=      "CompVis/stable-diffusion-v1-3"
A   :					Tuple	=      "CompVis/stable-diffusion-v1-4"







class     _lowercase				(							__a):


       """simple docstring"""




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


             '''simple docstring'''



             super()._init_()

             lowerCamelCase__	:       Tuple					=						StableDiffusionPipeline.from_pretrained(a_ )
             lowerCamelCase__	:       int					=						StableDiffusionPipeline.from_pretrained(a_ )
             lowerCamelCase__	:       Any					=						StableDiffusionPipeline.from_pretrained(a_ )
             lowerCamelCase__	:       Any					=						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 		lowerCAmelCase  (     self							:    Optional[int] ):


             '''simple docstring'''



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





       def 		lowerCAmelCase  (     self							:    str      ,   __lowerCamelCase							:    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__	:       Optional[int]					=						self.unet.config.attention_head_dim // 2
             self.unet.set_attention_slice(a_ )





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


             '''simple docstring'''



             self.enable_attention_slicing(a_ )





       @torch.no_grad()
       def 		lowerCAmelCase  (     self							:    Union[str, Any]      ,   __lowerCamelCase							:    Union[str, List[str]]      ,   __lowerCamelCase							:    int = 512      ,   __lowerCamelCase							:    int = 512      ,   __lowerCamelCase							:    int = 50      ,   __lowerCamelCase							:    float = 7.5      ,   __lowerCamelCase							:    Optional[Union[str, List[str]]] = None      ,   __lowerCamelCase							:    Optional[int] = 1      ,   __lowerCamelCase							:    float = 0.0      ,   __lowerCamelCase							:    Optional[torch.Generator] = None      ,   __lowerCamelCase							:    Optional[torch.FloatTensor] = None      ,   __lowerCamelCase							:    Optional[str] = "pil"      ,   __lowerCamelCase							:    bool = True      ,   __lowerCamelCase							:    Optional[Callable[[int, int, torch.FloatTensor], None]] = None      ,   __lowerCamelCase							:    int = 1      ,   **__lowerCamelCase							:    List[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 		lowerCAmelCase  (     self							:    List[Any]      ,   __lowerCamelCase							:    Union[str, List[str]]      ,   __lowerCamelCase							:    int = 512      ,   __lowerCamelCase							:    int = 512      ,   __lowerCamelCase							:    int = 50      ,   __lowerCamelCase							:    float = 7.5      ,   __lowerCamelCase							:    Optional[Union[str, List[str]]] = None      ,   __lowerCamelCase							:    Optional[int] = 1      ,   __lowerCamelCase							:    float = 0.0      ,   __lowerCamelCase							:    Optional[torch.Generator] = None      ,   __lowerCamelCase							:    Optional[torch.FloatTensor] = None      ,   __lowerCamelCase							:    Optional[str] = "pil"      ,   __lowerCamelCase							:    bool = True      ,   __lowerCamelCase							:    Optional[Callable[[int, int, torch.FloatTensor], None]] = None      ,   __lowerCamelCase							:    int = 1      ,   **__lowerCamelCase							:    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 		lowerCAmelCase  (     self							:    Dict      ,   __lowerCamelCase							:    Union[str, List[str]]      ,   __lowerCamelCase							:    int = 512      ,   __lowerCamelCase							:    int = 512      ,   __lowerCamelCase							:    int = 50      ,   __lowerCamelCase							:    float = 7.5      ,   __lowerCamelCase							:    Optional[Union[str, List[str]]] = None      ,   __lowerCamelCase							:    Optional[int] = 1      ,   __lowerCamelCase							:    float = 0.0      ,   __lowerCamelCase							:    Optional[torch.Generator] = None      ,   __lowerCamelCase							:    Optional[torch.FloatTensor] = None      ,   __lowerCamelCase							:    Optional[str] = "pil"      ,   __lowerCamelCase							:    bool = True      ,   __lowerCamelCase							:    Optional[Callable[[int, int, torch.FloatTensor], None]] = None      ,   __lowerCamelCase							:    int = 1      ,   **__lowerCamelCase							:    Optional[int]      ,   ):


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


             '''simple docstring'''



             lowerCamelCase__	:       int					=						"""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__	:       Dict					=						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__	:       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.3
             lowerCamelCase__	:       Optional[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.4
             lowerCamelCase__	:       Optional[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 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    lowercase_	(	_A    :					int		):

      """simple docstring"""




      if not isinstance(_A					,      _A		):
            lowerCamelCase__	:       List[str]					=						F"Input value of [number={number}] must be an integer"
            raise TypeError(_A		)
      if number < 0:
            return False
      lowerCamelCase__	:       Dict					=						number * number
      while number > 0:
            if number % 10 != number_square % 10:
                  return False
            number //= 10
            number_square //= 10
      return True


if __name__ == "__main__":
    import doctest

    doctest.testmod()


