



'''simple docstring'''




from collections.abc import Generator
from math import sin



def       __lowerCamelCase  (					_lowercase		)      ->			bytes:


							if len(UpperCamelCase_		) != 3_2:
														raise ValueError("""Input must be of length 32"""		)

							UpperCAmelCase     :		List[Any]							     =		B""""""
							for i in [3, 2, 1, 0]:
														little_endian += string_aa[8 * i : 8 * i + 8]
							return little_endian



def       __lowerCamelCase  (					_lowercase		)      ->			bytes:


							if i < 0:
														raise ValueError("""Input must be non-negative"""		)

							UpperCAmelCase     :		Union[str, Any]							     =		format(UpperCamelCase_	,				"""08x"""		)[-8:]
							UpperCAmelCase     :		Optional[Any]							     =		B""""""
							for i in [3, 2, 1, 0]:
														little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode("""utf-8"""		)
							return little_endian_hex



def       __lowerCamelCase  (					_lowercase		)      ->			bytes:
							UpperCAmelCase     :		str							     =		B""""""
							for char in message:
														bit_string += format(UpperCamelCase_	,				"""08b"""		).encode("""utf-8"""		)
							UpperCAmelCase     :		int							     =		format(len(UpperCamelCase_		)	,				"""064b"""		).encode("""utf-8"""		)

							# Pad bit_string to a multiple of 512 chars
							bit_string += b"1"
							while len(UpperCamelCase_		) % 5_1_2 != 4_4_8:
														bit_string += b"0"
							bit_string += to_little_endian(start_len[3_2:]		) + to_little_endian(start_len[:3_2]		)

							return bit_string



def       __lowerCamelCase  (					_lowercase		)      ->			Generator[list[int], None, None]:


							if len(UpperCamelCase_		) % 5_1_2 != 0:
														raise ValueError("""Input must have length that's a multiple of 512"""		)

							for pos in range(0	,				len(UpperCamelCase_		)	,				5_1_2		):
														UpperCAmelCase     :		Union[str, Any]							     =		bit_string[pos : pos + 5_1_2]
														UpperCAmelCase     :		Tuple							     =		[]
														for i in range(0	,				5_1_2	,				3_2		):
																					block_words.append(int(to_little_endian(block[i : i + 3_2]		)	,				2		)		)
														yield block_words



def       __lowerCamelCase  (					_lowercase		)      ->			int:


							if i < 0:
														raise ValueError("""Input must be non-negative"""		)

							UpperCAmelCase     :		List[Any]							     =		format(UpperCamelCase_	,				"""032b"""		)
							UpperCAmelCase     :		Any							     =		""""""
							for c in i_str:
														new_str += "1" if c == "0" else "0"
							return int(UpperCamelCase_	,				2		)



def       __lowerCamelCase  (					_lowercase	,				_lowercase		)      ->			int:
							return (a + b) % 2**3_2



def       __lowerCamelCase  (					_lowercase	,				_lowercase		)      ->			int:


							if i < 0:
														raise ValueError("""Input must be non-negative"""		)
							if shift < 0:
														raise ValueError("""Shift must be non-negative"""		)
							return ((i << shift) ^ (i >> (3_2 - shift))) % 2**3_2



