


'''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


__A					:  str											=      "CompVis/stable-diffusion-v1-1"
__A					:  Tuple											=      "CompVis/stable-diffusion-v1-2"
__A					:  List[str]											=      "CompVis/stable-diffusion-v1-3"
__A					:  Union[str, Any]											=      "CompVis/stable-diffusion-v1-4"






class    __snake_case       (   _SCREAMING_SNAKE_CASE):







    """simple docstring"""



    def __init__(   self    :  Optional[int]    ,						lowerCamelCase    :  AutoencoderKL    ,						lowerCamelCase    :  CLIPTextModel    ,						lowerCamelCase    :  CLIPTokenizer    ,						lowerCamelCase    :  UNetaDConditionModel    ,						lowerCamelCase    :  Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]    ,						lowerCamelCase    :  StableDiffusionSafetyChecker    ,						lowerCamelCase    :  CLIPImageProcessor    ,						lowerCamelCase    :  bool = True    ,						)   ->  Union[str, Any]:
      super()._init_()

      lowerCAmelCase_			:      List[str]			=   StableDiffusionPipeline.from_pretrained(lowerCamelCase		)
      lowerCAmelCase_			:      Optional[Any]			=   StableDiffusionPipeline.from_pretrained(lowerCamelCase		)
      lowerCAmelCase_			:      Dict			=   StableDiffusionPipeline.from_pretrained(lowerCamelCase		)
      lowerCAmelCase_			:      List[Any]			=   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 __lowercase   (   self    :  List[Any]		)   ->  Dict[str, Any]:
      return {k: getattr(self    ,						lowerCamelCase		) for k in self.config.keys() if not k.startswith("""_"""		)}

    def __lowercase   (   self    :  List[str]    ,						lowerCamelCase    :  Optional[Union[str, int]] = "auto"		)   ->  Optional[Any]:
      if slice_size == "auto":
        # half the attention head size is usually a good trade-off between
        # speed and memory
        lowerCAmelCase_			:      Dict			=   self.unet.config.attention_head_dim // 2
      self.unet.set_attention_slice(lowerCamelCase		)

    def __lowercase   (   self    :  Union[str, Any]		)   ->  List[str]:
      self.enable_attention_slicing(lowerCamelCase		)

    @torch.no_grad()
    def __lowercase   (   self    :  List[Any]    ,						lowerCamelCase    :  Union[str, List[str]]    ,						lowerCamelCase    :  int = 5_12    ,						lowerCamelCase    :  int = 5_12    ,						lowerCamelCase    :  int = 50    ,						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    :  Union[str, Any]    ,						)   ->  int:
      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 __lowercase   (   self    :  Optional[int]    ,						lowerCamelCase    :  Union[str, List[str]]    ,						lowerCamelCase    :  int = 5_12    ,						lowerCamelCase    :  int = 5_12    ,						lowerCamelCase    :  int = 50    ,						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    ,						)   ->  Tuple:
      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 __lowercase   (   self    :  Any    ,						lowerCamelCase    :  Union[str, List[str]]    ,						lowerCamelCase    :  int = 5_12    ,						lowerCamelCase    :  int = 5_12    ,						lowerCamelCase    :  int = 50    ,						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    :  Any    ,						)   ->  Optional[int]:
      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 __lowercase   (   self    :  str    ,						lowerCamelCase    :  Union[str, List[str]]    ,						lowerCamelCase    :  int = 5_12    ,						lowerCamelCase    :  int = 5_12    ,						lowerCamelCase    :  int = 50    ,						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[str]    ,						)   ->  str:
      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 __lowercase   (   self    :  str    ,						lowerCamelCase    :  Union[str, List[str]]    ,						lowerCamelCase    :  int = 5_12    ,						lowerCamelCase    :  int = 5_12    ,						lowerCamelCase    :  int = 50    ,						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    :  int    ,						)   ->  int:
      lowerCAmelCase_			:      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
      lowerCAmelCase_			:      Union[str, 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
      lowerCAmelCase_			:      Union[str, 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.3
      lowerCAmelCase_			:      Optional[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.4
      lowerCAmelCase_			:      Union[str, 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 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 statistics import mean, stdev







def 				UpperCamelCase_			(    A__					:   list							,    A__					:   int = 3					):
  '''simple docstring'''





  lowerCAmelCase_			:      List[str]			=   min(A__					)
  lowerCAmelCase_			:      Optional[int]			=   max(A__					)
  # normalize data
  return [round((x - x_min) / (x_max - x_min)							,    A__					) for x in data]







def 				UpperCamelCase_			(    A__					:   list							,    A__					:   int = 3					):
  '''simple docstring'''





  lowerCAmelCase_			:      str			=   mean(A__					)
  lowerCAmelCase_			:      List[Any]			=   stdev(A__					)
  # standardize data
  return [round((x - mu) / (sigma)							,    A__					) for x in data]



