'''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      :				Tuple 				=    logging.get_logger(__name__)  # pylint: disable=invalid-name







class     _lowercase					(    UpperCAmelCase__      ):


 '''simple docstring'''






 _SCREAMING_SNAKE_CASE					:	Dict				     = ["""safety_checker""", """feature_extractor"""]
 def __init__(				self       :     Union[str, Any]				,	SCREAMING_SNAKE_CASE__       :     AutoencoderKL				,	SCREAMING_SNAKE_CASE__       :     CLIPTextModel				,	SCREAMING_SNAKE_CASE__       :     CLIPTokenizer				,	SCREAMING_SNAKE_CASE__       :     UNetaDConditionModel				,	SCREAMING_SNAKE_CASE__       :     Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]				,	SCREAMING_SNAKE_CASE__       :     StableDiffusionSafetyChecker				,	SCREAMING_SNAKE_CASE__       :     CLIPImageProcessor				,	SCREAMING_SNAKE_CASE__       :     bool = True				,	)  ->   Dict:
  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"""				,	SCREAMING_SNAKE_CASE__				,	standard_warn=SCREAMING_SNAKE_CASE__							)
   __lowerCAmelCase    							=						dict(scheduler.config							)
   __lowerCAmelCase    							=						1
   __lowerCAmelCase    							=						FrozenDict(SCREAMING_SNAKE_CASE__							)

  self.register_modules(
      vae=SCREAMING_SNAKE_CASE__				,	text_encoder=SCREAMING_SNAKE_CASE__				,	tokenizer=SCREAMING_SNAKE_CASE__				,	unet=SCREAMING_SNAKE_CASE__				,	scheduler=SCREAMING_SNAKE_CASE__				,	safety_checker=SCREAMING_SNAKE_CASE__				,	feature_extractor=SCREAMING_SNAKE_CASE__				,	)
  self.register_to_config(requires_safety_checker=SCREAMING_SNAKE_CASE__							)
 @property
 def a (				self       :     Dict							)  ->   Dict[str, Any]:
  return {k: getattr(self				,	SCREAMING_SNAKE_CASE__							) for k in self.config.keys() if not k.startswith("""_"""							)}
 def a (				self       :     Union[str, Any]				,	SCREAMING_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(SCREAMING_SNAKE_CASE__							)
 def a (				self       :     Any							)  ->   List[Any]:
  self.enable_attention_slicing(SCREAMING_SNAKE_CASE__							)
 @torch.no_grad()
 def a (				self       :     str				,	SCREAMING_SNAKE_CASE__       :     Union[str, List[str]]				,	SCREAMING_SNAKE_CASE__       :     Union[torch.FloatTensor, PIL.Image.Image]				,	SCREAMING_SNAKE_CASE__       :     Union[torch.FloatTensor, PIL.Image.Image]				,	SCREAMING_SNAKE_CASE__       :     float = 0.8				,	SCREAMING_SNAKE_CASE__       :     Optional[int] = 50				,	SCREAMING_SNAKE_CASE__       :     Optional[float] = 7.5				,	SCREAMING_SNAKE_CASE__       :     Optional[Union[str, List[str]]] = None				,	SCREAMING_SNAKE_CASE__       :     Optional[int] = 1				,	SCREAMING_SNAKE_CASE__       :     Optional[float] = 0.0				,	SCREAMING_SNAKE_CASE__       :     Optional[torch.Generator] = None				,	SCREAMING_SNAKE_CASE__       :     Optional[str] = "pil"				,	SCREAMING_SNAKE_CASE__       :     bool = True				,	SCREAMING_SNAKE_CASE__       :     Optional[Callable[[int, int, torch.FloatTensor], None]] = None				,	SCREAMING_SNAKE_CASE__       :     int = 1				,	)  ->   List[str]:
  # 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=SCREAMING_SNAKE_CASE__				,	image=SCREAMING_SNAKE_CASE__				,	mask_image=SCREAMING_SNAKE_CASE__				,	strength=SCREAMING_SNAKE_CASE__				,	num_inference_steps=SCREAMING_SNAKE_CASE__				,	guidance_scale=SCREAMING_SNAKE_CASE__				,	negative_prompt=SCREAMING_SNAKE_CASE__				,	num_images_per_prompt=SCREAMING_SNAKE_CASE__				,	eta=SCREAMING_SNAKE_CASE__				,	generator=SCREAMING_SNAKE_CASE__				,	output_type=SCREAMING_SNAKE_CASE__				,	return_dict=SCREAMING_SNAKE_CASE__				,	callback=SCREAMING_SNAKE_CASE__				,	)
 @torch.no_grad()
 def a (				self       :     Optional[Any]				,	SCREAMING_SNAKE_CASE__       :     Union[str, List[str]]				,	SCREAMING_SNAKE_CASE__       :     Union[torch.FloatTensor, PIL.Image.Image]				,	SCREAMING_SNAKE_CASE__       :     float = 0.8				,	SCREAMING_SNAKE_CASE__       :     Optional[int] = 50				,	SCREAMING_SNAKE_CASE__       :     Optional[float] = 7.5				,	SCREAMING_SNAKE_CASE__       :     Optional[Union[str, List[str]]] = None				,	SCREAMING_SNAKE_CASE__       :     Optional[int] = 1				,	SCREAMING_SNAKE_CASE__       :     Optional[float] = 0.0				,	SCREAMING_SNAKE_CASE__       :     Optional[torch.Generator] = None				,	SCREAMING_SNAKE_CASE__       :     Optional[str] = "pil"				,	SCREAMING_SNAKE_CASE__       :     bool = True				,	SCREAMING_SNAKE_CASE__       :     Optional[Callable[[int, int, torch.FloatTensor], None]] = None				,	SCREAMING_SNAKE_CASE__       :     int = 1				,	**SCREAMING_SNAKE_CASE__       :     str				,	)  ->   List[str]:
  # 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=SCREAMING_SNAKE_CASE__				,	image=SCREAMING_SNAKE_CASE__				,	strength=SCREAMING_SNAKE_CASE__				,	num_inference_steps=SCREAMING_SNAKE_CASE__				,	guidance_scale=SCREAMING_SNAKE_CASE__				,	negative_prompt=SCREAMING_SNAKE_CASE__				,	num_images_per_prompt=SCREAMING_SNAKE_CASE__				,	eta=SCREAMING_SNAKE_CASE__				,	generator=SCREAMING_SNAKE_CASE__				,	output_type=SCREAMING_SNAKE_CASE__				,	return_dict=SCREAMING_SNAKE_CASE__				,	callback=SCREAMING_SNAKE_CASE__				,	callback_steps=SCREAMING_SNAKE_CASE__				,	)





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







'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


_A      :				Optional[int] 				=    {
    '''configuration_speech_to_text_2''': ['''SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''Speech2Text2Config'''],
    '''processing_speech_to_text_2''': ['''Speech2Text2Processor'''],
    '''tokenization_speech_to_text_2''': ['''Speech2Text2Tokenizer'''],
}


try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _A      :				Any 				=    [
     '''SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''Speech2Text2ForCausalLM''',
     '''Speech2Text2PreTrainedModel''',
 ]


if TYPE_CHECKING:
 from .configuration_speech_to_text_a import SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextaConfig
 from .processing_speech_to_text_a import SpeechaTextaProcessor
 from .tokenization_speech_to_text_a import SpeechaTextaTokenizer

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_speech_to_text_a import (
      SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST,
      SpeechaTextaForCausalLM,
      SpeechaTextaPreTrainedModel,
  )

else:
 import sys

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






