


"""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    :     Optional[Any]   						=		'CompVis/stable-diffusion-v1-1'
UpperCAmelCase    :     Dict   						=		'CompVis/stable-diffusion-v1-2'
UpperCAmelCase    :     Optional[int]   						=		'CompVis/stable-diffusion-v1-3'
UpperCAmelCase    :     Union[str, Any]   						=		'CompVis/stable-diffusion-v1-4'





class      lowerCamelCase__   (     lowerCamelCase_				):







					"""simple docstring"""


					def __init__(       self    : Union[str, Any] ,       UpperCamelCase    : Any ,       UpperCamelCase    : Union[str, Any] ,       UpperCamelCase    : str ,       UpperCamelCase    : Dict ,       UpperCamelCase    : List[Any] ,       UpperCamelCase    : Optional[int] ,       UpperCamelCase    : Dict ,       UpperCamelCase    : Tuple = True ,       ):
												'''simple docstring'''






												super()._init_()

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

												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 ,       lowerCAmelCase__  ) for k in self.config.keys() if not k.startswith("""_"""  )}






					def lowerCamelCase__							(       self    : Optional[Any] ,       UpperCamelCase    : Optional[int] = "auto"  ):
												'''simple docstring'''






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






					def lowerCamelCase__							(       self    : int  ):
												'''simple docstring'''






												self.enable_attention_slicing(lowerCAmelCase__  )






					@torch.no_grad()
					def lowerCamelCase__							(       self    : int ,       UpperCamelCase    : Optional[int] ,       UpperCamelCase    : Optional[int] = 512 ,       UpperCamelCase    : Dict = 512 ,       UpperCamelCase    : int = 50 ,       UpperCamelCase    : Any = 7.5 ,       UpperCamelCase    : Dict = None ,       UpperCamelCase    : Any = 1 ,       UpperCamelCase    : str = 0.0 ,       UpperCamelCase    : List[str] = None ,       UpperCamelCase    : List[str] = None ,       UpperCamelCase    : int = "pil" ,       UpperCamelCase    : Any = True ,       UpperCamelCase    : str = None ,       UpperCamelCase    : Dict = 1 ,       **UpperCamelCase    : str ,       ):
												'''simple docstring'''






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






					@torch.no_grad()
					def lowerCamelCase__							(       self    : List[str] ,       UpperCamelCase    : int ,       UpperCamelCase    : Dict = 512 ,       UpperCamelCase    : str = 512 ,       UpperCamelCase    : Union[str, Any] = 50 ,       UpperCamelCase    : Optional[Any] = 7.5 ,       UpperCamelCase    : Dict = None ,       UpperCamelCase    : Tuple = 1 ,       UpperCamelCase    : int = 0.0 ,       UpperCamelCase    : Optional[int] = None ,       UpperCamelCase    : Optional[Any] = None ,       UpperCamelCase    : Optional[int] = "pil" ,       UpperCamelCase    : Optional[Any] = True ,       UpperCamelCase    : Union[str, Any] = None ,       UpperCamelCase    : str = 1 ,       **UpperCamelCase    : Union[str, Any] ,       ):
												'''simple docstring'''






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






					@torch.no_grad()
					def lowerCamelCase__							(       self    : Any ,       UpperCamelCase    : str ,       UpperCamelCase    : List[Any] = 512 ,       UpperCamelCase    : Dict = 512 ,       UpperCamelCase    : Union[str, Any] = 50 ,       UpperCamelCase    : int = 7.5 ,       UpperCamelCase    : Tuple = None ,       UpperCamelCase    : Dict = 1 ,       UpperCamelCase    : str = 0.0 ,       UpperCamelCase    : Union[str, Any] = None ,       UpperCamelCase    : int = None ,       UpperCamelCase    : Union[str, Any] = "pil" ,       UpperCamelCase    : str = True ,       UpperCamelCase    : Tuple = None ,       UpperCamelCase    : List[Any] = 1 ,       **UpperCamelCase    : Tuple ,       ):
												'''simple docstring'''






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






					@torch.no_grad()
					def lowerCamelCase__							(       self    : int ,       UpperCamelCase    : Dict ,       UpperCamelCase    : Optional[int] = 512 ,       UpperCamelCase    : str = 512 ,       UpperCamelCase    : Optional[Any] = 50 ,       UpperCamelCase    : Optional[Any] = 7.5 ,       UpperCamelCase    : Dict = None ,       UpperCamelCase    : str = 1 ,       UpperCamelCase    : Any = 0.0 ,       UpperCamelCase    : List[Any] = None ,       UpperCamelCase    : List[Any] = None ,       UpperCamelCase    : Dict = "pil" ,       UpperCamelCase    : Union[str, Any] = True ,       UpperCamelCase    : Dict = None ,       UpperCamelCase    : Any = 1 ,       **UpperCamelCase    : Any ,       ):
												'''simple docstring'''






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






					@torch.no_grad()
					def lowerCamelCase__							(       self    : Optional[Any] ,       UpperCamelCase    : Optional[int] ,       UpperCamelCase    : Union[str, Any] = 512 ,       UpperCamelCase    : str = 512 ,       UpperCamelCase    : Any = 50 ,       UpperCamelCase    : List[Any] = 7.5 ,       UpperCamelCase    : List[str] = None ,       UpperCamelCase    : Union[str, Any] = 1 ,       UpperCamelCase    : Optional[Any] = 0.0 ,       UpperCamelCase    : Dict = None ,       UpperCamelCase    : str = None ,       UpperCamelCase    : Optional[int] = "pil" ,       UpperCamelCase    : List[Any] = True ,       UpperCamelCase    : Tuple = None ,       UpperCamelCase    : Optional[Any] = 1 ,       **UpperCamelCase    : List[Any] ,       ):
												'''simple docstring'''






												__UpperCAmelCase   :						str      							=					"""cuda""" if torch.cuda.is_available() else """cpu"""
												self.to(lowerCAmelCase__  )

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

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

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

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

												# 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"""




