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


_SCREAMING_SNAKE_CASE 		=      """CompVis/stable-diffusion-v1-1"""
_SCREAMING_SNAKE_CASE 		=      """CompVis/stable-diffusion-v1-2"""
_SCREAMING_SNAKE_CASE 		=      """CompVis/stable-diffusion-v1-3"""
_SCREAMING_SNAKE_CASE 		=      """CompVis/stable-diffusion-v1-4"""
class SCREAMING_SNAKE_CASE_		(      __lowerCAmelCase		):







   def __init__(     self						:						Tuple   ,   lowerCamelCase_						:						Any   ,   lowerCamelCase_						:						Tuple   ,   lowerCamelCase_						:						Optional[Any]   ,   lowerCamelCase_						:						Dict   ,   lowerCamelCase_						:						Union[str, Any]   ,   lowerCamelCase_						:						int   ,   lowerCamelCase_						:						Tuple   ,   lowerCamelCase_						:						int = True   ,   ):





    """simple docstring"""


    super()._init_()

    UpperCamelCase			  =      StableDiffusionPipeline.from_pretrained(lowerCamelCase_				)
    UpperCamelCase			  =      StableDiffusionPipeline.from_pretrained(lowerCamelCase_				)
    UpperCamelCase			  =      StableDiffusionPipeline.from_pretrained(lowerCamelCase_				)
    UpperCamelCase			  =      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						:						List[str]				):





    """simple docstring"""


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







   def 						lowerCamelCase_	(     self						:						Optional[Any]   ,   lowerCamelCase_						:						int = "auto"				):





    """simple docstring"""


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







   def 						lowerCamelCase_	(     self						:						Any				):





    """simple docstring"""


    self.enable_attention_slicing(lowerCamelCase_				)







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





    """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]   ,   lowerCamelCase_						:						Any   ,   lowerCamelCase_						:						Optional[int] = 512   ,   lowerCamelCase_						:						List[Any] = 512   ,   lowerCamelCase_						:						Optional[Any] = 50   ,   lowerCamelCase_						:						List[Any] = 7.5   ,   lowerCamelCase_						:						Optional[Any] = None   ,   lowerCamelCase_						:						Optional[int] = 1   ,   lowerCamelCase_						:						str = 0.0   ,   lowerCamelCase_						:						int = None   ,   lowerCamelCase_						:						Tuple = None   ,   lowerCamelCase_						:						Tuple = "pil"   ,   lowerCamelCase_						:						str = True   ,   lowerCamelCase_						:						Optional[Any] = None   ,   lowerCamelCase_						:						List[Any] = 1   ,   **lowerCamelCase_						:						Optional[int]   ,   ):





    """simple docstring"""


    UpperCamelCase			  =      '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
    UpperCamelCase			  =      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
    UpperCamelCase			  =      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
    UpperCamelCase			  =      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
    UpperCamelCase			  =      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_distilbert import DistilBertTokenizer


UpperCamelCase_    	=				logging.get_logger(__name__)

UpperCamelCase_    	=				{"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}

UpperCamelCase_    	=				{
    "vocab_file": {
        "distilbert-base-uncased": "https://huggingface.co/distilbert-base-uncased/resolve/main/vocab.txt",
        "distilbert-base-uncased-distilled-squad": (
            "https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/vocab.txt"
        ),
        "distilbert-base-cased": "https://huggingface.co/distilbert-base-cased/resolve/main/vocab.txt",
        "distilbert-base-cased-distilled-squad": (
            "https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/vocab.txt"
        ),
        "distilbert-base-german-cased": "https://huggingface.co/distilbert-base-german-cased/resolve/main/vocab.txt",
        "distilbert-base-multilingual-cased": (
            "https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/vocab.txt"
        ),
    },
    "tokenizer_file": {
        "distilbert-base-uncased": "https://huggingface.co/distilbert-base-uncased/resolve/main/tokenizer.json",
        "distilbert-base-uncased-distilled-squad": (
            "https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/tokenizer.json"
        ),
        "distilbert-base-cased": "https://huggingface.co/distilbert-base-cased/resolve/main/tokenizer.json",
        "distilbert-base-cased-distilled-squad": (
            "https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/tokenizer.json"
        ),
        "distilbert-base-german-cased": (
            "https://huggingface.co/distilbert-base-german-cased/resolve/main/tokenizer.json"
        ),
        "distilbert-base-multilingual-cased": (
            "https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/tokenizer.json"
        ),
    },
}

UpperCamelCase_    	=				{
    "distilbert-base-uncased": 5_1_2,
    "distilbert-base-uncased-distilled-squad": 5_1_2,
    "distilbert-base-cased": 5_1_2,
    "distilbert-base-cased-distilled-squad": 5_1_2,
    "distilbert-base-german-cased": 5_1_2,
    "distilbert-base-multilingual-cased": 5_1_2,
}


UpperCamelCase_    	=				{
    "distilbert-base-uncased": {"do_lower_case": True},
    "distilbert-base-uncased-distilled-squad": {"do_lower_case": True},
    "distilbert-base-cased": {"do_lower_case": False},
    "distilbert-base-cased-distilled-squad": {"do_lower_case": False},
    "distilbert-base-german-cased": {"do_lower_case": False},
    "distilbert-base-multilingual-cased": {"do_lower_case": False},
}






class 							_a				(			SCREAMING_SNAKE_CASE ):





       '''simple docstring'''






       A						:				List[Any]        =						VOCAB_FILES_NAMES
       A						:				Dict        =						PRETRAINED_VOCAB_FILES_MAP
       A						:				Optional[int]        =						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       A						:				Optional[Any]        =						PRETRAINED_INIT_CONFIGURATION
       A						:				Optional[int]        =						['''input_ids''', '''attention_mask''']
       A						:				List[Any]        =						DistilBertTokenizer







       def __init__(      self,							A=None,							A=None,							A=True,							A="[UNK]",							A="[SEP]",							A="[PAD]",							A="[CLS]",							A="[MASK]",							A=True,							A=None,							**A,							):







             '''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,							)

             SCREAMING_SNAKE_CASE   :      Optional[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
             ):
                   SCREAMING_SNAKE_CASE   :      Union[str, Any]    					=						getattr(A,							normalizer_state.pop('type'  )  )
                   SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						do_lower_case
                   SCREAMING_SNAKE_CASE   :      List[str]    					=						strip_accents
                   SCREAMING_SNAKE_CASE   :      List[str]    					=						tokenize_chinese_chars
                   SCREAMING_SNAKE_CASE   :      Dict    					=						normalizer_class(**A  )

             SCREAMING_SNAKE_CASE   :      Union[str, Any]    					=						do_lower_case







       def        UpperCamelCase_							(      self,							A,							A=None  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      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,							A,							A = None  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      List[str]    					=						[self.sep_token_id]
             SCREAMING_SNAKE_CASE   :      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,							A,							A = None  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      List[str]    					=						self._tokenizer.model.save(A,							name=A  )
             return tuple(A  )


