
"""simple docstring"""




class 		a__						:
   def __init__(			self				):
          lowercase    :				int       		=							0
          lowercase    :				Union[str, Any]       		=							0
          lowercase    :				int       		=							{}
   def 			__magic_name__			(			self	,    _a				):
          if vertex not in self.adjacency:
                 lowercase    :				Union[str, Any]       		=							{}
                 self.num_vertices += 1
   def 			__magic_name__			(			self	,    _a	,    _a	,    _a				):
          self.add_vertex(_a				)
          self.add_vertex(_a				)

          if head == tail:
                 return

          lowercase    :				str       		=							weight
          lowercase    :				int       		=							weight
   def 			__magic_name__			(			self				):
          lowercase    :				Union[str, Any]       		=							self.get_edges()
          for edge in edges:
                 lowercase		,    lowercase		,    lowercase    :				Any       		=							edge
                 edges.remove((tail, head, weight)				)
          for i in range(len(_a				)				):
                 lowercase    :				str       		=							list(edges[i]				)

          edges.sort(key=lambda _a				: e[2]				)
          for i in range(len(_a				) - 1				):
                 if edges[i][2] >= edges[i + 1][2]:
                        lowercase    :				Tuple       		=							edges[i][2] + 1
          for edge in edges:
                 lowercase		,    lowercase		,    lowercase    :				List[Any]       		=							edge
                 lowercase    :				int       		=							weight
                 lowercase    :				Any       		=							weight
   def __str__(			self				):
          lowercase    :				str       		=							""
          for tail in self.adjacency:
                 for head in self.adjacency[tail]:
                        lowercase    :				Optional[Any]       		=							self.adjacency[head][tail]
                        string += f"""{head} -> {tail} == {weight}\n"""
          return string.rstrip("\n"				)
   def 			__magic_name__			(			self				):
          lowercase    :				Tuple       		=							[]
          for tail in self.adjacency:
                 for head in self.adjacency[tail]:
                        output.append((tail, head, self.adjacency[head][tail])				)
          return output
   def 			__magic_name__			(			self				):
          return self.adjacency.keys()
   @staticmethod
   def 			__magic_name__			(			_a=None	,    _a=None				):
          lowercase    :				List[Any]       		=							Graph()
          if vertices is None:
                 lowercase    :				Optional[Any]       		=							[]
          if edges is None:
                 lowercase    :				List[Any]       		=							[]
          for vertex in vertices:
                 g.add_vertex(_a				)
          for edge in edges:
                 g.add_edge(*_a				)
          return g

   class 		a__						:
      def __init__(			self				):
             lowercase    :				Union[str, Any]       		=							{}
             lowercase    :				Union[str, Any]       		=							{}
      def __len__(			self				):
             return len(self.parent				)
      def 			__magic_name__			(			self	,    _a				):
             if item in self.parent:
                    return self.find(_a				)

             lowercase    :				List[str]       		=							item
             lowercase    :				Optional[int]       		=							0
             return item
      def 			__magic_name__			(			self	,    _a				):
             if item not in self.parent:
                    return self.make_set(_a				)
             if item != self.parent[item]:
                    lowercase    :				Optional[Any]       		=							self.find(self.parent[item]				)
             return self.parent[item]

      def 			__magic_name__			(			self	,    _a	,    _a				):
             lowercase    :				Optional[int]       		=							self.find(_a				)
             lowercase    :				Any       		=							self.find(_a				)

             if roota == roota:
                    return roota

             if self.rank[roota] > self.rank[roota]:
                    lowercase    :				Union[str, Any]       		=							roota
                    return roota

             if self.rank[roota] < self.rank[roota]:
                    lowercase    :				Optional[Any]       		=							roota
                    return roota

             if self.rank[roota] == self.rank[roota]:
                    self.rank[roota] += 1
                    lowercase    :				Tuple       		=							roota
                    return roota
             return None


   @staticmethod
   def 			__magic_name__			(			_a				):
          lowercase    :				Tuple       		=							graph.num_vertices

          lowercase    :				List[Any]       		=							Graph.UnionFind()
          lowercase    :				str       		=							[]
          while num_components > 1:
                 lowercase    :				Union[str, Any]       		=							{}
                 for vertex in graph.get_vertices():
                        lowercase    :				Optional[Any]       		=							-1

                 lowercase    :				str       		=							graph.get_edges()
                 for edge in edges:
                        lowercase		,    lowercase		,    lowercase    :				Optional[Any]       		=							edge
                        edges.remove((tail, head, weight)				)
                 for edge in edges:
                        lowercase		,    lowercase		,    lowercase    :				Union[str, Any]       		=							edge
                        lowercase    :				Tuple       		=							union_find.find(_a				)
                        lowercase    :				int       		=							union_find.find(_a				)
                        if seta != seta:
                               if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
                                      lowercase    :				Union[str, Any]       		=							[head, tail, weight]

                               if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
                                      lowercase    :				Any       		=							[head, tail, weight]
                 for vertex in cheap_edge:
                        if cheap_edge[vertex] != -1:
                               lowercase		,    lowercase		,    lowercase    :				List[Any]       		=							cheap_edge[vertex]
                               if union_find.find(_a				) != union_find.find(_a				):
                                      union_find.union(_a	,    _a				)
                                      mst_edges.append(cheap_edge[vertex]				)
                                      lowercase    :				List[Any]       		=							num_components - 1
          lowercase    :				Dict       		=							Graph.build(edges=_a				)
          return mst




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

