



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


__snake_case							:     Union[str, Any]   =					'CompVis/stable-diffusion-v1-1'
__snake_case							:     str   =					'CompVis/stable-diffusion-v1-2'
__snake_case							:     List[Any]   =					'CompVis/stable-diffusion-v1-3'
__snake_case							:     int   =					'CompVis/stable-diffusion-v1-4'



class     A__     (						__SCREAMING_SNAKE_CASE							):




	'''simple docstring'''





	def __init__(  self:	List[str] ,    _SCREAMING_SNAKE_CASE:	Optional[int] ,    _SCREAMING_SNAKE_CASE:	Optional[int] ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	Any ,    _SCREAMING_SNAKE_CASE:	Any ,    _SCREAMING_SNAKE_CASE:	Optional[int] ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	Optional[int] = True ,    )       -> Any:

				"""simple docstring"""

				super()._init_()

				__lowerCAmelCase				= StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase				= StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase				= StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase				= StableDiffusionPipeline(
				    vae=_SCREAMING_SNAKE_CASE ,    text_encoder=_SCREAMING_SNAKE_CASE ,    tokenizer=_SCREAMING_SNAKE_CASE ,    unet=_SCREAMING_SNAKE_CASE ,    scheduler=_SCREAMING_SNAKE_CASE ,    safety_checker=_SCREAMING_SNAKE_CASE ,    feature_extractor=_SCREAMING_SNAKE_CASE ,    requires_safety_checker=_SCREAMING_SNAKE_CASE ,    )

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

	@property
	def 							_SCREAMING_SNAKE_CASE     (  self:	Union[str, Any])       -> Dict[str, Any]:

				"""simple docstring"""

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

	def 							_SCREAMING_SNAKE_CASE     (  self:	Any ,    _SCREAMING_SNAKE_CASE:	List[str] = "auto")       -> Optional[Any]:

				"""simple docstring"""

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

	def 							_SCREAMING_SNAKE_CASE     (  self:	int)       -> Tuple:

				"""simple docstring"""

				self.enable_attention_slicing(_SCREAMING_SNAKE_CASE)

	@torch.no_grad()
	def 							_SCREAMING_SNAKE_CASE     (  self:	int ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	str = 512 ,    _SCREAMING_SNAKE_CASE:	Union[str, Any] = 512 ,    _SCREAMING_SNAKE_CASE:	int = 50 ,    _SCREAMING_SNAKE_CASE:	Dict = 7.5 ,    _SCREAMING_SNAKE_CASE:	Optional[int] = None ,    _SCREAMING_SNAKE_CASE:	Optional[Any] = 1 ,    _SCREAMING_SNAKE_CASE:	Union[str, Any] = 0.0 ,    _SCREAMING_SNAKE_CASE:	List[Any] = None ,    _SCREAMING_SNAKE_CASE:	int = None ,    _SCREAMING_SNAKE_CASE:	str = "pil" ,    _SCREAMING_SNAKE_CASE:	List[Any] = True ,    _SCREAMING_SNAKE_CASE:	Tuple = None ,    _SCREAMING_SNAKE_CASE:	Optional[int] = 1 ,    **_SCREAMING_SNAKE_CASE:	Dict ,    )       -> List[Any]:

				"""simple docstring"""

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

	@torch.no_grad()
	def 							_SCREAMING_SNAKE_CASE     (  self:	List[str] ,    _SCREAMING_SNAKE_CASE:	Optional[int] ,    _SCREAMING_SNAKE_CASE:	Union[str, Any] = 512 ,    _SCREAMING_SNAKE_CASE:	Optional[Any] = 512 ,    _SCREAMING_SNAKE_CASE:	str = 50 ,    _SCREAMING_SNAKE_CASE:	Any = 7.5 ,    _SCREAMING_SNAKE_CASE:	int = None ,    _SCREAMING_SNAKE_CASE:	Dict = 1 ,    _SCREAMING_SNAKE_CASE:	Any = 0.0 ,    _SCREAMING_SNAKE_CASE:	Union[str, Any] = None ,    _SCREAMING_SNAKE_CASE:	Tuple = None ,    _SCREAMING_SNAKE_CASE:	Any = "pil" ,    _SCREAMING_SNAKE_CASE:	Optional[int] = True ,    _SCREAMING_SNAKE_CASE:	Union[str, Any] = None ,    _SCREAMING_SNAKE_CASE:	Union[str, Any] = 1 ,    **_SCREAMING_SNAKE_CASE:	List[Any] ,    )       -> List[Any]:

				"""simple docstring"""

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

	@torch.no_grad()
	def 							_SCREAMING_SNAKE_CASE     (  self:	Tuple ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	Optional[int] = 512 ,    _SCREAMING_SNAKE_CASE:	Dict = 512 ,    _SCREAMING_SNAKE_CASE:	str = 50 ,    _SCREAMING_SNAKE_CASE:	str = 7.5 ,    _SCREAMING_SNAKE_CASE:	Any = None ,    _SCREAMING_SNAKE_CASE:	List[Any] = 1 ,    _SCREAMING_SNAKE_CASE:	Dict = 0.0 ,    _SCREAMING_SNAKE_CASE:	Optional[int] = None ,    _SCREAMING_SNAKE_CASE:	int = None ,    _SCREAMING_SNAKE_CASE:	Optional[int] = "pil" ,    _SCREAMING_SNAKE_CASE:	List[Any] = True ,    _SCREAMING_SNAKE_CASE:	List[str] = None ,    _SCREAMING_SNAKE_CASE:	str = 1 ,    **_SCREAMING_SNAKE_CASE:	int ,    )       -> Dict:

				"""simple docstring"""

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

	@torch.no_grad()
	def 							_SCREAMING_SNAKE_CASE     (  self:	Union[str, Any] ,    _SCREAMING_SNAKE_CASE:	Dict ,    _SCREAMING_SNAKE_CASE:	Any = 512 ,    _SCREAMING_SNAKE_CASE:	str = 512 ,    _SCREAMING_SNAKE_CASE:	int = 50 ,    _SCREAMING_SNAKE_CASE:	Optional[int] = 7.5 ,    _SCREAMING_SNAKE_CASE:	Tuple = None ,    _SCREAMING_SNAKE_CASE:	Dict = 1 ,    _SCREAMING_SNAKE_CASE:	Any = 0.0 ,    _SCREAMING_SNAKE_CASE:	Any = None ,    _SCREAMING_SNAKE_CASE:	Optional[int] = None ,    _SCREAMING_SNAKE_CASE:	List[str] = "pil" ,    _SCREAMING_SNAKE_CASE:	List[str] = True ,    _SCREAMING_SNAKE_CASE:	str = None ,    _SCREAMING_SNAKE_CASE:	Dict = 1 ,    **_SCREAMING_SNAKE_CASE:	Optional[int] ,    )       -> str:

				"""simple docstring"""

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







	@torch.no_grad()
	def 							_SCREAMING_SNAKE_CASE     (  self:	Tuple ,    _SCREAMING_SNAKE_CASE:	Any ,    _SCREAMING_SNAKE_CASE:	List[str] = 512 ,    _SCREAMING_SNAKE_CASE:	Optional[Any] = 512 ,    _SCREAMING_SNAKE_CASE:	Optional[Any] = 50 ,    _SCREAMING_SNAKE_CASE:	Any = 7.5 ,    _SCREAMING_SNAKE_CASE:	Tuple = None ,    _SCREAMING_SNAKE_CASE:	str = 1 ,    _SCREAMING_SNAKE_CASE:	Optional[int] = 0.0 ,    _SCREAMING_SNAKE_CASE:	List[str] = None ,    _SCREAMING_SNAKE_CASE:	Optional[Any] = None ,    _SCREAMING_SNAKE_CASE:	Tuple = "pil" ,    _SCREAMING_SNAKE_CASE:	Tuple = True ,    _SCREAMING_SNAKE_CASE:	Dict = None ,    _SCREAMING_SNAKE_CASE:	str = 1 ,    **_SCREAMING_SNAKE_CASE:	int ,    )       -> List[str]:

				"""simple docstring"""

				__lowerCAmelCase				= "cuda" if torch.cuda.is_available() else "cpu"
				self.to(_SCREAMING_SNAKE_CASE)

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

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

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

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

				# 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"""






