

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







class  lowercase				(       lowercase_			):




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

											snake_case_							=    StableDiffusionPipeline.from_pretrained(snake_case       )
											snake_case_							=    StableDiffusionPipeline.from_pretrained(snake_case       )
											snake_case_							=    StableDiffusionPipeline.from_pretrained(snake_case       )
											snake_case_							=    StableDiffusionPipeline(
											    vae=snake_case      ,   text_encoder=snake_case      ,   tokenizer=snake_case      ,   unet=snake_case      ,   scheduler=snake_case      ,   safety_checker=snake_case      ,   feature_extractor=snake_case      ,   requires_safety_checker=snake_case      ,   )

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




				@property
				def     a							(					self       ):
											return {k: getattr(self      ,   snake_case       ) for k in self.config.keys() if not k.startswith('_'       )}




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




				def     a							(					self       ):
											self.enable_attention_slicing(snake_case       )




				@torch.no_grad()
				def     a							(					self      ,   snake_case      ,   snake_case = 512      ,   snake_case = 512      ,   snake_case = 50      ,   snake_case = 7.5      ,   snake_case = None      ,   snake_case = 1      ,   snake_case = 0.0      ,   snake_case = None      ,   snake_case = None      ,   snake_case = "pil"      ,   snake_case = True      ,   snake_case = None      ,   snake_case = 1      ,   **snake_case      ,   ):
											return self.pipea(
											    prompt=snake_case      ,   height=snake_case      ,   width=snake_case      ,   num_inference_steps=snake_case      ,   guidance_scale=snake_case      ,   negative_prompt=snake_case      ,   num_images_per_prompt=snake_case      ,   eta=snake_case      ,   generator=snake_case      ,   latents=snake_case      ,   output_type=snake_case      ,   return_dict=snake_case      ,   callback=snake_case      ,   callback_steps=snake_case      ,   **snake_case      ,   )




				@torch.no_grad()
				def     a							(					self      ,   snake_case      ,   snake_case = 512      ,   snake_case = 512      ,   snake_case = 50      ,   snake_case = 7.5      ,   snake_case = None      ,   snake_case = 1      ,   snake_case = 0.0      ,   snake_case = None      ,   snake_case = None      ,   snake_case = "pil"      ,   snake_case = True      ,   snake_case = None      ,   snake_case = 1      ,   **snake_case      ,   ):
											return self.pipea(
											    prompt=snake_case      ,   height=snake_case      ,   width=snake_case      ,   num_inference_steps=snake_case      ,   guidance_scale=snake_case      ,   negative_prompt=snake_case      ,   num_images_per_prompt=snake_case      ,   eta=snake_case      ,   generator=snake_case      ,   latents=snake_case      ,   output_type=snake_case      ,   return_dict=snake_case      ,   callback=snake_case      ,   callback_steps=snake_case      ,   **snake_case      ,   )




				@torch.no_grad()
				def     a							(					self      ,   snake_case      ,   snake_case = 512      ,   snake_case = 512      ,   snake_case = 50      ,   snake_case = 7.5      ,   snake_case = None      ,   snake_case = 1      ,   snake_case = 0.0      ,   snake_case = None      ,   snake_case = None      ,   snake_case = "pil"      ,   snake_case = True      ,   snake_case = None      ,   snake_case = 1      ,   **snake_case      ,   ):
											return self.pipea(
											    prompt=snake_case      ,   height=snake_case      ,   width=snake_case      ,   num_inference_steps=snake_case      ,   guidance_scale=snake_case      ,   negative_prompt=snake_case      ,   num_images_per_prompt=snake_case      ,   eta=snake_case      ,   generator=snake_case      ,   latents=snake_case      ,   output_type=snake_case      ,   return_dict=snake_case      ,   callback=snake_case      ,   callback_steps=snake_case      ,   **snake_case      ,   )




				@torch.no_grad()
				def     a							(					self      ,   snake_case      ,   snake_case = 512      ,   snake_case = 512      ,   snake_case = 50      ,   snake_case = 7.5      ,   snake_case = None      ,   snake_case = 1      ,   snake_case = 0.0      ,   snake_case = None      ,   snake_case = None      ,   snake_case = "pil"      ,   snake_case = True      ,   snake_case = None      ,   snake_case = 1      ,   **snake_case      ,   ):
											return self.pipea(
											    prompt=snake_case      ,   height=snake_case      ,   width=snake_case      ,   num_inference_steps=snake_case      ,   guidance_scale=snake_case      ,   negative_prompt=snake_case      ,   num_images_per_prompt=snake_case      ,   eta=snake_case      ,   generator=snake_case      ,   latents=snake_case      ,   output_type=snake_case      ,   return_dict=snake_case      ,   callback=snake_case      ,   callback_steps=snake_case      ,   **snake_case      ,   )




				@torch.no_grad()
				def     a							(					self      ,   snake_case      ,   snake_case = 512      ,   snake_case = 512      ,   snake_case = 50      ,   snake_case = 7.5      ,   snake_case = None      ,   snake_case = 1      ,   snake_case = 0.0      ,   snake_case = None      ,   snake_case = None      ,   snake_case = "pil"      ,   snake_case = True      ,   snake_case = None      ,   snake_case = 1      ,   **snake_case      ,   ):
											snake_case_							=    'cuda' if torch.cuda.is_available() else 'cpu'
											self.to(snake_case       )

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

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

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

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

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




				@staticmethod
				@abstractmethod
				def     a							(					snake_case       ):
											raise NotImplementedError()




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




