



'''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 							lowercase (						_lowerCamelCase       ):


 """simple docstring"""


 UpperCAmelCase					=						["""safety_checker""", """feature_extractor"""]







 def __init__(							self						,a_						,a_						,a_						,a_						,a_						,a_						,a_						,a_ = True						,)	->     int:
        super().__init__()
        if hasattr(scheduler.config						,"""steps_offset"""							) and scheduler.config.steps_offset != 1:
               _UpperCAmelCase						:		Tuple      =				(
                   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_							)
               _UpperCAmelCase						:		Any      =				dict(scheduler.config							)
               _UpperCAmelCase						:		str      =				1
               _UpperCAmelCase						:		Any      =				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"							)	->     Union[str, Any]:
        if slice_size == "auto":
               # half the attention head size is usually a good trade-off between
               # speed and memory
               _UpperCAmelCase						:		Optional[int]      =				self.unet.config.attention_head_dim // 2
        self.unet.set_attention_slice(a_							)







 def _snake_case				(							self							)	->     Tuple:
        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						,)	->     List[Any]:
        # 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[str]:
        # 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_torch_available, is_vision_available


A_							:				List[Any]						=			{
    """configuration_deta""": ["""DETA_PRETRAINED_CONFIG_ARCHIVE_MAP""", """DetaConfig"""],
}

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_							:				Optional[int]						=			["""DetaImageProcessor"""]

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_							:				Optional[Any]						=			[
       """DETA_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """DetaForObjectDetection""",
       """DetaModel""",
       """DetaPreTrainedModel""",
   ]


if TYPE_CHECKING:
   from .configuration_deta import DETA_PRETRAINED_CONFIG_ARCHIVE_MAP, DetaConfig

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .image_processing_deta import DetaImageProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_deta import (
          DETA_PRETRAINED_MODEL_ARCHIVE_LIST,
          DetaForObjectDetection,
          DetaModel,
          DetaPreTrainedModel,
      )

else:
   import sys

   A_							:				List[Any]						=			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