import string
from math import logaa


def     _lowercase       (						__snake_case      ,__snake_case			)		->     int:
			__lowerCAmelCase   :						int				= document.translate(
			    str.maketrans(""      ,""      ,string.punctuation			)			).replace("\n"      ,""			)
			__lowerCAmelCase   :						Dict				= document_without_punctuation.split(" "			)  # word tokenization
			return len([word for word in tokenize_document if word.lower() == term.lower()]			)


def     _lowercase       (						__snake_case      ,__snake_case			)		->     tuple[int, int]:
			__lowerCAmelCase   :						Optional[Any]				= corpus.lower().translate(
			    str.maketrans(""      ,""      ,string.punctuation			)			)  # strip all punctuation and replace it with ''
			__lowerCAmelCase   :						List[str]				= corpus_without_punctuation.split("\n"			)
			__lowerCAmelCase   :						str				= term.lower()
			return (len([doc for doc in docs if term in doc]			), len(__snake_case			))


def     _lowercase       (						__snake_case      ,__snake_case      ,__snake_case=False			)		->     float:
			if smoothing:
						if n == 0:
									raise ValueError("log10(0) is undefined."			)
						return round(1 + logaa(n / (1 + df)			)      ,3			)

			if df == 0:
						raise ZeroDivisionError("df must be > 0"			)
			elif n == 0:
						raise ValueError("log10(0) is undefined."			)
			return round(logaa(n / df			)      ,3			)





def     _lowercase       (						__snake_case      ,__snake_case			)		->     float:
			return round(tf * idf      ,3			)