





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


lowerCAmelCase_					:    Dict      	=			'CompVis/stable-diffusion-v1-1'
lowerCAmelCase_					:    str      	=			'CompVis/stable-diffusion-v1-2'
lowerCAmelCase_					:    Dict      	=			'CompVis/stable-diffusion-v1-3'
lowerCAmelCase_					:    List[Any]      	=			'CompVis/stable-diffusion-v1-4'
class 				__SCREAMING_SNAKE_CASE  (_UpperCAmelCase      ):






				"""simple docstring"""







				def __init__(  self     :					List[str]					,				__a     :					int					,				__a     :					str					,				__a     :					Optional[Any]					,				__a     :					Any					,				__a     :					Optional[int]					,				__a     :					Optional[int]					,				__a     :					List[Any]					,				__a     :					Dict = True					,				):
								super()._init_()

								_a								= StableDiffusionPipeline.from_pretrained(A_					)
								_a								= StableDiffusionPipeline.from_pretrained(A_					)
								_a								= StableDiffusionPipeline.from_pretrained(A_					)
								_a								= 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   UpperCamelCase__   (  self     :					List[Any]					):
								return {k: getattr(self					,				A_					) for k in self.config.keys() if not k.startswith("_"					)}




				def   UpperCamelCase__   (  self     :					str					,				__a     :					int = "auto"					):





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




				def   UpperCamelCase__   (  self     :					Tuple					):
								self.enable_attention_slicing(A_					)




				@torch.no_grad()
				def   UpperCamelCase__   (  self     :					str					,				__a     :					Optional[int]					,				__a     :					str = 5_12					,				__a     :					Any = 5_12					,				__a     :					int = 50					,				__a     :					Union[str, Any] = 7.5					,				__a     :					int = None					,				__a     :					int = 1					,				__a     :					str = 0.0					,				__a     :					Union[str, Any] = None					,				__a     :					Dict = None					,				__a     :					str = "pil"					,				__a     :					Tuple = True					,				__a     :					int = None					,				__a     :					Tuple = 1					,				**__a     :					Tuple					,				):
								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   UpperCamelCase__   (  self     :					Dict					,				__a     :					int					,				__a     :					int = 5_12					,				__a     :					Dict = 5_12					,				__a     :					Optional[Any] = 50					,				__a     :					str = 7.5					,				__a     :					List[Any] = None					,				__a     :					List[str] = 1					,				__a     :					Optional[Any] = 0.0					,				__a     :					Dict = None					,				__a     :					List[str] = None					,				__a     :					Union[str, Any] = "pil"					,				__a     :					Optional[int] = True					,				__a     :					Optional[int] = None					,				__a     :					Optional[Any] = 1					,				**__a     :					List[str]					,				):
								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   UpperCamelCase__   (  self     :					Optional[Any]					,				__a     :					Optional[int]					,				__a     :					Optional[int] = 5_12					,				__a     :					int = 5_12					,				__a     :					Dict = 50					,				__a     :					str = 7.5					,				__a     :					Optional[Any] = None					,				__a     :					int = 1					,				__a     :					Tuple = 0.0					,				__a     :					Tuple = None					,				__a     :					List[Any] = None					,				__a     :					Tuple = "pil"					,				__a     :					List[Any] = True					,				__a     :					List[Any] = None					,				__a     :					Optional[int] = 1					,				**__a     :					Union[str, Any]					,				):
								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   UpperCamelCase__   (  self     :					List[str]					,				__a     :					Any					,				__a     :					int = 5_12					,				__a     :					List[str] = 5_12					,				__a     :					List[Any] = 50					,				__a     :					str = 7.5					,				__a     :					Union[str, Any] = None					,				__a     :					Any = 1					,				__a     :					Dict = 0.0					,				__a     :					Optional[int] = None					,				__a     :					Union[str, Any] = None					,				__a     :					Optional[Any] = "pil"					,				__a     :					Any = True					,				__a     :					Dict = None					,				__a     :					Optional[Any] = 1					,				**__a     :					Tuple					,				):
								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   UpperCamelCase__   (  self     :					Tuple					,				__a     :					Optional[int]					,				__a     :					Optional[Any] = 5_12					,				__a     :					Tuple = 5_12					,				__a     :					List[str] = 50					,				__a     :					Optional[int] = 7.5					,				__a     :					Any = None					,				__a     :					Any = 1					,				__a     :					Any = 0.0					,				__a     :					str = None					,				__a     :					int = None					,				__a     :					Optional[int] = "pil"					,				__a     :					Union[str, Any] = True					,				__a     :					Tuple = None					,				__a     :					Dict = 1					,				**__a     :					Any					,				):
								_a								= '''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
								_a								= 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
								_a								= 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
								_a								= 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
								_a								= 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]]					)



def 		_lowercase (     lowercase__   ,	lowercase__						):
      if a < 0 or b < 0:
            raise ValueError('''the value of both inputs must be positive'''						)
      __lowerCAmelCase					:						int					=					str(bin(lowercase__						)						)[2:]  # remove the leading "0b"
      __lowerCAmelCase					:						Any					=					str(bin(lowercase__						)						)[2:]
      __lowerCAmelCase					:						List[str]					=					max(len(lowercase__						)   ,	len(lowercase__						)						)
      return "0b" + "".join(
          str(int('''1''' in (char_a, char_b)						)						)
          for char_a, char_b in zip(a_binary.zfill(lowercase__						)   ,	b_binary.zfill(lowercase__						)						)						)


if __name__ == "__main__":
 import doctest

 doctest.testmod()


