
"""simple docstring"""




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_A			:       str   		=       {
    """configuration_lxmert""": ["""LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """LxmertConfig"""],
    """tokenization_lxmert""": ["""LxmertTokenizer"""],
}

try:
   if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _A			:       Optional[Any]   		=       ["""LxmertTokenizerFast"""]

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _A			:       Dict   		=       [
       """LxmertEncoder""",
       """LxmertForPreTraining""",
       """LxmertForQuestionAnswering""",
       """LxmertModel""",
       """LxmertPreTrainedModel""",
       """LxmertVisualFeatureEncoder""",
       """LxmertXLayer""",
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _A			:       Dict   		=       [
       """TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """TFLxmertForPreTraining""",
       """TFLxmertMainLayer""",
       """TFLxmertModel""",
       """TFLxmertPreTrainedModel""",
       """TFLxmertVisualFeatureEncoder""",
   ]


if TYPE_CHECKING:
   from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
   from .tokenization_lxmert import LxmertTokenizer

   try:
      if not is_tokenizers_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_lxmert_fast import LxmertTokenizerFast

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_lxmert import (
          LxmertEncoder,
          LxmertForPreTraining,
          LxmertForQuestionAnswering,
          LxmertModel,
          LxmertPreTrainedModel,
          LxmertVisualFeatureEncoder,
          LxmertXLayer,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_lxmert import (
          TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFLxmertForPreTraining,
          TFLxmertMainLayer,
          TFLxmertModel,
          TFLxmertPreTrainedModel,
          TFLxmertVisualFeatureEncoder,
      )

else:
   import sys

   _A			:       Tuple   		=       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




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


_A			:       int   		=       """CompVis/stable-diffusion-v1-1"""
_A			:       Any   		=       """CompVis/stable-diffusion-v1-2"""
_A			:       Optional[int]   		=       """CompVis/stable-diffusion-v1-3"""
_A			:       Union[str, Any]   		=       """CompVis/stable-diffusion-v1-4"""

class 		a__						(      a_						):
   def __init__(			self	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a = True	,    ):
          super()._init_()

          lowercase    :				Optional[Any]       		=							StableDiffusionPipeline.from_pretrained(_a				)
          lowercase    :				str       		=							StableDiffusionPipeline.from_pretrained(_a				)
          lowercase    :				Dict       		=							StableDiffusionPipeline.from_pretrained(_a				)
          lowercase    :				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 			__magic_name__			(			self				):
          return {k: getattr(self	,    _a				) for k in self.config.keys() if not k.startswith("_"				)}
   def 			__magic_name__			(			self	,    _a = "auto"				):
          if slice_size == "auto":
                 # half the attention head size is usually a good trade-off between
                 # speed and memory
                 lowercase    :				str       		=							self.unet.config.attention_head_dim // 2
          self.unet.set_attention_slice(_a				)
   def 			__magic_name__			(			self				):
          self.enable_attention_slicing(_a				)
   @torch.no_grad()
   def 			__magic_name__			(			self	,    _a	,    _a = 512	,    _a = 512	,    _a = 50	,    _a = 7.5	,    _a = None	,    _a = 1	,    _a = 0.0	,    _a = None	,    _a = None	,    _a = "pil"	,    _a = True	,    _a = None	,    _a = 1	,    **_a	,    ):
          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 			__magic_name__			(			self	,    _a	,    _a = 512	,    _a = 512	,    _a = 50	,    _a = 7.5	,    _a = None	,    _a = 1	,    _a = 0.0	,    _a = None	,    _a = None	,    _a = "pil"	,    _a = True	,    _a = None	,    _a = 1	,    **_a	,    ):
          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 			__magic_name__			(			self	,    _a	,    _a = 512	,    _a = 512	,    _a = 50	,    _a = 7.5	,    _a = None	,    _a = 1	,    _a = 0.0	,    _a = None	,    _a = None	,    _a = "pil"	,    _a = True	,    _a = None	,    _a = 1	,    **_a	,    ):
          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 			__magic_name__			(			self	,    _a	,    _a = 512	,    _a = 512	,    _a = 50	,    _a = 7.5	,    _a = None	,    _a = 1	,    _a = 0.0	,    _a = None	,    _a = None	,    _a = "pil"	,    _a = True	,    _a = None	,    _a = 1	,    **_a	,    ):
          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 			__magic_name__			(			self	,    _a	,    _a = 512	,    _a = 512	,    _a = 50	,    _a = 7.5	,    _a = None	,    _a = 1	,    _a = 0.0	,    _a = None	,    _a = None	,    _a = "pil"	,    _a = True	,    _a = None	,    _a = 1	,    **_a	,    ):
          lowercase    :				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
          lowercase    :				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 first result from Stable Diffusion Checkpoint v1.2
          lowercase    :				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.3
          lowercase    :				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
          lowercase    :				Optional[int]       		=							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]]				)


