





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__						:			Union[str, Any]									='''CompVis/stable-diffusion-v1-1'''
UpperCAmelCase__						:			str									='''CompVis/stable-diffusion-v1-2'''
UpperCAmelCase__						:			List[str]									='''CompVis/stable-diffusion-v1-3'''
UpperCAmelCase__						:			Dict									='''CompVis/stable-diffusion-v1-4'''

class       __A     (						a    ):


				def __init__(		self   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_ = True   , ):
								super()._init_()

								lowerCamelCase	 =StableDiffusionPipeline.from_pretrained(UpperCAmelCase_							)
								lowerCamelCase	 =StableDiffusionPipeline.from_pretrained(UpperCAmelCase_							)
								lowerCamelCase	 =StableDiffusionPipeline.from_pretrained(UpperCAmelCase_							)
								lowerCamelCase	 =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 _snake_case       (		self							):
								return {k: getattr(self   , UpperCAmelCase_							) for k in self.config.keys() if not k.startswith("""_"""							)}


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


				def _snake_case       (		self							):
								self.enable_attention_slicing(UpperCAmelCase_							)


				@torch.no_grad()
				def _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_ = 512   , UpperCAmelCase_ = 512   , UpperCAmelCase_ = 50   , UpperCAmelCase_ = 7.5   , UpperCAmelCase_ = None   , UpperCAmelCase_ = 1   , UpperCAmelCase_ = 0.0   , UpperCAmelCase_ = None   , UpperCAmelCase_ = None   , UpperCAmelCase_ = "pil"   , UpperCAmelCase_ = True   , UpperCAmelCase_ = None   , UpperCAmelCase_ = 1   , **UpperCAmelCase_   , ):
								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 _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_ = 512   , UpperCAmelCase_ = 512   , UpperCAmelCase_ = 50   , UpperCAmelCase_ = 7.5   , UpperCAmelCase_ = None   , UpperCAmelCase_ = 1   , UpperCAmelCase_ = 0.0   , UpperCAmelCase_ = None   , UpperCAmelCase_ = None   , UpperCAmelCase_ = "pil"   , UpperCAmelCase_ = True   , UpperCAmelCase_ = None   , UpperCAmelCase_ = 1   , **UpperCAmelCase_   , ):
								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 _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_ = 512   , UpperCAmelCase_ = 512   , UpperCAmelCase_ = 50   , UpperCAmelCase_ = 7.5   , UpperCAmelCase_ = None   , UpperCAmelCase_ = 1   , UpperCAmelCase_ = 0.0   , UpperCAmelCase_ = None   , UpperCAmelCase_ = None   , UpperCAmelCase_ = "pil"   , UpperCAmelCase_ = True   , UpperCAmelCase_ = None   , UpperCAmelCase_ = 1   , **UpperCAmelCase_   , ):
								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 _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_ = 512   , UpperCAmelCase_ = 512   , UpperCAmelCase_ = 50   , UpperCAmelCase_ = 7.5   , UpperCAmelCase_ = None   , UpperCAmelCase_ = 1   , UpperCAmelCase_ = 0.0   , UpperCAmelCase_ = None   , UpperCAmelCase_ = None   , UpperCAmelCase_ = "pil"   , UpperCAmelCase_ = True   , UpperCAmelCase_ = None   , UpperCAmelCase_ = 1   , **UpperCAmelCase_   , ):
								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 _snake_case       (		self   , UpperCAmelCase_   , UpperCAmelCase_ = 512   , UpperCAmelCase_ = 512   , UpperCAmelCase_ = 50   , UpperCAmelCase_ = 7.5   , UpperCAmelCase_ = None   , UpperCAmelCase_ = 1   , UpperCAmelCase_ = 0.0   , UpperCAmelCase_ = None   , UpperCAmelCase_ = None   , UpperCAmelCase_ = "pil"   , UpperCAmelCase_ = True   , UpperCAmelCase_ = None   , UpperCAmelCase_ = 1   , **UpperCAmelCase_   , ):
								lowerCamelCase	 ="""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
								lowerCamelCase	 =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
								lowerCamelCase	 =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
								lowerCamelCase	 =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
								lowerCamelCase	 =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]]							)












from abc import ABC, abstractmethod
from argparse import ArgumentParser

class       __A     (						a    ):


				@staticmethod
				@abstractmethod
				def _snake_case       (		UpperCAmelCase_							):
								raise NotImplementedError()


				@abstractmethod
				def _snake_case       (		self							):
								raise NotImplementedError()