__UpperCamelCase						=      frozenset(
    [
        '''prompt''',
        '''height''',
        '''width''',
        '''guidance_scale''',
        '''negative_prompt''',
        '''prompt_embeds''',
        '''negative_prompt_embeds''',
        '''cross_attention_kwargs''',
    ]
)

__UpperCamelCase						=      frozenset(['''prompt''', '''negative_prompt'''])

__UpperCamelCase						=      frozenset([])

__UpperCamelCase						=      frozenset(['''image'''])

__UpperCamelCase						=      frozenset(
    [
        '''image''',
        '''height''',
        '''width''',
        '''guidance_scale''',
    ]
)

__UpperCamelCase						=      frozenset(['''image'''])

__UpperCamelCase						=      frozenset(
    [
        '''prompt''',
        '''image''',
        '''height''',
        '''width''',
        '''guidance_scale''',
        '''negative_prompt''',
        '''prompt_embeds''',
        '''negative_prompt_embeds''',
    ]
)

__UpperCamelCase						=      frozenset(['''prompt''', '''image''', '''negative_prompt'''])

__UpperCamelCase						=      frozenset(
    [
        # Text guided image variation with an image mask
        '''prompt''',
        '''image''',
        '''mask_image''',
        '''height''',
        '''width''',
        '''guidance_scale''',
        '''negative_prompt''',
        '''prompt_embeds''',
        '''negative_prompt_embeds''',
    ]
)

__UpperCamelCase						=      frozenset(['''prompt''', '''image''', '''mask_image''', '''negative_prompt'''])

__UpperCamelCase						=      frozenset(
    [
        # image variation with an image mask
        '''image''',
        '''mask_image''',
        '''height''',
        '''width''',
        '''guidance_scale''',
    ]
)

__UpperCamelCase						=      frozenset(['''image''', '''mask_image'''])

__UpperCamelCase						=      frozenset(
    [
        '''example_image''',
        '''image''',
        '''mask_image''',
        '''height''',
        '''width''',
        '''guidance_scale''',
    ]
)

__UpperCamelCase						=      frozenset(['''example_image''', '''image''', '''mask_image'''])

__UpperCamelCase						=      frozenset(['''class_labels'''])

__UpperCamelCase						=      frozenset(['''class_labels'''])

__UpperCamelCase						=      frozenset(['''batch_size'''])

__UpperCamelCase						=      frozenset([])

__UpperCamelCase						=      frozenset(['''batch_size'''])

__UpperCamelCase						=      frozenset([])

__UpperCamelCase						=      frozenset(
    [
        '''prompt''',
        '''audio_length_in_s''',
        '''guidance_scale''',
        '''negative_prompt''',
        '''prompt_embeds''',
        '''negative_prompt_embeds''',
        '''cross_attention_kwargs''',
    ]
)

__UpperCamelCase						=      frozenset(['''prompt''', '''negative_prompt'''])
__UpperCamelCase						=      frozenset(['''input_tokens'''])

__UpperCamelCase						=      frozenset(['''input_tokens'''])


