



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__  :  Dict								=					'''CompVis/stable-diffusion-v1-1'''
A__  :  int								=					'''CompVis/stable-diffusion-v1-2'''
A__  :  List[Any]								=					'''CompVis/stable-diffusion-v1-3'''
A__  :  List[Any]								=					'''CompVis/stable-diffusion-v1-4'''



class 				__snake_case						(     UpperCamelCase_						):




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

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




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




							def    UpperCAmelCase__			(       self     :       Optional[int]):
									self.enable_attention_slicing(A_)




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










A__  :  Any								=					'''Tobias Carryer'''

from time import time



class 				__snake_case						:




							def __init__(       self     :       Any				,				A_     :       Tuple				,				A_     :       Dict				,				A_     :       Tuple				,				A_     :       str=int(time())):  # noqa: B008
									lowerCAmelCase_			:     int									= multiplier
									lowerCAmelCase_			:     int									= increment
									lowerCAmelCase_			:     str									= modulo
									lowerCAmelCase_			:     str									= seed







							def    UpperCAmelCase__			(       self     :       int):
									lowerCAmelCase_			:     Optional[int]									= (self.multiplier * self.seed + self.increment) % self.modulo
									return self.seed


if __name__ == "__main__":
						# Show the LCG in action.
						A__  :  Union[str, Any]								=					LinearCongruentialGenerator(166_4525, 10_1390_4223, 2 << 31)
						while True:
												print(lcg.next_number())





