





'''simple docstring'''

from typing import Any, Callable, Dict, List, Optional, Union

import PIL.Image
import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionImgaImgPipeline,
    StableDiffusionInpaintPipelineLegacy,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.configuration_utils import FrozenDict
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
from diffusers.utils import deprecate, logging


lowercase_         =			logging.get_logger(__name__)  # pylint: disable=invalid-name


class  a_					(    snake_case_	):

    '''simple docstring'''
    UpperCamelCase			   =			['''safety_checker''', '''feature_extractor''']


    def __init__(		self			,		A			,		A			,		A			,		A			,		A			,		A			,		A			,		A = True			,		)		->       Dict:
        super().__init__()
        if hasattr(scheduler.config			,		"""steps_offset"""	) and scheduler.config.steps_offset != 1:
            _SCREAMING_SNAKE_CASE     =      (
                f'The configuration file of this scheduler: {scheduler} is outdated. `steps_offset`'
                f' should be set to 1 instead of {scheduler.config.steps_offset}. Please make sure '
                """to update the config accordingly as leaving `steps_offset` might led to incorrect results"""
                """ in future versions. If you have downloaded this checkpoint from the Hugging Face Hub,"""
                """ it would be very nice if you could open a Pull request for the `scheduler/scheduler_config.json`"""
                """ file"""
            )
            deprecate("""steps_offset!=1"""			,		"""1.0.0"""			,		A			,		standard_warn=A	)
            _SCREAMING_SNAKE_CASE     =      dict(scheduler.config	)
            _SCREAMING_SNAKE_CASE     =      1
            _SCREAMING_SNAKE_CASE     =      FrozenDict(A	)

        self.register_modules(
            vae=A			,		text_encoder=A			,		tokenizer=A			,		unet=A			,		scheduler=A			,		safety_checker=A			,		feature_extractor=A			,		)
        self.register_to_config(requires_safety_checker=A	)


    @property
    def       snake_case_(		self	)		->       Dict[str, Any]:
        return {k: getattr(self			,		A	) for k in self.config.keys() if not k.startswith("""_"""	)}


    def       snake_case_(		self			,		A = "auto"	)		->       List[Any]:
        if slice_size == "auto":
            # half the attention head size is usually a good trade-off between
            # speed and memory
            _SCREAMING_SNAKE_CASE     =      self.unet.config.attention_head_dim // 2
        self.unet.set_attention_slice(A	)


    def       snake_case_(		self	)		->       Any:
        self.enable_attention_slicing(A	)


    @torch.no_grad()
    def       snake_case_(		self			,		A			,		A			,		A			,		A = 0.8			,		A = 50			,		A = 7.5			,		A = None			,		A = 1			,		A = 0.0			,		A = None			,		A = "pil"			,		A = True			,		A = None			,		A = 1			,		)		->       Dict:
        # For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
        return StableDiffusionInpaintPipelineLegacy(**self.components	)(
            prompt=A			,		image=A			,		mask_image=A			,		strength=A			,		num_inference_steps=A			,		guidance_scale=A			,		negative_prompt=A			,		num_images_per_prompt=A			,		eta=A			,		generator=A			,		output_type=A			,		return_dict=A			,		callback=A			,		)


    @torch.no_grad()
    def       snake_case_(		self			,		A			,		A			,		A = 0.8			,		A = 50			,		A = 7.5			,		A = None			,		A = 1			,		A = 0.0			,		A = None			,		A = "pil"			,		A = True			,		A = None			,		A = 1			,		**A			,		)		->       Tuple:
        # For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
        return StableDiffusionImgaImgPipeline(**self.components	)(
            prompt=A			,		image=A			,		strength=A			,		num_inference_steps=A			,		guidance_scale=A			,		negative_prompt=A			,		num_images_per_prompt=A			,		eta=A			,		generator=A			,		output_type=A			,		return_dict=A			,		callback=A			,		callback_steps=A			,		)





    @torch.no_grad()
    def       snake_case_(		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			,		)		->       List[Any]:
        # For more information on how this function https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionPipeline
        return StableDiffusionPipeline(**self.components	)(
            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			,		)










'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


lowercase_         =			{
    """configuration_esm""": ["""ESM_PRETRAINED_CONFIG_ARCHIVE_MAP""", """EsmConfig"""],
    """tokenization_esm""": ["""EsmTokenizer"""],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase_         =			[
          """ESM_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """EsmForMaskedLM""",
          """EsmForSequenceClassification""",
          """EsmForTokenClassification""",
          """EsmModel""",
          """EsmPreTrainedModel""",
      ]
      lowercase_         =			["""EsmForProteinFolding""", """EsmFoldPreTrainedModel"""]

try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase_         =			[
          """TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """TFEsmForMaskedLM""",
          """TFEsmForSequenceClassification""",
          """TFEsmForTokenClassification""",
          """TFEsmModel""",
          """TFEsmPreTrainedModel""",
      ]

if TYPE_CHECKING:
      from .configuration_esm import ESM_PRETRAINED_CONFIG_ARCHIVE_MAP, EsmConfig
      from .tokenization_esm import EsmTokenizer

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_esm import (
                ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
                EsmForMaskedLM,
                EsmForSequenceClassification,
                EsmForTokenClassification,
                EsmModel,
                EsmPreTrainedModel,
            )
            from .modeling_esmfold import EsmFoldPreTrainedModel, EsmForProteinFolding

      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_esm import (
                TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
                TFEsmForMaskedLM,
                TFEsmForSequenceClassification,
                TFEsmForTokenClassification,
                TFEsmModel,
                TFEsmPreTrainedModel,
            )


else:
      import sys

      lowercase_         =			_LazyModule(__name__, globals()["""__file__"""], _import_structure)