def       __lowerCamelCase  (					_lowercase		)      ->			bytes:
							UpperCAmelCase     :		int							     =		preprocess(UpperCamelCase_		)

							UpperCAmelCase     :		Any							     =		[int(2**3_2 * abs(sin(i + 1		)		)		) for i in range(6_4		)]

							# Starting states
							UpperCAmelCase     :		Dict							     =		0x67_452_301
							UpperCAmelCase     :		Optional[int]							     =		0xEF_CDA_B89
							UpperCAmelCase     :		str							     =		0x98_BAD_CFE
							UpperCAmelCase     :		Optional[Any]							     =		0x10_325_476

							UpperCAmelCase     :		int							     =		[
							    7,
							    1_2,
							    1_7,
							    2_2,
							    7,
							    1_2,
							    1_7,
							    2_2,
							    7,
							    1_2,
							    1_7,
							    2_2,
							    7,
							    1_2,
							    1_7,
							    2_2,
							    5,
							    9,
							    1_4,
							    2_0,
							    5,
							    9,
							    1_4,
							    2_0,
							    5,
							    9,
							    1_4,
							    2_0,
							    5,
							    9,
							    1_4,
							    2_0,
							    4,
							    1_1,
							    1_6,
							    2_3,
							    4,
							    1_1,
							    1_6,
							    2_3,
							    4,
							    1_1,
							    1_6,
							    2_3,
							    4,
							    1_1,
							    1_6,
							    2_3,
							    6,
							    1_0,
							    1_5,
							    2_1,
							    6,
							    1_0,
							    1_5,
							    2_1,
							    6,
							    1_0,
							    1_5,
							    2_1,
							    6,
							    1_0,
							    1_5,
							    2_1,
							]

							# Process bit string in chunks, each with 16 32-char words
							for block_words in get_block_words(UpperCamelCase_		):
														UpperCAmelCase     :		Optional[Any]							     =		aa
														UpperCAmelCase     :		str							     =		ba
														UpperCAmelCase     :		str							     =		ca
														UpperCAmelCase     :		List[Any]							     =		da

														# Hash current chunk
														for i in range(6_4		):
																					if i <= 1_5:
																												# f = (b & c) | (not_32(b) & d)     # Alternate definition for f
																												UpperCAmelCase     :		Tuple							     =		d ^ (b & (c ^ d))
																												UpperCAmelCase     :		Optional[Any]							     =		i
																					elif i <= 3_1:
																												# f = (d & b) | (not_32(d) & c)     # Alternate definition for f
																												UpperCAmelCase     :		Union[str, Any]							     =		c ^ (d & (b ^ c))
																												UpperCAmelCase     :		Tuple							     =		(5 * i + 1) % 1_6
																					elif i <= 4_7:
																												UpperCAmelCase     :		Any							     =		b ^ c ^ d
																												UpperCAmelCase     :		Tuple							     =		(3 * i + 5) % 1_6
																					else:
																												UpperCAmelCase     :		Union[str, Any]							     =		c ^ (b | not_aa(UpperCamelCase_		))
																												UpperCAmelCase     :		Dict							     =		(7 * i) % 1_6
																					UpperCAmelCase     :		Dict							     =		(f + a + added_consts[i] + block_words[g]) % 2**3_2
																					UpperCAmelCase     :		Tuple							     =		d
																					UpperCAmelCase     :		Tuple							     =		c
																					UpperCAmelCase     :		Optional[int]							     =		b
																					UpperCAmelCase     :		Optional[Any]							     =		sum_aa(UpperCamelCase_	,				left_rotate_aa(UpperCamelCase_	,				shift_amounts[i]		)		)

														# Add hashed chunk to running total
														UpperCAmelCase     :		Optional[Any]							     =		sum_aa(UpperCamelCase_	,				UpperCamelCase_		)
														UpperCAmelCase     :		Tuple							     =		sum_aa(UpperCamelCase_	,				UpperCamelCase_		)
														UpperCAmelCase     :		Optional[Any]							     =		sum_aa(UpperCamelCase_	,				UpperCamelCase_		)
														UpperCAmelCase     :		int							     =		sum_aa(UpperCamelCase_	,				UpperCamelCase_		)

							UpperCAmelCase     :		Any							     =		reformat_hex(UpperCamelCase_		) + reformat_hex(UpperCamelCase_		) + reformat_hex(UpperCamelCase_		) + reformat_hex(UpperCamelCase_		)
							return digest


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


_a       =							'CompVis/stable-diffusion-v1-1'
_a       =							'CompVis/stable-diffusion-v1-2'
_a       =							'CompVis/stable-diffusion-v1-3'
_a       =							'CompVis/stable-diffusion-v1-4'




