





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


UpperCAmelCase_ 							=       """CompVis/stable-diffusion-v1-1"""
UpperCAmelCase_ 							=       """CompVis/stable-diffusion-v1-2"""
UpperCAmelCase_ 							=       """CompVis/stable-diffusion-v1-3"""
UpperCAmelCase_ 							=       """CompVis/stable-diffusion-v1-4"""
class      UpperCamelCase_						(					_lowerCamelCase   ):




					def __init__(						self			,  lowerCAmelCase_			,  lowerCAmelCase_			,  lowerCAmelCase_			,  lowerCAmelCase_			,  lowerCAmelCase_			,  lowerCAmelCase_			,  lowerCAmelCase_			,  lowerCAmelCase_ = True			,  )						->							Optional[int]:
										super()._init_()

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




					def 		lowerCAmelCase     (						self			,  lowerCAmelCase_ = "auto"					)						->							Any:
										if slice_size == "auto":
															# half the attention head size is usually a good trade-off between
															# speed and memory
															_snake_case													=			self.unet.config.attention_head_dim // 2
										self.unet.set_attention_slice(lowerCAmelCase_					)




					def 		lowerCAmelCase     (						self					)						->							List[str]:
										self.enable_attention_slicing(lowerCAmelCase_					)




					@torch.no_grad()
					def 		lowerCAmelCase     (						self			,  lowerCAmelCase_			,  lowerCAmelCase_ = 512			,  lowerCAmelCase_ = 512			,  lowerCAmelCase_ = 50			,  lowerCAmelCase_ = 7.5			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = 1			,  lowerCAmelCase_ = 0.0			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = "pil"			,  lowerCAmelCase_ = True			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = 1			,  **lowerCAmelCase_			,  )						->							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 		lowerCAmelCase     (						self			,  lowerCAmelCase_			,  lowerCAmelCase_ = 512			,  lowerCAmelCase_ = 512			,  lowerCAmelCase_ = 50			,  lowerCAmelCase_ = 7.5			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = 1			,  lowerCAmelCase_ = 0.0			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = "pil"			,  lowerCAmelCase_ = True			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = 1			,  **lowerCAmelCase_			,  )						->							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 		lowerCAmelCase     (						self			,  lowerCAmelCase_			,  lowerCAmelCase_ = 512			,  lowerCAmelCase_ = 512			,  lowerCAmelCase_ = 50			,  lowerCAmelCase_ = 7.5			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = 1			,  lowerCAmelCase_ = 0.0			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = "pil"			,  lowerCAmelCase_ = True			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = 1			,  **lowerCAmelCase_			,  )						->							List[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 		lowerCAmelCase     (						self			,  lowerCAmelCase_			,  lowerCAmelCase_ = 512			,  lowerCAmelCase_ = 512			,  lowerCAmelCase_ = 50			,  lowerCAmelCase_ = 7.5			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = 1			,  lowerCAmelCase_ = 0.0			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = "pil"			,  lowerCAmelCase_ = True			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = 1			,  **lowerCAmelCase_			,  )						->							Dict:
										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 		lowerCAmelCase     (						self			,  lowerCAmelCase_			,  lowerCAmelCase_ = 512			,  lowerCAmelCase_ = 512			,  lowerCAmelCase_ = 50			,  lowerCAmelCase_ = 7.5			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = 1			,  lowerCAmelCase_ = 0.0			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = "pil"			,  lowerCAmelCase_ = True			,  lowerCAmelCase_ = None			,  lowerCAmelCase_ = 1			,  **lowerCAmelCase_			,  )						->							Any:
										_snake_case													=			'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
										_snake_case													=			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
										_snake_case													=			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
										_snake_case													=			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
										_snake_case													=			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]]					)










from collections import defaultdict

from graphs.minimum_spanning_tree_prims import prisms_algorithm as mst





def   lowerCamelCase__       (       )     ->	List[str]:



					'''simple docstring'''




					_snake_case							,       _snake_case													=			9, 14  # noqa: F841
					_snake_case													=			[
					    [0, 1, 4],
					    [0, 7, 8],
					    [1, 2, 8],
					    [7, 8, 7],
					    [7, 6, 1],
					    [2, 8, 2],
					    [8, 6, 6],
					    [2, 3, 7],
					    [2, 5, 4],
					    [6, 5, 2],
					    [3, 5, 14],
					    [3, 4, 9],
					    [5, 4, 10],
					    [1, 7, 11],
					]

					_snake_case													=			defaultdict(UpperCamelCase__  )
					for nodea, nodea, cost in edges:
										adjancency[nodea].append([nodea, cost]  )
										adjancency[nodea].append([nodea, cost]  )

					_snake_case													=			mst(UpperCamelCase__  )

					_snake_case													=			[
					    [7, 6, 1],
					    [2, 8, 2],
					    [6, 5, 2],
					    [0, 1, 4],
					    [2, 5, 4],
					    [2, 3, 7],
					    [0, 7, 8],
					    [3, 4, 9],
					]

					for answer in expected:
										_snake_case													=			tuple(answer[:2]  )
										_snake_case													=			tuple(edge[::-1]  )
										assert edge in result or reverse in result