class 		a__						(      a_						):
   def __init__(			self	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a = True	,    ):
          super()._init_()

          lowercase    :				Optional[Any]       		=							StableDiffusionPipeline.from_pretrained(_a				)
          lowercase    :				str       		=							StableDiffusionPipeline.from_pretrained(_a				)
          lowercase    :				Dict       		=							StableDiffusionPipeline.from_pretrained(_a				)
          lowercase    :				Union[str, Any]       		=							StableDiffusionPipeline(
              vae=_a	,    text_encoder=_a	,    tokenizer=_a	,    unet=_a	,    scheduler=_a	,    safety_checker=_a	,    feature_extractor=_a	,    requires_safety_checker=_a	,    )

          self.register_modules(pipelinea=self.pipea	,    pipelinea=self.pipea	,    pipelinea=self.pipea	,    pipelinea=self.pipea				)
   @property
   def 			__magic_name__			(			self				):
          return {k: getattr(self	,    _a				) for k in self.config.keys() if not k.startswith("_"				)}
   def 			__magic_name__			(			self	,    _a = "auto"				):
          if slice_size == "auto":
                 # half the attention head size is usually a good trade-off between
                 # speed and memory
                 lowercase    :				str       		=							self.unet.config.attention_head_dim // 2
          self.unet.set_attention_slice(_a				)
   def 			__magic_name__			(			self				):
          self.enable_attention_slicing(_a				)
   @torch.no_grad()
   def 			__magic_name__			(			self	,    _a	,    _a = 512	,    _a = 512	,    _a = 50	,    _a = 7.5	,    _a = None	,    _a = 1	,    _a = 0.0	,    _a = None	,    _a = None	,    _a = "pil"	,    _a = True	,    _a = None	,    _a = 1	,    **_a	,    ):
          return self.pipea(
              prompt=_a	,    height=_a	,    width=_a	,    num_inference_steps=_a	,    guidance_scale=_a	,    negative_prompt=_a	,    num_images_per_prompt=_a	,    eta=_a	,    generator=_a	,    latents=_a	,    output_type=_a	,    return_dict=_a	,    callback=_a	,    callback_steps=_a	,    **_a	,    )
   @torch.no_grad()
   def 			__magic_name__			(			self	,    _a	,    _a = 512	,    _a = 512	,    _a = 50	,    _a = 7.5	,    _a = None	,    _a = 1	,    _a = 0.0	,    _a = None	,    _a = None	,    _a = "pil"	,    _a = True	,    _a = None	,    _a = 1	,    **_a	,    ):
          return self.pipea(
              prompt=_a	,    height=_a	,    width=_a	,    num_inference_steps=_a	,    guidance_scale=_a	,    negative_prompt=_a	,    num_images_per_prompt=_a	,    eta=_a	,    generator=_a	,    latents=_a	,    output_type=_a	,    return_dict=_a	,    callback=_a	,    callback_steps=_a	,    **_a	,    )
   @torch.no_grad()
   def 			__magic_name__			(			self	,    _a	,    _a = 512	,    _a = 512	,    _a = 50	,    _a = 7.5	,    _a = None	,    _a = 1	,    _a = 0.0	,    _a = None	,    _a = None	,    _a = "pil"	,    _a = True	,    _a = None	,    _a = 1	,    **_a	,    ):
          return self.pipea(
              prompt=_a	,    height=_a	,    width=_a	,    num_inference_steps=_a	,    guidance_scale=_a	,    negative_prompt=_a	,    num_images_per_prompt=_a	,    eta=_a	,    generator=_a	,    latents=_a	,    output_type=_a	,    return_dict=_a	,    callback=_a	,    callback_steps=_a	,    **_a	,    )
   @torch.no_grad()
   def 			__magic_name__			(			self	,    _a	,    _a = 512	,    _a = 512	,    _a = 50	,    _a = 7.5	,    _a = None	,    _a = 1	,    _a = 0.0	,    _a = None	,    _a = None	,    _a = "pil"	,    _a = True	,    _a = None	,    _a = 1	,    **_a	,    ):
          return self.pipea(
              prompt=_a	,    height=_a	,    width=_a	,    num_inference_steps=_a	,    guidance_scale=_a	,    negative_prompt=_a	,    num_images_per_prompt=_a	,    eta=_a	,    generator=_a	,    latents=_a	,    output_type=_a	,    return_dict=_a	,    callback=_a	,    callback_steps=_a	,    **_a	,    )

   @torch.no_grad()
   def 			__magic_name__			(			self	,    _a	,    _a = 512	,    _a = 512	,    _a = 50	,    _a = 7.5	,    _a = None	,    _a = 1	,    _a = 0.0	,    _a = None	,    _a = None	,    _a = "pil"	,    _a = True	,    _a = None	,    _a = 1	,    **_a	,    ):
          lowercase    :				List[Any]       		=							"cuda" if torch.cuda.is_available() else "cpu"
          self.to(_a				)

          # 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
          lowercase    :				List[Any]       		=							self.textaimg_sda_a(
              prompt=_a	,    height=_a	,    width=_a	,    num_inference_steps=_a	,    guidance_scale=_a	,    negative_prompt=_a	,    num_images_per_prompt=_a	,    eta=_a	,    generator=_a	,    latents=_a	,    output_type=_a	,    return_dict=_a	,    callback=_a	,    callback_steps=_a	,    **_a	,    )

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

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

          # Get first result from Stable Diffusion Checkpoint v1.4
          lowercase    :				Optional[int]       		=							self.textaimg_sda_a(
              prompt=_a	,    height=_a	,    width=_a	,    num_inference_steps=_a	,    guidance_scale=_a	,    negative_prompt=_a	,    num_images_per_prompt=_a	,    eta=_a	,    generator=_a	,    latents=_a	,    output_type=_a	,    return_dict=_a	,    callback=_a	,    callback_steps=_a	,    **_a	,    )

          # 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]]				)


