


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






class   __snake_case			(  _SCREAMING_SNAKE_CASE):







    """simple docstring"""



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

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

    def __lowercase  (  self       :    List[str]						)  ->    List[Any]:
      self.enable_attention_slicing(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       :    List[Any]       ,		)  ->    Optional[Any]:
      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       :    List[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       :    Union[str, Any]       ,		)  ->    List[Any]:
      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       :    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       :    Tuple       ,		)  ->    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       :    Optional[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]       ,		)  ->    Any:
      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       :    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       :    Tuple       ,		)  ->    int:
      lowerCAmelCase_     : Optional[int]     =  """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_     : 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.3
      lowerCAmelCase_     : Dict     =  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_     : int     =  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 __future__ import annotations

import numpy as np







def 							UpperCamelCase_     (       A__   :  np.ndarray   ):
  '''simple docstring'''





  lowerCAmelCase_,				lowerCAmelCase_     : List[str]     =  np.shape(A__   )
  if rows != columns:
    lowerCAmelCase_     : List[str]     =  (
        """'table' has to be of square shaped array but got a """
        f'{rows}x{columns} array:\n{table}'
    )
    raise ValueError(A__   )

  lowerCAmelCase_     : Optional[int]     =  np.zeros((rows, columns)   )
  lowerCAmelCase_     : Tuple     =  np.zeros((rows, columns)   )
  for i in range(A__   ):
    for j in range(A__   ):
      lowerCAmelCase_     : str     =  sum(lower[i][k] * upper[k][j] for k in range(A__   )   )
      if upper[j][j] == 0:
        raise ArithmeticError("""No LU decomposition exists"""   )
      lowerCAmelCase_     : Union[str, Any]     =  (table[i][j] - total) / upper[j][j]
    lowerCAmelCase_     : Dict     =  1
    for j in range(A__				,       A__   ):
      lowerCAmelCase_     : str     =  sum(lower[i][k] * upper[k][j] for k in range(A__   )   )
      lowerCAmelCase_     : List[str]     =  table[i][j] - total
  return lower, upper


if __name__ == "__main__":
  import doctest

  doctest.testmod()



