



'''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	 =       """CompVis/stable-diffusion-v1-1"""
lowerCamelCase	 =       """CompVis/stable-diffusion-v1-2"""
lowerCamelCase	 =       """CompVis/stable-diffusion-v1-3"""
lowerCamelCase	 =       """CompVis/stable-diffusion-v1-4"""





class _UpperCamelCase		(     __lowercase		):





    '''simple docstring'''





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







           '''simple docstring'''

           super()._init_()

           __lowercase       	=StableDiffusionPipeline.from_pretrained(_A)
           __lowercase       	=StableDiffusionPipeline.from_pretrained(_A)
           __lowercase       	=StableDiffusionPipeline.from_pretrained(_A)
           __lowercase       	=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[Any]):







           '''simple docstring'''

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

    def 				__lowerCamelCase     (							self  :  List[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
                  __lowercase       	=self.unet.config.attention_head_dim // 2
           self.unet.set_attention_slice(_A)

    def 				__lowerCamelCase     (							self  :  Any):







           '''simple docstring'''

           self.enable_attention_slicing(_A)

    @torch.no_grad()
    def 				__lowerCamelCase     (							self  :  Optional[Any]  ,       _lowerCAmelCase  :  Union[str, List[str]]  ,       _lowerCAmelCase  :  int = 5_1_2  ,       _lowerCAmelCase  :  int = 5_1_2  ,       _lowerCAmelCase  :  int = 5_0  ,       _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  :  Dict  ,       ):







           '''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 = 5_1_2  ,       _lowerCAmelCase  :  int = 5_1_2  ,       _lowerCAmelCase  :  int = 5_0  ,       _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[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  :  List[str]  ,       _lowerCAmelCase  :  Union[str, List[str]]  ,       _lowerCAmelCase  :  int = 5_1_2  ,       _lowerCAmelCase  :  int = 5_1_2  ,       _lowerCAmelCase  :  int = 5_0  ,       _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[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 = 5_1_2  ,       _lowerCAmelCase  :  int = 5_1_2  ,       _lowerCAmelCase  :  int = 5_0  ,       _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  :  Dict  ,       _lowerCAmelCase  :  Union[str, List[str]]  ,       _lowerCAmelCase  :  int = 5_1_2  ,       _lowerCAmelCase  :  int = 5_1_2  ,       _lowerCAmelCase  :  int = 5_0  ,       _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[Any]  ,       ):







           '''simple docstring'''

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








'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import _LazyModule


lowerCamelCase	 =       {"""tokenization_bertweet""": ["""BertweetTokenizer"""]}


if TYPE_CHECKING:
		from .tokenization_bertweet import BertweetTokenizer

else:
		import sys

		lowerCamelCase	 =       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



