





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



class    A__  (			__snake_case     ):





      def __init__(					self			,				A_			,				A_			,				A_			,				A_			,				A_			,				A_			,				A_			,				A_ = True			,				):
       '''simple docstring'''




       super()._init_()

       UpperCamelCase      :   Optional[Any]			      =  StableDiffusionPipeline.from_pretrained(A_  )
       UpperCamelCase      :   Dict			      =  StableDiffusionPipeline.from_pretrained(A_  )
       UpperCamelCase      :   Any			      =  StableDiffusionPipeline.from_pretrained(A_  )
       UpperCamelCase      :   Tuple			      =  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 			__UpperCamelCase(					self  ):
       '''simple docstring'''




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





      def 			__UpperCamelCase(					self			,				A_ = "auto"  ):
       '''simple docstring'''




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





      def 			__UpperCamelCase(					self  ):
       '''simple docstring'''




       self.enable_attention_slicing(A_  )





      @torch.no_grad()
      def 			__UpperCamelCase(					self			,				A_			,				A_ = 512			,				A_ = 512			,				A_ = 50			,				A_ = 7.5			,				A_ = None			,				A_ = 1			,				A_ = 0.0			,				A_ = None			,				A_ = None			,				A_ = "pil"			,				A_ = True			,				A_ = None			,				A_ = 1			,				**A_			,				):
       '''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 			__UpperCamelCase(					self			,				A_			,				A_ = 512			,				A_ = 512			,				A_ = 50			,				A_ = 7.5			,				A_ = None			,				A_ = 1			,				A_ = 0.0			,				A_ = None			,				A_ = None			,				A_ = "pil"			,				A_ = True			,				A_ = None			,				A_ = 1			,				**A_			,				):
       '''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 			__UpperCamelCase(					self			,				A_			,				A_ = 512			,				A_ = 512			,				A_ = 50			,				A_ = 7.5			,				A_ = None			,				A_ = 1			,				A_ = 0.0			,				A_ = None			,				A_ = None			,				A_ = "pil"			,				A_ = True			,				A_ = None			,				A_ = 1			,				**A_			,				):
       '''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 			__UpperCamelCase(					self			,				A_			,				A_ = 512			,				A_ = 512			,				A_ = 50			,				A_ = 7.5			,				A_ = None			,				A_ = 1			,				A_ = 0.0			,				A_ = None			,				A_ = None			,				A_ = "pil"			,				A_ = True			,				A_ = None			,				A_ = 1			,				**A_			,				):
       '''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 			__UpperCamelCase(					self			,				A_			,				A_ = 512			,				A_ = 512			,				A_ = 50			,				A_ = 7.5			,				A_ = None			,				A_ = 1			,				A_ = 0.0			,				A_ = None			,				A_ = None			,				A_ = "pil"			,				A_ = True			,				A_ = None			,				A_ = 1			,				**A_			,				):
       '''simple docstring'''




       UpperCamelCase      :   Optional[Any]			      =  "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
       UpperCamelCase      :   List[Any]			      =  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
       UpperCamelCase      :   Any			      =  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
       UpperCamelCase      :   List[Any]			      =  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
       UpperCamelCase      :   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 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 typing import Any



def 						A_							(	_lowerCAmelCase	)		->					list[Any]:
 if not input_list:
  return []
 UpperCamelCase      :   List[str]			      =  [input_list.count(_lowerCAmelCase	) for value in input_list]
 UpperCamelCase      :   Dict			      =  max(_lowerCAmelCase	)  # Gets the maximum count in the input list.
 # Gets values of modes
 return sorted({input_list[i] for i, value in enumerate(_lowerCAmelCase	) if value == y}	)


if __name__ == "__main__":
    import doctest

    doctest.testmod()