class 					_lowerCAmelCase  (	lowercase   ):







 """simple docstring"""







 def __init__(			self							:			Dict,					UpperCAmelCase__							:			AutoencoderKL,					UpperCAmelCase__							:			CLIPTextModel,					UpperCAmelCase__							:			CLIPTokenizer,					UpperCAmelCase__							:			UNetaDConditionModel,					UpperCAmelCase__							:			Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler],					UpperCAmelCase__							:			StableDiffusionSafetyChecker,					UpperCAmelCase__							:			CLIPImageProcessor,					UpperCAmelCase__							:			bool = True,					):
    super()._init_()

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


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


 def 					_lowercase (			self							:			List[str]	):
    self.enable_attention_slicing(UpperCAmelCase__	)


 @torch.no_grad()
 def 					_lowercase (			self							:			Optional[Any],					UpperCAmelCase__							:			Union[str, List[str]],					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_0,					UpperCAmelCase__							:			float = 7.5,					UpperCAmelCase__							:			Optional[Union[str, List[str]]] = None,					UpperCAmelCase__							:			Optional[int] = 1,					UpperCAmelCase__							:			float = 0.0,					UpperCAmelCase__							:			Optional[torch.Generator] = None,					UpperCAmelCase__							:			Optional[torch.FloatTensor] = None,					UpperCAmelCase__							:			Optional[str] = "pil",					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Optional[Callable[[int, int, torch.FloatTensor], None]] = None,					UpperCAmelCase__							:			int = 1,					**UpperCAmelCase__							:			Tuple,					):
    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 					_lowercase (			self							:			Tuple,					UpperCAmelCase__							:			Union[str, List[str]],					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_0,					UpperCAmelCase__							:			float = 7.5,					UpperCAmelCase__							:			Optional[Union[str, List[str]]] = None,					UpperCAmelCase__							:			Optional[int] = 1,					UpperCAmelCase__							:			float = 0.0,					UpperCAmelCase__							:			Optional[torch.Generator] = None,					UpperCAmelCase__							:			Optional[torch.FloatTensor] = None,					UpperCAmelCase__							:			Optional[str] = "pil",					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Optional[Callable[[int, int, torch.FloatTensor], None]] = None,					UpperCAmelCase__							:			int = 1,					**UpperCAmelCase__							:			str,					):
    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 					_lowercase (			self							:			str,					UpperCAmelCase__							:			Union[str, List[str]],					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_0,					UpperCAmelCase__							:			float = 7.5,					UpperCAmelCase__							:			Optional[Union[str, List[str]]] = None,					UpperCAmelCase__							:			Optional[int] = 1,					UpperCAmelCase__							:			float = 0.0,					UpperCAmelCase__							:			Optional[torch.Generator] = None,					UpperCAmelCase__							:			Optional[torch.FloatTensor] = None,					UpperCAmelCase__							:			Optional[str] = "pil",					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Optional[Callable[[int, int, torch.FloatTensor], None]] = None,					UpperCAmelCase__							:			int = 1,					**UpperCAmelCase__							:			Any,					):
    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 					_lowercase (			self							:			Union[str, Any],					UpperCAmelCase__							:			Union[str, List[str]],					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_0,					UpperCAmelCase__							:			float = 7.5,					UpperCAmelCase__							:			Optional[Union[str, List[str]]] = None,					UpperCAmelCase__							:			Optional[int] = 1,					UpperCAmelCase__							:			float = 0.0,					UpperCAmelCase__							:			Optional[torch.Generator] = None,					UpperCAmelCase__							:			Optional[torch.FloatTensor] = None,					UpperCAmelCase__							:			Optional[str] = "pil",					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Optional[Callable[[int, int, torch.FloatTensor], None]] = None,					UpperCAmelCase__							:			int = 1,					**UpperCAmelCase__							:			Optional[int],					):
    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 					_lowercase (			self							:			Optional[Any],					UpperCAmelCase__							:			Union[str, List[str]],					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_0,					UpperCAmelCase__							:			float = 7.5,					UpperCAmelCase__							:			Optional[Union[str, List[str]]] = None,					UpperCAmelCase__							:			Optional[int] = 1,					UpperCAmelCase__							:			float = 0.0,					UpperCAmelCase__							:			Optional[torch.Generator] = None,					UpperCAmelCase__							:			Optional[torch.FloatTensor] = None,					UpperCAmelCase__							:			Optional[str] = "pil",					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Optional[Callable[[int, int, torch.FloatTensor], None]] = None,					UpperCAmelCase__							:			int = 1,					**UpperCAmelCase__							:			str,					):
    __lowercase								=						"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
    __lowercase								=						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
    __lowercase								=						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
    __lowercase								=						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
    __lowercase								=						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]]	)




