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







class __snake_case       (		lowerCamelCase_	):




   def __init__(					self    :       List[str] ,			_lowercase    :       AutoencoderKL ,			_lowercase    :       CLIPTextModel ,			_lowercase    :       CLIPTokenizer ,			_lowercase    :       UNetaDConditionModel ,			_lowercase    :       Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler] ,			_lowercase    :       StableDiffusionSafetyChecker ,			_lowercase    :       CLIPImageProcessor ,			_lowercase    :       bool = True ,			):



     """simple docstring"""






     super()._init_()

     SCREAMING_SNAKE_CASE__    							=   StableDiffusionPipeline.from_pretrained(_lowercase   )
     SCREAMING_SNAKE_CASE__    							=   StableDiffusionPipeline.from_pretrained(_lowercase   )
     SCREAMING_SNAKE_CASE__    							=   StableDiffusionPipeline.from_pretrained(_lowercase   )
     SCREAMING_SNAKE_CASE__    							=   StableDiffusionPipeline(
         vae=_lowercase ,			text_encoder=_lowercase ,			tokenizer=_lowercase ,			unet=_lowercase ,			scheduler=_lowercase ,			safety_checker=_lowercase ,			feature_extractor=_lowercase ,			requires_safety_checker=_lowercase ,			)

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




   @property
   def 			__a		(					self    :       Any   ):



     """simple docstring"""






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




   def 			__a		(					self    :       Optional[int] ,			_lowercase    :       Optional[Union[str, int]] = "auto"   ):



     """simple docstring"""






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




   def 			__a		(					self    :       List[str]   ):



     """simple docstring"""






     self.enable_attention_slicing(_lowercase   )




   @torch.no_grad()
   def 			__a		(					self    :       List[Any] ,			_lowercase    :       Union[str, List[str]] ,			_lowercase    :       int = 5_12 ,			_lowercase    :       int = 5_12 ,			_lowercase    :       int = 50 ,			_lowercase    :       float = 7.5 ,			_lowercase    :       Optional[Union[str, List[str]]] = None ,			_lowercase    :       Optional[int] = 1 ,			_lowercase    :       float = 0.0 ,			_lowercase    :       Optional[torch.Generator] = None ,			_lowercase    :       Optional[torch.FloatTensor] = None ,			_lowercase    :       Optional[str] = "pil" ,			_lowercase    :       bool = True ,			_lowercase    :       Optional[Callable[[int, int, torch.FloatTensor], None]] = None ,			_lowercase    :       int = 1 ,			**_lowercase    :       str ,			):



     """simple docstring"""






     return self.pipea(
         prompt=_lowercase ,			height=_lowercase ,			width=_lowercase ,			num_inference_steps=_lowercase ,			guidance_scale=_lowercase ,			negative_prompt=_lowercase ,			num_images_per_prompt=_lowercase ,			eta=_lowercase ,			generator=_lowercase ,			latents=_lowercase ,			output_type=_lowercase ,			return_dict=_lowercase ,			callback=_lowercase ,			callback_steps=_lowercase ,			**_lowercase ,			)




   @torch.no_grad()
   def 			__a		(					self    :       int ,			_lowercase    :       Union[str, List[str]] ,			_lowercase    :       int = 5_12 ,			_lowercase    :       int = 5_12 ,			_lowercase    :       int = 50 ,			_lowercase    :       float = 7.5 ,			_lowercase    :       Optional[Union[str, List[str]]] = None ,			_lowercase    :       Optional[int] = 1 ,			_lowercase    :       float = 0.0 ,			_lowercase    :       Optional[torch.Generator] = None ,			_lowercase    :       Optional[torch.FloatTensor] = None ,			_lowercase    :       Optional[str] = "pil" ,			_lowercase    :       bool = True ,			_lowercase    :       Optional[Callable[[int, int, torch.FloatTensor], None]] = None ,			_lowercase    :       int = 1 ,			**_lowercase    :       List[Any] ,			):



     """simple docstring"""






     return self.pipea(
         prompt=_lowercase ,			height=_lowercase ,			width=_lowercase ,			num_inference_steps=_lowercase ,			guidance_scale=_lowercase ,			negative_prompt=_lowercase ,			num_images_per_prompt=_lowercase ,			eta=_lowercase ,			generator=_lowercase ,			latents=_lowercase ,			output_type=_lowercase ,			return_dict=_lowercase ,			callback=_lowercase ,			callback_steps=_lowercase ,			**_lowercase ,			)




   @torch.no_grad()
   def 			__a		(					self    :       Dict ,			_lowercase    :       Union[str, List[str]] ,			_lowercase    :       int = 5_12 ,			_lowercase    :       int = 5_12 ,			_lowercase    :       int = 50 ,			_lowercase    :       float = 7.5 ,			_lowercase    :       Optional[Union[str, List[str]]] = None ,			_lowercase    :       Optional[int] = 1 ,			_lowercase    :       float = 0.0 ,			_lowercase    :       Optional[torch.Generator] = None ,			_lowercase    :       Optional[torch.FloatTensor] = None ,			_lowercase    :       Optional[str] = "pil" ,			_lowercase    :       bool = True ,			_lowercase    :       Optional[Callable[[int, int, torch.FloatTensor], None]] = None ,			_lowercase    :       int = 1 ,			**_lowercase    :       List[Any] ,			):



     """simple docstring"""






     return self.pipea(
         prompt=_lowercase ,			height=_lowercase ,			width=_lowercase ,			num_inference_steps=_lowercase ,			guidance_scale=_lowercase ,			negative_prompt=_lowercase ,			num_images_per_prompt=_lowercase ,			eta=_lowercase ,			generator=_lowercase ,			latents=_lowercase ,			output_type=_lowercase ,			return_dict=_lowercase ,			callback=_lowercase ,			callback_steps=_lowercase ,			**_lowercase ,			)




   @torch.no_grad()
   def 			__a		(					self    :       List[Any] ,			_lowercase    :       Union[str, List[str]] ,			_lowercase    :       int = 5_12 ,			_lowercase    :       int = 5_12 ,			_lowercase    :       int = 50 ,			_lowercase    :       float = 7.5 ,			_lowercase    :       Optional[Union[str, List[str]]] = None ,			_lowercase    :       Optional[int] = 1 ,			_lowercase    :       float = 0.0 ,			_lowercase    :       Optional[torch.Generator] = None ,			_lowercase    :       Optional[torch.FloatTensor] = None ,			_lowercase    :       Optional[str] = "pil" ,			_lowercase    :       bool = True ,			_lowercase    :       Optional[Callable[[int, int, torch.FloatTensor], None]] = None ,			_lowercase    :       int = 1 ,			**_lowercase    :       Any ,			):



     """simple docstring"""






     return self.pipea(
         prompt=_lowercase ,			height=_lowercase ,			width=_lowercase ,			num_inference_steps=_lowercase ,			guidance_scale=_lowercase ,			negative_prompt=_lowercase ,			num_images_per_prompt=_lowercase ,			eta=_lowercase ,			generator=_lowercase ,			latents=_lowercase ,			output_type=_lowercase ,			return_dict=_lowercase ,			callback=_lowercase ,			callback_steps=_lowercase ,			**_lowercase ,			)




   @torch.no_grad()
   def 			__a		(					self    :       Optional[int] ,			_lowercase    :       Union[str, List[str]] ,			_lowercase    :       int = 5_12 ,			_lowercase    :       int = 5_12 ,			_lowercase    :       int = 50 ,			_lowercase    :       float = 7.5 ,			_lowercase    :       Optional[Union[str, List[str]]] = None ,			_lowercase    :       Optional[int] = 1 ,			_lowercase    :       float = 0.0 ,			_lowercase    :       Optional[torch.Generator] = None ,			_lowercase    :       Optional[torch.FloatTensor] = None ,			_lowercase    :       Optional[str] = "pil" ,			_lowercase    :       bool = True ,			_lowercase    :       Optional[Callable[[int, int, torch.FloatTensor], None]] = None ,			_lowercase    :       int = 1 ,			**_lowercase    :       Optional[int] ,			):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   """cuda""" if torch.cuda.is_available() else """cpu"""
     self.to(_lowercase   )

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

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

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

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

     # 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 __future__ import annotations

