




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




class     snake_case__							(_UpperCamelCase   ):
				"""simple docstring"""



				def __init__(      self				:     str					,      __lowerCamelCase				:     AutoencoderKL					,      __lowerCamelCase				:     CLIPTextModel					,      __lowerCamelCase				:     CLIPTokenizer					,      __lowerCamelCase				:     UNetaDConditionModel					,      __lowerCamelCase				:     Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]					,      __lowerCamelCase				:     StableDiffusionSafetyChecker					,      __lowerCamelCase				:     CLIPImageProcessor					,      __lowerCamelCase				:     bool = True					,      )					->     List[Any]:
							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 							__UpperCAmelCase							(      self				:     Optional[int]							)					->     Dict[str, Any]:
							return {k: getattr(self					,      __lowerCamelCase							) for k in self.config.keys() if not k.startswith("_"							)}





				def 							__UpperCAmelCase							(      self				:     List[Any]					,      __lowerCamelCase				:     Optional[Union[str, int]] = "auto"							)					->     Dict:
							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 							__UpperCAmelCase							(      self				:     List[str]							)					->     List[str]:
							self.enable_attention_slicing(__lowerCamelCase							)





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












"""simple docstring"""


import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ....tokenization_utils_fast import PreTrainedTokenizerFast
from ....utils import logging
from .tokenization_retribert import RetriBertTokenizer


A_						=				logging.get_logger(__name__)

A_						=				{'''vocab_file''': '''vocab.txt''', '''tokenizer_file''': '''tokenizer.json'''}

A_						=				{
    '''vocab_file''': {
        '''yjernite/retribert-base-uncased''': (
            '''https://huggingface.co/yjernite/retribert-base-uncased/resolve/main/vocab.txt'''
        ),
    },
    '''tokenizer_file''': {
        '''yjernite/retribert-base-uncased''': (
            '''https://huggingface.co/yjernite/retribert-base-uncased/resolve/main/tokenizer.json'''
        ),
    },
}

A_						=				{
    '''yjernite/retribert-base-uncased''': 5_12,
}


A_						=				{
    '''yjernite/retribert-base-uncased''': {'''do_lower_case''': True},
}






class 					lowercase(     __a ):







 '''simple docstring'''





 lowercase__ 					=					VOCAB_FILES_NAMES
 lowercase__ 					=					PRETRAINED_VOCAB_FILES_MAP
 lowercase__ 					=					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 lowercase__ 					=					PRETRAINED_INIT_CONFIGURATION
 lowercase__ 					=					RetriBertTokenizer
 lowercase__ 					=					["input_ids", "attention_mask"]


 def __init__(				self:		int,      a_:		int=None,      a_:		Dict=None,      a_:		Any=True,      a_:		int="[UNK]",      a_:		Any="[SEP]",      a_:		List[Any]="[PAD]",      a_:		List[Any]="[CLS]",      a_:		str="[MASK]",      a_:		Dict=True,      a_:		Optional[int]=None,      **a_:		Tuple,      ):




   '''simple docstring'''



   super().__init__(
       a_,      tokenizer_file=a_,      do_lower_case=a_,      unk_token=a_,      sep_token=a_,      pad_token=a_,      cls_token=a_,      mask_token=a_,      tokenize_chinese_chars=a_,      strip_accents=a_,      **a_,      )

   _snake_case							:		List[Any]								=  json.loads(self.backend_tokenizer.normalizer.__getstate__()		)
   if (
       normalizer_state.get("""lowercase""",      a_		) != do_lower_case
       or normalizer_state.get("""strip_accents""",      a_		) != strip_accents
       or normalizer_state.get("""handle_chinese_chars""",      a_		) != tokenize_chinese_chars
   ):
     _snake_case							:		Dict								=  getattr(a_,      normalizer_state.pop("""type"""		)		)
     _snake_case							:		List[Any]								=  do_lower_case
     _snake_case							:		List[str]								=  strip_accents
     _snake_case							:		Tuple								=  tokenize_chinese_chars
     _snake_case							:		Tuple								=  normalizer_class(**a_		)

   _snake_case							:		List[str]								=  do_lower_case


 def  UpperCamelCase_   (				self:		Any,      a_:		str,      a_:		Optional[int]=None		):




   '''simple docstring'''



   _snake_case							:		Optional[Any]								=  [self.cls_token_id] + token_ids_a + [self.sep_token_id]

   if token_ids_a:
     output += token_ids_a + [self.sep_token_id]

   return output


 def  UpperCamelCase_   (				self:		List[str],      a_:		List[int],      a_:		Optional[List[int]] = None		):




   '''simple docstring'''



   _snake_case							:		Union[str, Any]								=  [self.sep_token_id]
   _snake_case							:		List[str]								=  [self.cls_token_id]
   if token_ids_a is None:
     return len(cls + token_ids_a + sep		) * [0]
   return len(cls + token_ids_a + sep		) * [0] + len(token_ids_a + sep		) * [1]


 def  UpperCamelCase_   (				self:		Dict,      a_:		str,      a_:		Optional[str] = None		):




   '''simple docstring'''



   _snake_case							:		Union[str, Any]								=  self._tokenizer.model.save(a_,      name=a_		)
   return tuple(a_		)


