





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


lowercase__   :				int      =   '''CompVis/stable-diffusion-v1-1'''
lowercase__   :				List[Any]      =   '''CompVis/stable-diffusion-v1-2'''
lowercase__   :				Dict      =   '''CompVis/stable-diffusion-v1-3'''
lowercase__   :				Tuple      =   '''CompVis/stable-diffusion-v1-4'''


class 			SCREAMING_SNAKE_CASE   (a__							):


     def __init__(						self						,     _UpperCAmelCase						,     _UpperCAmelCase						,     _UpperCAmelCase						,     _UpperCAmelCase						,     _UpperCAmelCase						,     _UpperCAmelCase						,     _UpperCAmelCase						,     _UpperCAmelCase = True						,     ):

          '''simple docstring'''






          super()._init_()

          __A						:			Union[str, Any]								=	StableDiffusionPipeline.from_pretrained(_UpperCAmelCase)
          __A						:			Union[str, Any]								=	StableDiffusionPipeline.from_pretrained(_UpperCAmelCase)
          __A						:			Any								=	StableDiffusionPipeline.from_pretrained(_UpperCAmelCase)
          __A						:			Any								=	StableDiffusionPipeline(
              vae=_UpperCAmelCase						,     text_encoder=_UpperCAmelCase						,     tokenizer=_UpperCAmelCase						,     unet=_UpperCAmelCase						,     scheduler=_UpperCAmelCase						,     safety_checker=_UpperCAmelCase						,     feature_extractor=_UpperCAmelCase						,     requires_safety_checker=_UpperCAmelCase						,     )

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


     @property
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






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


     def 							SCREAMING_SNAKE_CASE  (						self						,     _UpperCAmelCase = "auto"):

          '''simple docstring'''






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


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          self.enable_attention_slicing(_UpperCAmelCase)


     @torch.no_grad()
     def 							SCREAMING_SNAKE_CASE  (						self						,     _UpperCAmelCase						,     _UpperCAmelCase = 512						,     _UpperCAmelCase = 512						,     _UpperCAmelCase = 50						,     _UpperCAmelCase = 7.5						,     _UpperCAmelCase = None						,     _UpperCAmelCase = 1						,     _UpperCAmelCase = 0.0						,     _UpperCAmelCase = None						,     _UpperCAmelCase = None						,     _UpperCAmelCase = "pil"						,     _UpperCAmelCase = True						,     _UpperCAmelCase = None						,     _UpperCAmelCase = 1						,     **_UpperCAmelCase						,     ):

          '''simple docstring'''






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


     @torch.no_grad()
     def 							SCREAMING_SNAKE_CASE  (						self						,     _UpperCAmelCase						,     _UpperCAmelCase = 512						,     _UpperCAmelCase = 512						,     _UpperCAmelCase = 50						,     _UpperCAmelCase = 7.5						,     _UpperCAmelCase = None						,     _UpperCAmelCase = 1						,     _UpperCAmelCase = 0.0						,     _UpperCAmelCase = None						,     _UpperCAmelCase = None						,     _UpperCAmelCase = "pil"						,     _UpperCAmelCase = True						,     _UpperCAmelCase = None						,     _UpperCAmelCase = 1						,     **_UpperCAmelCase						,     ):

          '''simple docstring'''






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


     @torch.no_grad()
     def 							SCREAMING_SNAKE_CASE  (						self						,     _UpperCAmelCase						,     _UpperCAmelCase = 512						,     _UpperCAmelCase = 512						,     _UpperCAmelCase = 50						,     _UpperCAmelCase = 7.5						,     _UpperCAmelCase = None						,     _UpperCAmelCase = 1						,     _UpperCAmelCase = 0.0						,     _UpperCAmelCase = None						,     _UpperCAmelCase = None						,     _UpperCAmelCase = "pil"						,     _UpperCAmelCase = True						,     _UpperCAmelCase = None						,     _UpperCAmelCase = 1						,     **_UpperCAmelCase						,     ):

          '''simple docstring'''






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


     @torch.no_grad()
     def 							SCREAMING_SNAKE_CASE  (						self						,     _UpperCAmelCase						,     _UpperCAmelCase = 512						,     _UpperCAmelCase = 512						,     _UpperCAmelCase = 50						,     _UpperCAmelCase = 7.5						,     _UpperCAmelCase = None						,     _UpperCAmelCase = 1						,     _UpperCAmelCase = 0.0						,     _UpperCAmelCase = None						,     _UpperCAmelCase = None						,     _UpperCAmelCase = "pil"						,     _UpperCAmelCase = True						,     _UpperCAmelCase = None						,     _UpperCAmelCase = 1						,     **_UpperCAmelCase						,     ):

          '''simple docstring'''






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


     @torch.no_grad()
     def 							SCREAMING_SNAKE_CASE  (						self						,     _UpperCAmelCase						,     _UpperCAmelCase = 512						,     _UpperCAmelCase = 512						,     _UpperCAmelCase = 50						,     _UpperCAmelCase = 7.5						,     _UpperCAmelCase = None						,     _UpperCAmelCase = 1						,     _UpperCAmelCase = 0.0						,     _UpperCAmelCase = None						,     _UpperCAmelCase = None						,     _UpperCAmelCase = "pil"						,     _UpperCAmelCase = True						,     _UpperCAmelCase = None						,     _UpperCAmelCase = 1						,     **_UpperCAmelCase						,     ):

          '''simple docstring'''






          __A						:			Optional[Any]								=	'cuda' if torch.cuda.is_available() else 'cpu'
          self.to(_UpperCAmelCase)

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

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

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

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

          # 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






def 	_lowerCAmelCase      (  __snake_case  :			list[int | str]      )					->					None:
     create_state_space_tree(__snake_case			,							[]			,							0			,							[0 for i in range(len(__snake_case      )      )]      )






def 	_lowerCAmelCase      (  __snake_case  :			list[int | str]			,							__snake_case  :			list[int | str]			,							__snake_case  :			int			,							__snake_case  :			list[int]			,							)					->					None:

     if index == len(__snake_case      ):
          print(__snake_case      )
          return

     for i in range(len(__snake_case      )      ):
          if not index_used[i]:
               current_sequence.append(sequence[i]      )
               __A						:			Any								=	True
               create_state_space_tree(__snake_case			,							__snake_case			,							index + 1			,							__snake_case      )
               current_sequence.pop()
               __A						:			Any								=	False
lowercase__   :				list[int | str]      =   [3, 1, 2, 4]
generate_all_permutations(sequence)

lowercase__   :				list[int | str]      =   ["A", "B", "C"]







generate_all_permutations(sequence_a)