





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


A__       :     List[str]          =logging.get_logger(__name__)  # pylint: disable=invalid-name




class 				UpperCAmelCase  (    snake_case_     ):
      _lowercase:    str		  =     ['''safety_checker''', '''feature_extractor''']




      def __init__(    self    :				int    ,    __snake_case    :				AutoencoderKL    ,    __snake_case    :				CLIPTextModel    ,    __snake_case    :				CLIPTokenizer    ,    __snake_case    :				UNetaDConditionModel    ,    __snake_case    :				Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]    ,    __snake_case    :				StableDiffusionSafetyChecker    ,    __snake_case    :				CLIPImageProcessor    ,    __snake_case    :				bool = True    ,    )       ->   Optional[Any]:
            super().__init__()
            if hasattr(scheduler.config    ,    """steps_offset"""						) and scheduler.config.steps_offset != 1:
                  _lowerCAmelCase							  =							(
                      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"""    ,    __snake_case    ,    standard_warn=__snake_case						)
                  _lowerCAmelCase							  =							dict(scheduler.config						)
                  _lowerCAmelCase							  =							1
                  _lowerCAmelCase							  =							FrozenDict(__snake_case						)

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




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




      def        lowercase__					(    self    :				List[str]    ,    __snake_case    :				Optional[Union[str, int]] = "auto"						)       ->   Tuple:
            if slice_size == "auto":
                  # half the attention head size is usually a good trade-off between
                  # speed and memory
                  _lowerCAmelCase							  =							self.unet.config.attention_head_dim // 2
            self.unet.set_attention_slice(__snake_case						)




      def        lowercase__					(    self    :				List[Any]						)       ->   int:
            self.enable_attention_slicing(__snake_case						)




      @torch.no_grad()
      def        lowercase__					(    self    :				Tuple    ,    __snake_case    :				Union[str, List[str]]    ,    __snake_case    :				Union[torch.FloatTensor, PIL.Image.Image]    ,    __snake_case    :				Union[torch.FloatTensor, PIL.Image.Image]    ,    __snake_case    :				float = 0.8    ,    __snake_case    :				Optional[int] = 50    ,    __snake_case    :				Optional[float] = 7.5    ,    __snake_case    :				Optional[Union[str, List[str]]] = None    ,    __snake_case    :				Optional[int] = 1    ,    __snake_case    :				Optional[float] = 0.0    ,    __snake_case    :				Optional[torch.Generator] = None    ,    __snake_case    :				Optional[str] = "pil"    ,    __snake_case    :				bool = True    ,    __snake_case    :				Optional[Callable[[int, int, torch.FloatTensor], None]] = None    ,    __snake_case    :				int = 1    ,    )       ->   Tuple:
            # 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=__snake_case    ,    image=__snake_case    ,    mask_image=__snake_case    ,    strength=__snake_case    ,    num_inference_steps=__snake_case    ,    guidance_scale=__snake_case    ,    negative_prompt=__snake_case    ,    num_images_per_prompt=__snake_case    ,    eta=__snake_case    ,    generator=__snake_case    ,    output_type=__snake_case    ,    return_dict=__snake_case    ,    callback=__snake_case    ,    )




      @torch.no_grad()
      def        lowercase__					(    self    :				List[Any]    ,    __snake_case    :				Union[str, List[str]]    ,    __snake_case    :				Union[torch.FloatTensor, PIL.Image.Image]    ,    __snake_case    :				float = 0.8    ,    __snake_case    :				Optional[int] = 50    ,    __snake_case    :				Optional[float] = 7.5    ,    __snake_case    :				Optional[Union[str, List[str]]] = None    ,    __snake_case    :				Optional[int] = 1    ,    __snake_case    :				Optional[float] = 0.0    ,    __snake_case    :				Optional[torch.Generator] = None    ,    __snake_case    :				Optional[str] = "pil"    ,    __snake_case    :				bool = True    ,    __snake_case    :				Optional[Callable[[int, int, torch.FloatTensor], None]] = None    ,    __snake_case    :				int = 1    ,    **__snake_case    :				Tuple    ,    )       ->   Optional[int]:
            # 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=__snake_case    ,    image=__snake_case    ,    strength=__snake_case    ,    num_inference_steps=__snake_case    ,    guidance_scale=__snake_case    ,    negative_prompt=__snake_case    ,    num_images_per_prompt=__snake_case    ,    eta=__snake_case    ,    generator=__snake_case    ,    output_type=__snake_case    ,    return_dict=__snake_case    ,    callback=__snake_case    ,    callback_steps=__snake_case    ,    )




      @torch.no_grad()
      def        lowercase__					(    self    :				Any    ,    __snake_case    :				Union[str, List[str]]    ,    __snake_case    :				int = 5_12    ,    __snake_case    :				int = 5_12    ,    __snake_case    :				int = 50    ,    __snake_case    :				float = 7.5    ,    __snake_case    :				Optional[Union[str, List[str]]] = None    ,    __snake_case    :				Optional[int] = 1    ,    __snake_case    :				float = 0.0    ,    __snake_case    :				Optional[torch.Generator] = None    ,    __snake_case    :				Optional[torch.FloatTensor] = None    ,    __snake_case    :				Optional[str] = "pil"    ,    __snake_case    :				bool = True    ,    __snake_case    :				Optional[Callable[[int, int, torch.FloatTensor], None]] = None    ,    __snake_case    :				int = 1    ,    )       ->   Dict:
            # For more information on how this function https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionPipeline
            return StableDiffusionPipeline(**self.components						)(
                prompt=__snake_case    ,    height=__snake_case    ,    width=__snake_case    ,    num_inference_steps=__snake_case    ,    guidance_scale=__snake_case    ,    negative_prompt=__snake_case    ,    num_images_per_prompt=__snake_case    ,    eta=__snake_case    ,    generator=__snake_case    ,    latents=__snake_case    ,    output_type=__snake_case    ,    return_dict=__snake_case    ,    callback=__snake_case    ,    callback_steps=__snake_case    ,    )













'''simple docstring'''






from typing import TYPE_CHECKING

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


A__       :     Tuple          ={
    '''configuration_oneformer''': ['''ONEFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''OneFormerConfig'''],
    '''processing_oneformer''': ['''OneFormerProcessor'''],
}

try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__       :     List[str]          =['''OneFormerImageProcessor''']

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__       :     Dict          =[
          '''ONEFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
          '''OneFormerForUniversalSegmentation''',
          '''OneFormerModel''',
          '''OneFormerPreTrainedModel''',
      ]

if TYPE_CHECKING:
      from .configuration_oneformer import ONEFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, OneFormerConfig
      from .processing_oneformer import OneFormerProcessor

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .image_processing_oneformer import OneFormerImageProcessor
      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_oneformer import (
                ONEFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
                OneFormerForUniversalSegmentation,
                OneFormerModel,
                OneFormerPreTrainedModel,
            )


else:
      import sys

      A__       :     Optional[Any]          =_LazyModule(__name__, globals()['''__file__'''], _import_structure)