from collections.abc import Iterator
from typing import Any







class __snake_case       :




   def __init__(					self    :       Union[str, Any] ,			_lowercase    :       Any   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   data
     SCREAMING_SNAKE_CASE__    							=   None







class __snake_case       :




   def __init__(					self    :       List[Any]   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   None
     SCREAMING_SNAKE_CASE__    							=   None




   def __iter__(					self    :       Tuple   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   self.head
     while self.head:
       yield node.data
       SCREAMING_SNAKE_CASE__    							=   node.next
       if node == self.head:
         break




   def __len__(					self    :       int   ):



     """simple docstring"""






     return sum(1 for _ in self   )




   def __repr__(					self    :       Optional[int]   ):



     """simple docstring"""






     return "->".join(str(_lowercase   ) for item in iter(self   )   )




   def 			__a		(					self    :       Optional[int] ,			_lowercase    :       Any   ):



     """simple docstring"""






     self.insert_nth(len(self   ) ,			_lowercase   )




   def 			__a		(					self    :       Tuple ,			_lowercase    :       Any   ):



     """simple docstring"""






     self.insert_nth(0 ,			_lowercase   )




   def 			__a		(					self    :       Tuple ,			_lowercase    :       int ,			_lowercase    :       Any   ):



     """simple docstring"""






     if index < 0 or index > len(self   ):
       raise IndexError("""list index out of range."""   )
     SCREAMING_SNAKE_CASE__    							=   Node(_lowercase   )
     if self.head is None:
       SCREAMING_SNAKE_CASE__    							=   new_node  # first node points itself
       SCREAMING_SNAKE_CASE__    							=   SCREAMING_SNAKE_CASE__    							=   new_node
     elif index == 0:  # insert at head
       SCREAMING_SNAKE_CASE__    							=   self.head
       SCREAMING_SNAKE_CASE__    							=   SCREAMING_SNAKE_CASE__    							=   new_node
     else:
       SCREAMING_SNAKE_CASE__    							=   self.head
       for _ in range(index - 1   ):
         SCREAMING_SNAKE_CASE__    							=   temp.next
       SCREAMING_SNAKE_CASE__    							=   temp.next
       SCREAMING_SNAKE_CASE__    							=   new_node
       if index == len(self   ) - 1:  # insert at tail
         SCREAMING_SNAKE_CASE__    							=   new_node




   def 			__a		(					self    :       Dict   ):



     """simple docstring"""






     return self.delete_nth(0   )




   def 			__a		(					self    :       str   ):



     """simple docstring"""






     return self.delete_nth(len(self   ) - 1   )




   def 			__a		(					self    :       str ,			_lowercase    :       int = 0   ):



     """simple docstring"""






     if not 0 <= index < len(self   ):
       raise IndexError("""list index out of range."""   )
     SCREAMING_SNAKE_CASE__    							=   self.head
     if self.head == self.tail:  # just one node
       SCREAMING_SNAKE_CASE__    							=   SCREAMING_SNAKE_CASE__    							=   None
     elif index == 0:  # delete head node
       SCREAMING_SNAKE_CASE__    							=   self.tail.next.next
       SCREAMING_SNAKE_CASE__    							=   self.head.next
     else:
       SCREAMING_SNAKE_CASE__    							=   self.head
       for _ in range(index - 1   ):
         SCREAMING_SNAKE_CASE__    							=   temp.next
       SCREAMING_SNAKE_CASE__    							=   temp.next
       SCREAMING_SNAKE_CASE__    							=   temp.next.next
       if index == len(self   ) - 1:  # delete at tail
         SCREAMING_SNAKE_CASE__    							=   temp
     return delete_node.data




   def 			__a		(					self    :       Optional[int]   ):



     """simple docstring"""






     return len(self   ) == 0





def 			__SCREAMING_SNAKE_CASE						(      )							->      None:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__    							=   CircularLinkedList()
  assert len(__UpperCamelCase			) == 0
  assert circular_linked_list.is_empty() is True
  assert str(__UpperCamelCase			) == ""

  try:
    circular_linked_list.delete_front()
    raise AssertionError  # This should not happen
  except IndexError:
    assert True  # This should happen

  try:
    circular_linked_list.delete_tail()
    raise AssertionError  # This should not happen
  except IndexError:
    assert True  # This should happen

  try:
    circular_linked_list.delete_nth(-1			)
    raise AssertionError
  except IndexError:
    assert True

  try:
    circular_linked_list.delete_nth(0			)
    raise AssertionError
  except IndexError:
    assert True

  assert circular_linked_list.is_empty() is True
  for i in range(5			):
    assert len(__UpperCamelCase			) == i
    circular_linked_list.insert_nth(__UpperCamelCase				,  i + 1			)
  assert str(__UpperCamelCase			) == "->".join(str(__UpperCamelCase			) for i in range(1				,  6			)			)

  circular_linked_list.insert_tail(6			)
  assert str(__UpperCamelCase			) == "->".join(str(__UpperCamelCase			) for i in range(1				,  7			)			)
  circular_linked_list.insert_head(0			)
  assert str(__UpperCamelCase			) == "->".join(str(__UpperCamelCase			) for i in range(0				,  7			)			)

  assert circular_linked_list.delete_front() == 0
  assert circular_linked_list.delete_tail() == 6
  assert str(__UpperCamelCase			) == "->".join(str(__UpperCamelCase			) for i in range(1				,  6			)			)
  assert circular_linked_list.delete_nth(2			) == 3

  circular_linked_list.insert_nth(2				,  3			)
  assert str(__UpperCamelCase			) == "->".join(str(__UpperCamelCase			) for i in range(1				,  6			)			)

  assert circular_linked_list.is_empty() is False


if __name__ == "__main__":
   import doctest

   doctest.testmod()
