


"""simple docstring"""







import heapq as hq
import math
from collections.abc import Iterator


class       SCREAMING_SNAKE_CASE__				:
       """simple docstring"""


       def __init__(						self		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     int								=							str(id_						)
         lowerCAmelCase     :     Union[str, Any]								=							None
         lowerCAmelCase     :     str								=							None
         lowerCAmelCase     :     Union[str, Any]								=							[]
         lowerCAmelCase     :     Tuple								=							{}  # {vertex:distance}

       def __lt__(						self		,     snake_case__						):






         """simple docstring"""





         return self.key < other.key

       def __repr__(						self						):






         """simple docstring"""





         return self.id

       def        lowercase__							(						self		,     snake_case__						):






         """simple docstring"""





         self.neighbors.append(__SCREAMING_SNAKE_CASE						)







       def        lowercase__							(						self		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     Optional[int]								=							weight

def 					a__			(				SCREAMING_SNAKE_CASE    :    Union[str, Any]				,      SCREAMING_SNAKE_CASE    :    List[str]				,      SCREAMING_SNAKE_CASE    :    List[Any]				,      SCREAMING_SNAKE_CASE    :    str				):


  '''simple docstring'''







  graph[a - 1].add_neighbor(graph[b - 1]				)
  graph[b - 1].add_neighbor(graph[a - 1]				)
  # add the edges:
  graph[a - 1].add_edge(graph[b - 1]				,      _lowerCamelCase				)
  graph[b - 1].add_edge(graph[a - 1]				,      _lowerCamelCase				)
def 					a__			(				SCREAMING_SNAKE_CASE    :    list				,      SCREAMING_SNAKE_CASE    :    Vertex				):


  '''simple docstring'''







  lowerCAmelCase     :     Any								=							[]
  for u in graph:
    lowerCAmelCase     :     List[Any]								=							math.inf
    lowerCAmelCase     :     List[Any]								=							None
  lowerCAmelCase     :     Dict								=							0
  lowerCAmelCase     :     Union[str, Any]								=							graph[:]
  while q:
    lowerCAmelCase     :     Optional[int]								=							min(_lowerCamelCase				)
    q.remove(_lowerCamelCase				)
    for v in u.neighbors:
      if (v in q) and (u.edges[v.id] < v.key):
        lowerCAmelCase     :     Optional[int]								=							u
        lowerCAmelCase     :     str								=							u.edges[v.id]
  for i in range(1				,      len(_lowerCamelCase				)				):
    a.append((int(graph[i].id				) + 1, int(graph[i].pi.id				) + 1)				)
  return a
def 					a__			(				SCREAMING_SNAKE_CASE    :    list				,      SCREAMING_SNAKE_CASE    :    Vertex				):


  '''simple docstring'''







  for u in graph:
    lowerCAmelCase     :     Dict								=							math.inf
    lowerCAmelCase     :     Optional[int]								=							None
  lowerCAmelCase     :     Optional[Any]								=							0

  lowerCAmelCase     :     Any								=							list(_lowerCamelCase				)
  hq.heapify(_lowerCamelCase				)

  while h:
    lowerCAmelCase     :     Optional[Any]								=							hq.heappop(_lowerCamelCase				)
    for v in u.neighbors:
      if (v in h) and (u.edges[v.id] < v.key):
        lowerCAmelCase     :     Any								=							u
        lowerCAmelCase     :     Any								=							u.edges[v.id]
        hq.heapify(_lowerCamelCase				)

  for i in range(1				,      len(_lowerCamelCase				)				):
    yield (int(graph[i].id				) + 1, int(graph[i].pi.id				) + 1)
def 					a__			(				):


  '''simple docstring'''







  pass


if __name__ == "__main__":
     import doctest

     doctest.testmod()













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


_SCREAMING_SNAKE_CASE					:				Union[str, Any]					    =						'''CompVis/stable-diffusion-v1-1'''
_SCREAMING_SNAKE_CASE					:				Optional[Any]					    =						'''CompVis/stable-diffusion-v1-2'''
_SCREAMING_SNAKE_CASE					:				int					    =						'''CompVis/stable-diffusion-v1-3'''
_SCREAMING_SNAKE_CASE					:				str					    =						'''CompVis/stable-diffusion-v1-4'''






class      a						(					__snake_case		):






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

      lowerCamelCase_         =						StableDiffusionPipeline.from_pretrained(__SCREAMING_SNAKE_CASE					)
      lowerCamelCase_         =						StableDiffusionPipeline.from_pretrained(__SCREAMING_SNAKE_CASE					)
      lowerCamelCase_         =						StableDiffusionPipeline.from_pretrained(__SCREAMING_SNAKE_CASE					)
      lowerCamelCase_         =						StableDiffusionPipeline(
          vae=__SCREAMING_SNAKE_CASE       ,						text_encoder=__SCREAMING_SNAKE_CASE       ,						tokenizer=__SCREAMING_SNAKE_CASE       ,						unet=__SCREAMING_SNAKE_CASE       ,						scheduler=__SCREAMING_SNAKE_CASE       ,						safety_checker=__SCREAMING_SNAKE_CASE       ,						feature_extractor=__SCREAMING_SNAKE_CASE       ,						requires_safety_checker=__SCREAMING_SNAKE_CASE       ,						)

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






    @property
    def    UpperCamelCase       (       self     :							List[str]					)     ->		Dict[str, Any]:
      return {k: getattr(self       ,						__SCREAMING_SNAKE_CASE					) for k in self.config.keys() if not k.startswith('_'					)}






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






    def    UpperCamelCase       (       self     :							Any					)     ->		List[Any]:
      self.enable_attention_slicing(__SCREAMING_SNAKE_CASE					)






    @torch.no_grad()
    def    UpperCamelCase       (       self     :							Any       ,						__SCREAMING_SNAKE_CASE     :							Union[str, List[str]]       ,						__SCREAMING_SNAKE_CASE     :							int = 512       ,						__SCREAMING_SNAKE_CASE     :							int = 512       ,						__SCREAMING_SNAKE_CASE     :							int = 50       ,						__SCREAMING_SNAKE_CASE     :							float = 7.5       ,						__SCREAMING_SNAKE_CASE     :							Optional[Union[str, List[str]]] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[int] = 1       ,						__SCREAMING_SNAKE_CASE     :							float = 0.0       ,						__SCREAMING_SNAKE_CASE     :							Optional[torch.Generator] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[torch.FloatTensor] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[str] = "pil"       ,						__SCREAMING_SNAKE_CASE     :							bool = True       ,						__SCREAMING_SNAKE_CASE     :							Optional[Callable[[int, int, torch.FloatTensor], None]] = None       ,						__SCREAMING_SNAKE_CASE     :							int = 1       ,						**__SCREAMING_SNAKE_CASE     :							int       ,						)     ->		Tuple:
      return self.pipea(
          prompt=__SCREAMING_SNAKE_CASE       ,						height=__SCREAMING_SNAKE_CASE       ,						width=__SCREAMING_SNAKE_CASE       ,						num_inference_steps=__SCREAMING_SNAKE_CASE       ,						guidance_scale=__SCREAMING_SNAKE_CASE       ,						negative_prompt=__SCREAMING_SNAKE_CASE       ,						num_images_per_prompt=__SCREAMING_SNAKE_CASE       ,						eta=__SCREAMING_SNAKE_CASE       ,						generator=__SCREAMING_SNAKE_CASE       ,						latents=__SCREAMING_SNAKE_CASE       ,						output_type=__SCREAMING_SNAKE_CASE       ,						return_dict=__SCREAMING_SNAKE_CASE       ,						callback=__SCREAMING_SNAKE_CASE       ,						callback_steps=__SCREAMING_SNAKE_CASE       ,						**__SCREAMING_SNAKE_CASE       ,						)






    @torch.no_grad()
    def    UpperCamelCase       (       self     :							List[str]       ,						__SCREAMING_SNAKE_CASE     :							Union[str, List[str]]       ,						__SCREAMING_SNAKE_CASE     :							int = 512       ,						__SCREAMING_SNAKE_CASE     :							int = 512       ,						__SCREAMING_SNAKE_CASE     :							int = 50       ,						__SCREAMING_SNAKE_CASE     :							float = 7.5       ,						__SCREAMING_SNAKE_CASE     :							Optional[Union[str, List[str]]] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[int] = 1       ,						__SCREAMING_SNAKE_CASE     :							float = 0.0       ,						__SCREAMING_SNAKE_CASE     :							Optional[torch.Generator] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[torch.FloatTensor] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[str] = "pil"       ,						__SCREAMING_SNAKE_CASE     :							bool = True       ,						__SCREAMING_SNAKE_CASE     :							Optional[Callable[[int, int, torch.FloatTensor], None]] = None       ,						__SCREAMING_SNAKE_CASE     :							int = 1       ,						**__SCREAMING_SNAKE_CASE     :							List[str]       ,						)     ->		Optional[int]:
      return self.pipea(
          prompt=__SCREAMING_SNAKE_CASE       ,						height=__SCREAMING_SNAKE_CASE       ,						width=__SCREAMING_SNAKE_CASE       ,						num_inference_steps=__SCREAMING_SNAKE_CASE       ,						guidance_scale=__SCREAMING_SNAKE_CASE       ,						negative_prompt=__SCREAMING_SNAKE_CASE       ,						num_images_per_prompt=__SCREAMING_SNAKE_CASE       ,						eta=__SCREAMING_SNAKE_CASE       ,						generator=__SCREAMING_SNAKE_CASE       ,						latents=__SCREAMING_SNAKE_CASE       ,						output_type=__SCREAMING_SNAKE_CASE       ,						return_dict=__SCREAMING_SNAKE_CASE       ,						callback=__SCREAMING_SNAKE_CASE       ,						callback_steps=__SCREAMING_SNAKE_CASE       ,						**__SCREAMING_SNAKE_CASE       ,						)






    @torch.no_grad()
    def    UpperCamelCase       (       self     :							Optional[Any]       ,						__SCREAMING_SNAKE_CASE     :							Union[str, List[str]]       ,						__SCREAMING_SNAKE_CASE     :							int = 512       ,						__SCREAMING_SNAKE_CASE     :							int = 512       ,						__SCREAMING_SNAKE_CASE     :							int = 50       ,						__SCREAMING_SNAKE_CASE     :							float = 7.5       ,						__SCREAMING_SNAKE_CASE     :							Optional[Union[str, List[str]]] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[int] = 1       ,						__SCREAMING_SNAKE_CASE     :							float = 0.0       ,						__SCREAMING_SNAKE_CASE     :							Optional[torch.Generator] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[torch.FloatTensor] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[str] = "pil"       ,						__SCREAMING_SNAKE_CASE     :							bool = True       ,						__SCREAMING_SNAKE_CASE     :							Optional[Callable[[int, int, torch.FloatTensor], None]] = None       ,						__SCREAMING_SNAKE_CASE     :							int = 1       ,						**__SCREAMING_SNAKE_CASE     :							Optional[int]       ,						)     ->		Tuple:
      return self.pipea(
          prompt=__SCREAMING_SNAKE_CASE       ,						height=__SCREAMING_SNAKE_CASE       ,						width=__SCREAMING_SNAKE_CASE       ,						num_inference_steps=__SCREAMING_SNAKE_CASE       ,						guidance_scale=__SCREAMING_SNAKE_CASE       ,						negative_prompt=__SCREAMING_SNAKE_CASE       ,						num_images_per_prompt=__SCREAMING_SNAKE_CASE       ,						eta=__SCREAMING_SNAKE_CASE       ,						generator=__SCREAMING_SNAKE_CASE       ,						latents=__SCREAMING_SNAKE_CASE       ,						output_type=__SCREAMING_SNAKE_CASE       ,						return_dict=__SCREAMING_SNAKE_CASE       ,						callback=__SCREAMING_SNAKE_CASE       ,						callback_steps=__SCREAMING_SNAKE_CASE       ,						**__SCREAMING_SNAKE_CASE       ,						)






    @torch.no_grad()
    def    UpperCamelCase       (       self     :							Tuple       ,						__SCREAMING_SNAKE_CASE     :							Union[str, List[str]]       ,						__SCREAMING_SNAKE_CASE     :							int = 512       ,						__SCREAMING_SNAKE_CASE     :							int = 512       ,						__SCREAMING_SNAKE_CASE     :							int = 50       ,						__SCREAMING_SNAKE_CASE     :							float = 7.5       ,						__SCREAMING_SNAKE_CASE     :							Optional[Union[str, List[str]]] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[int] = 1       ,						__SCREAMING_SNAKE_CASE     :							float = 0.0       ,						__SCREAMING_SNAKE_CASE     :							Optional[torch.Generator] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[torch.FloatTensor] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[str] = "pil"       ,						__SCREAMING_SNAKE_CASE     :							bool = True       ,						__SCREAMING_SNAKE_CASE     :							Optional[Callable[[int, int, torch.FloatTensor], None]] = None       ,						__SCREAMING_SNAKE_CASE     :							int = 1       ,						**__SCREAMING_SNAKE_CASE     :							Tuple       ,						)     ->		Tuple:
      return self.pipea(
          prompt=__SCREAMING_SNAKE_CASE       ,						height=__SCREAMING_SNAKE_CASE       ,						width=__SCREAMING_SNAKE_CASE       ,						num_inference_steps=__SCREAMING_SNAKE_CASE       ,						guidance_scale=__SCREAMING_SNAKE_CASE       ,						negative_prompt=__SCREAMING_SNAKE_CASE       ,						num_images_per_prompt=__SCREAMING_SNAKE_CASE       ,						eta=__SCREAMING_SNAKE_CASE       ,						generator=__SCREAMING_SNAKE_CASE       ,						latents=__SCREAMING_SNAKE_CASE       ,						output_type=__SCREAMING_SNAKE_CASE       ,						return_dict=__SCREAMING_SNAKE_CASE       ,						callback=__SCREAMING_SNAKE_CASE       ,						callback_steps=__SCREAMING_SNAKE_CASE       ,						**__SCREAMING_SNAKE_CASE       ,						)






    @torch.no_grad()
    def    UpperCamelCase       (       self     :							Dict       ,						__SCREAMING_SNAKE_CASE     :							Union[str, List[str]]       ,						__SCREAMING_SNAKE_CASE     :							int = 512       ,						__SCREAMING_SNAKE_CASE     :							int = 512       ,						__SCREAMING_SNAKE_CASE     :							int = 50       ,						__SCREAMING_SNAKE_CASE     :							float = 7.5       ,						__SCREAMING_SNAKE_CASE     :							Optional[Union[str, List[str]]] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[int] = 1       ,						__SCREAMING_SNAKE_CASE     :							float = 0.0       ,						__SCREAMING_SNAKE_CASE     :							Optional[torch.Generator] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[torch.FloatTensor] = None       ,						__SCREAMING_SNAKE_CASE     :							Optional[str] = "pil"       ,						__SCREAMING_SNAKE_CASE     :							bool = True       ,						__SCREAMING_SNAKE_CASE     :							Optional[Callable[[int, int, torch.FloatTensor], None]] = None       ,						__SCREAMING_SNAKE_CASE     :							int = 1       ,						**__SCREAMING_SNAKE_CASE     :							int       ,						)     ->		str:
      lowerCamelCase_         =						'cuda' if torch.cuda.is_available() else 'cpu'
      self.to(__SCREAMING_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
      lowerCamelCase_         =						self.textaimg_sda_a(
          prompt=__SCREAMING_SNAKE_CASE       ,						height=__SCREAMING_SNAKE_CASE       ,						width=__SCREAMING_SNAKE_CASE       ,						num_inference_steps=__SCREAMING_SNAKE_CASE       ,						guidance_scale=__SCREAMING_SNAKE_CASE       ,						negative_prompt=__SCREAMING_SNAKE_CASE       ,						num_images_per_prompt=__SCREAMING_SNAKE_CASE       ,						eta=__SCREAMING_SNAKE_CASE       ,						generator=__SCREAMING_SNAKE_CASE       ,						latents=__SCREAMING_SNAKE_CASE       ,						output_type=__SCREAMING_SNAKE_CASE       ,						return_dict=__SCREAMING_SNAKE_CASE       ,						callback=__SCREAMING_SNAKE_CASE       ,						callback_steps=__SCREAMING_SNAKE_CASE       ,						**__SCREAMING_SNAKE_CASE       ,						)

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

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

      # Get first result from Stable Diffusion Checkpoint v1.4
      lowerCamelCase_         =						self.textaimg_sda_a(
          prompt=__SCREAMING_SNAKE_CASE       ,						height=__SCREAMING_SNAKE_CASE       ,						width=__SCREAMING_SNAKE_CASE       ,						num_inference_steps=__SCREAMING_SNAKE_CASE       ,						guidance_scale=__SCREAMING_SNAKE_CASE       ,						negative_prompt=__SCREAMING_SNAKE_CASE       ,						num_images_per_prompt=__SCREAMING_SNAKE_CASE       ,						eta=__SCREAMING_SNAKE_CASE       ,						generator=__SCREAMING_SNAKE_CASE       ,						latents=__SCREAMING_SNAKE_CASE       ,						output_type=__SCREAMING_SNAKE_CASE       ,						return_dict=__SCREAMING_SNAKE_CASE       ,						callback=__SCREAMING_SNAKE_CASE       ,						callback_steps=__SCREAMING_SNAKE_CASE       ,						**__SCREAMING_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]]					)




