



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

class    _A	(     __UpperCAmelCase   ):



							def __init__(		self							:					str					,		__SCREAMING_SNAKE_CASE							:					AutoencoderKL					,		__SCREAMING_SNAKE_CASE							:					CLIPTextModel					,		__SCREAMING_SNAKE_CASE							:					CLIPTokenizer					,		__SCREAMING_SNAKE_CASE							:					UNetaDConditionModel					,		__SCREAMING_SNAKE_CASE							:					Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]					,		__SCREAMING_SNAKE_CASE							:					StableDiffusionSafetyChecker					,		__SCREAMING_SNAKE_CASE							:					CLIPImageProcessor					,		__SCREAMING_SNAKE_CASE							:					bool = True					,		):


											'''simple docstring'''

											super()._init_()

											__a							=    StableDiffusionPipeline.from_pretrained(lowerCAmelCase__)
											__a							=    StableDiffusionPipeline.from_pretrained(lowerCAmelCase__)
											__a							=    StableDiffusionPipeline.from_pretrained(lowerCAmelCase__)
											__a							=    StableDiffusionPipeline(
											    vae=lowerCAmelCase__					,		text_encoder=lowerCAmelCase__					,		tokenizer=lowerCAmelCase__					,		unet=lowerCAmelCase__					,		scheduler=lowerCAmelCase__					,		safety_checker=lowerCAmelCase__					,		feature_extractor=lowerCAmelCase__					,		requires_safety_checker=lowerCAmelCase__					,		)

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



							@property
							def 		_lowerCamelCase      (		self							:					int):


											'''simple docstring'''

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



							def 		_lowerCamelCase      (		self							:					Tuple					,		__SCREAMING_SNAKE_CASE							:					Optional[Union[str, int]] = "auto"):


											'''simple docstring'''

											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(lowerCAmelCase__)



							def 		_lowerCamelCase      (		self							:					List[str]):


											'''simple docstring'''

											self.enable_attention_slicing(lowerCAmelCase__)



							@torch.no_grad()
							def 		_lowerCamelCase      (		self							:					List[str]					,		__SCREAMING_SNAKE_CASE							:					Union[str, List[str]]					,		__SCREAMING_SNAKE_CASE							:					int = 512					,		__SCREAMING_SNAKE_CASE							:					int = 512					,		__SCREAMING_SNAKE_CASE							:					int = 50					,		__SCREAMING_SNAKE_CASE							:					float = 7.5					,		__SCREAMING_SNAKE_CASE							:					Optional[Union[str, List[str]]] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[int] = 1					,		__SCREAMING_SNAKE_CASE							:					float = 0.0					,		__SCREAMING_SNAKE_CASE							:					Optional[torch.Generator] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[torch.FloatTensor] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[str] = "pil"					,		__SCREAMING_SNAKE_CASE							:					bool = True					,		__SCREAMING_SNAKE_CASE							:					Optional[Callable[[int, int, torch.FloatTensor], None]] = None					,		__SCREAMING_SNAKE_CASE							:					int = 1					,		**__SCREAMING_SNAKE_CASE							:					Union[str, Any]					,		):


											'''simple docstring'''

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



							@torch.no_grad()
							def 		_lowerCamelCase      (		self							:					List[Any]					,		__SCREAMING_SNAKE_CASE							:					Union[str, List[str]]					,		__SCREAMING_SNAKE_CASE							:					int = 512					,		__SCREAMING_SNAKE_CASE							:					int = 512					,		__SCREAMING_SNAKE_CASE							:					int = 50					,		__SCREAMING_SNAKE_CASE							:					float = 7.5					,		__SCREAMING_SNAKE_CASE							:					Optional[Union[str, List[str]]] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[int] = 1					,		__SCREAMING_SNAKE_CASE							:					float = 0.0					,		__SCREAMING_SNAKE_CASE							:					Optional[torch.Generator] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[torch.FloatTensor] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[str] = "pil"					,		__SCREAMING_SNAKE_CASE							:					bool = True					,		__SCREAMING_SNAKE_CASE							:					Optional[Callable[[int, int, torch.FloatTensor], None]] = None					,		__SCREAMING_SNAKE_CASE							:					int = 1					,		**__SCREAMING_SNAKE_CASE							:					Any					,		):


											'''simple docstring'''

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



							@torch.no_grad()
							def 		_lowerCamelCase      (		self							:					str					,		__SCREAMING_SNAKE_CASE							:					Union[str, List[str]]					,		__SCREAMING_SNAKE_CASE							:					int = 512					,		__SCREAMING_SNAKE_CASE							:					int = 512					,		__SCREAMING_SNAKE_CASE							:					int = 50					,		__SCREAMING_SNAKE_CASE							:					float = 7.5					,		__SCREAMING_SNAKE_CASE							:					Optional[Union[str, List[str]]] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[int] = 1					,		__SCREAMING_SNAKE_CASE							:					float = 0.0					,		__SCREAMING_SNAKE_CASE							:					Optional[torch.Generator] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[torch.FloatTensor] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[str] = "pil"					,		__SCREAMING_SNAKE_CASE							:					bool = True					,		__SCREAMING_SNAKE_CASE							:					Optional[Callable[[int, int, torch.FloatTensor], None]] = None					,		__SCREAMING_SNAKE_CASE							:					int = 1					,		**__SCREAMING_SNAKE_CASE							:					int					,		):


											'''simple docstring'''

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



							@torch.no_grad()
							def 		_lowerCamelCase      (		self							:					int					,		__SCREAMING_SNAKE_CASE							:					Union[str, List[str]]					,		__SCREAMING_SNAKE_CASE							:					int = 512					,		__SCREAMING_SNAKE_CASE							:					int = 512					,		__SCREAMING_SNAKE_CASE							:					int = 50					,		__SCREAMING_SNAKE_CASE							:					float = 7.5					,		__SCREAMING_SNAKE_CASE							:					Optional[Union[str, List[str]]] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[int] = 1					,		__SCREAMING_SNAKE_CASE							:					float = 0.0					,		__SCREAMING_SNAKE_CASE							:					Optional[torch.Generator] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[torch.FloatTensor] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[str] = "pil"					,		__SCREAMING_SNAKE_CASE							:					bool = True					,		__SCREAMING_SNAKE_CASE							:					Optional[Callable[[int, int, torch.FloatTensor], None]] = None					,		__SCREAMING_SNAKE_CASE							:					int = 1					,		**__SCREAMING_SNAKE_CASE							:					int					,		):


											'''simple docstring'''

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





							@torch.no_grad()
							def 		_lowerCamelCase      (		self							:					Optional[Any]					,		__SCREAMING_SNAKE_CASE							:					Union[str, List[str]]					,		__SCREAMING_SNAKE_CASE							:					int = 512					,		__SCREAMING_SNAKE_CASE							:					int = 512					,		__SCREAMING_SNAKE_CASE							:					int = 50					,		__SCREAMING_SNAKE_CASE							:					float = 7.5					,		__SCREAMING_SNAKE_CASE							:					Optional[Union[str, List[str]]] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[int] = 1					,		__SCREAMING_SNAKE_CASE							:					float = 0.0					,		__SCREAMING_SNAKE_CASE							:					Optional[torch.Generator] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[torch.FloatTensor] = None					,		__SCREAMING_SNAKE_CASE							:					Optional[str] = "pil"					,		__SCREAMING_SNAKE_CASE							:					bool = True					,		__SCREAMING_SNAKE_CASE							:					Optional[Callable[[int, int, torch.FloatTensor], None]] = None					,		__SCREAMING_SNAKE_CASE							:					int = 1					,		**__SCREAMING_SNAKE_CASE							:					str					,		):


											'''simple docstring'''

											__a							=    "cuda" if torch.cuda.is_available() else "cpu"
											self.to(lowerCAmelCase__)

											# 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=lowerCAmelCase__					,		height=lowerCAmelCase__					,		width=lowerCAmelCase__					,		num_inference_steps=lowerCAmelCase__					,		guidance_scale=lowerCAmelCase__					,		negative_prompt=lowerCAmelCase__					,		num_images_per_prompt=lowerCAmelCase__					,		eta=lowerCAmelCase__					,		generator=lowerCAmelCase__					,		latents=lowerCAmelCase__					,		output_type=lowerCAmelCase__					,		return_dict=lowerCAmelCase__					,		callback=lowerCAmelCase__					,		callback_steps=lowerCAmelCase__					,		**lowerCAmelCase__					,		)

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

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

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

											# 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 					__snake_case     (      _UpperCAmelCase       ,			_UpperCAmelCase    ):

    def get_matched_characters(_UpperCAmelCase       ,			_UpperCAmelCase    ) -> str:
        __a							=    []
        __a							=    min(len(_stra    )       ,			len(_stra    )    ) // 2
        for i, l in enumerate(_stra    ):
            __a							=    int(max(0       ,			i - limit    )    )
            __a							=    int(min(i + limit + 1       ,			len(_stra    )    )    )
            if l in _stra[left:right]:
                matched.append(_UpperCAmelCase    )
                __a							=    f'{_stra[0:_stra.index(_UpperCAmelCase    )]} {_stra[_stra.index(_UpperCAmelCase    ) + 1:]}'

        return "".join(_UpperCAmelCase    )

    # matching characters
    __a							=    get_matched_characters(_UpperCAmelCase       ,			_UpperCAmelCase    )
    __a							=    get_matched_characters(_UpperCAmelCase       ,			_UpperCAmelCase    )
    __a							=    len(_UpperCAmelCase    )

    # transposition
    __a							=    (
        len([(ca, ca) for ca, ca in zip(_UpperCAmelCase       ,			_UpperCAmelCase    ) if ca != ca]    ) // 2
    )

    if not match_count:
        __a							=    0.0
    else:
        __a							=    (
            1
            / 3
            * (
                match_count / len(_UpperCAmelCase    )
                + match_count / len(_UpperCAmelCase    )
                + (match_count - transpositions) / match_count
            )
        )

    # common prefix up to 4 characters
    __a							=    0
    for ca, ca in zip(stra[:4]       ,			stra[:4]    ):
        if ca == ca:
            prefix_len += 1
        else:
            break

    return jaro + 0.1 * prefix_len * (1 - jaro)


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 print(jaro_winkler('''hello''', '''world'''))





