





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


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




class 					UpperCamelCase_    (       UpperCamelCase__      ):
							lowerCamelCase_          =   ["safety_checker", "feature_extractor"]


							def __init__(							self      :Optional[int]							,			__A      :AutoencoderKL							,			__A      :CLIPTextModel							,			__A      :CLIPTokenizer							,			__A      :UNetaDConditionModel							,			__A      :Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]							,			__A      :StableDiffusionSafetyChecker							,			__A      :CLIPImageProcessor							,			__A      :bool = True							,			)				->				Dict:



									"""simple docstring"""



									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      :Tuple						)				->				Dict[str, Any]:



									"""simple docstring"""



									return {k: getattr(self							,			__A						) for k in self.config.keys() if not k.startswith("""_"""						)}


							def        _snake_case					(							self      :Any							,			__A      :Optional[Union[str, int]] = "auto"						)				->				Optional[Any]:



									"""simple docstring"""



									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      :Optional[Any]						)				->				Dict:



									"""simple docstring"""



									self.enable_attention_slicing(__A						)


							@torch.no_grad()
							def        _snake_case					(							self      :Optional[Any]							,			__A      :Union[str, List[str]]							,			__A      :Union[torch.FloatTensor, PIL.Image.Image]							,			__A      :Union[torch.FloatTensor, PIL.Image.Image]							,			__A      :float = 0.8							,			__A      :Optional[int] = 50							,			__A      :Optional[float] = 7.5							,			__A      :Optional[Union[str, List[str]]] = None							,			__A      :Optional[int] = 1							,			__A      :Optional[float] = 0.0							,			__A      :Optional[torch.Generator] = None							,			__A      :Optional[str] = "pil"							,			__A      :bool = True							,			__A      :Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,			__A      :int = 1							,			)				->				List[str]:



									"""simple docstring"""



									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      :Union[str, Any]							,			__A      :Union[str, List[str]]							,			__A      :Union[torch.FloatTensor, PIL.Image.Image]							,			__A      :float = 0.8							,			__A      :Optional[int] = 50							,			__A      :Optional[float] = 7.5							,			__A      :Optional[Union[str, List[str]]] = None							,			__A      :Optional[int] = 1							,			__A      :Optional[float] = 0.0							,			__A      :Optional[torch.Generator] = None							,			__A      :Optional[str] = "pil"							,			__A      :bool = True							,			__A      :Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,			__A      :int = 1							,			**__A      :int							,			)				->				List[Any]:



									"""simple docstring"""



									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      :List[Any]							,			__A      :Union[str, List[str]]							,			__A      :int = 512							,			__A      :int = 512							,			__A      :int = 50							,			__A      :float = 7.5							,			__A      :Optional[Union[str, List[str]]] = None							,			__A      :Optional[int] = 1							,			__A      :float = 0.0							,			__A      :Optional[torch.Generator] = None							,			__A      :Optional[torch.FloatTensor] = None							,			__A      :Optional[str] = "pil"							,			__A      :bool = True							,			__A      :Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,			__A      :int = 1							,			)				->				Union[str, Any]:



									"""simple docstring"""



									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							,			)






from typing import TYPE_CHECKING

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


_lowerCamelCase							=     {
    'configuration_utils': ['GenerationConfig'],
    'streamers': ['TextIteratorStreamer', 'TextStreamer'],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowerCamelCase							=     [
	    'Constraint',
	    'ConstraintListState',
	    'DisjunctiveConstraint',
	    'PhrasalConstraint',
	]
	_lowerCamelCase							=     [
	    'BeamHypotheses',
	    'BeamScorer',
	    'BeamSearchScorer',
	    'ConstrainedBeamSearchScorer',
	]
	_lowerCamelCase							=     [
	    'EpsilonLogitsWarper',
	    'EtaLogitsWarper',
	    'ForcedBOSTokenLogitsProcessor',
	    'ForcedEOSTokenLogitsProcessor',
	    'HammingDiversityLogitsProcessor',
	    'InfNanRemoveLogitsProcessor',
	    'LogitsProcessor',
	    'LogitsProcessorList',
	    'LogitsWarper',
	    'MinLengthLogitsProcessor',
	    'MinNewTokensLengthLogitsProcessor',
	    'NoBadWordsLogitsProcessor',
	    'NoRepeatNGramLogitsProcessor',
	    'PrefixConstrainedLogitsProcessor',
	    'RepetitionPenaltyLogitsProcessor',
	    'SequenceBiasLogitsProcessor',
	    'EncoderRepetitionPenaltyLogitsProcessor',
	    'TemperatureLogitsWarper',
	    'TopKLogitsWarper',
	    'TopPLogitsWarper',
	    'TypicalLogitsWarper',
	    'EncoderNoRepeatNGramLogitsProcessor',
	    'ExponentialDecayLengthPenalty',
	    'LogitNormalization',
	]
	_lowerCamelCase							=     [
	    'MaxNewTokensCriteria',
	    'MaxLengthCriteria',
	    'MaxTimeCriteria',
	    'StoppingCriteria',
	    'StoppingCriteriaList',
	    'validate_stopping_criteria',
	]
	_lowerCamelCase							=     [
	    'GenerationMixin',
	    'top_k_top_p_filtering',
	    'GreedySearchEncoderDecoderOutput',
	    'GreedySearchDecoderOnlyOutput',
	    'SampleEncoderDecoderOutput',
	    'SampleDecoderOnlyOutput',
	    'BeamSearchEncoderDecoderOutput',
	    'BeamSearchDecoderOnlyOutput',
	    'BeamSampleEncoderDecoderOutput',
	    'BeamSampleDecoderOnlyOutput',
	    'ContrastiveSearchEncoderDecoderOutput',
	    'ContrastiveSearchDecoderOnlyOutput',
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowerCamelCase							=     [
	    'TFForcedBOSTokenLogitsProcessor',
	    'TFForcedEOSTokenLogitsProcessor',
	    'TFLogitsProcessor',
	    'TFLogitsProcessorList',
	    'TFLogitsWarper',
	    'TFMinLengthLogitsProcessor',
	    'TFNoBadWordsLogitsProcessor',
	    'TFNoRepeatNGramLogitsProcessor',
	    'TFRepetitionPenaltyLogitsProcessor',
	    'TFTemperatureLogitsWarper',
	    'TFTopKLogitsWarper',
	    'TFTopPLogitsWarper',
	    'TFForceTokensLogitsProcessor',
	    'TFSuppressTokensAtBeginLogitsProcessor',
	    'TFSuppressTokensLogitsProcessor',
	]
	_lowerCamelCase							=     [
	    'TFGenerationMixin',
	    'tf_top_k_top_p_filtering',
	    'TFGreedySearchDecoderOnlyOutput',
	    'TFGreedySearchEncoderDecoderOutput',
	    'TFSampleEncoderDecoderOutput',
	    'TFSampleDecoderOnlyOutput',
	    'TFBeamSearchEncoderDecoderOutput',
	    'TFBeamSearchDecoderOnlyOutput',
	    'TFBeamSampleEncoderDecoderOutput',
	    'TFBeamSampleDecoderOnlyOutput',
	    'TFContrastiveSearchEncoderDecoderOutput',
	    'TFContrastiveSearchDecoderOnlyOutput',
	]

try:
	if not is_flax_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowerCamelCase							=     [
	    'FlaxForcedBOSTokenLogitsProcessor',
	    'FlaxForcedEOSTokenLogitsProcessor',
	    'FlaxLogitsProcessor',
	    'FlaxLogitsProcessorList',
	    'FlaxLogitsWarper',
	    'FlaxMinLengthLogitsProcessor',
	    'FlaxTemperatureLogitsWarper',
	    'FlaxTopKLogitsWarper',
	    'FlaxTopPLogitsWarper',
	]
	_lowerCamelCase							=     [
	    'FlaxGenerationMixin',
	    'FlaxGreedySearchOutput',
	    'FlaxSampleOutput',
	    'FlaxBeamSearchOutput',
	]

if TYPE_CHECKING:
	from .configuration_utils import GenerationConfig
	from .streamers import TextIteratorStreamer, TextStreamer

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .beam_constraints import Constraint, ConstraintListState, DisjunctiveConstraint, PhrasalConstraint
		from .beam_search import BeamHypotheses, BeamScorer, BeamSearchScorer, ConstrainedBeamSearchScorer
		from .logits_process import (
		    EncoderNoRepeatNGramLogitsProcessor,
		    EncoderRepetitionPenaltyLogitsProcessor,
		    EpsilonLogitsWarper,
		    EtaLogitsWarper,
		    ExponentialDecayLengthPenalty,
		    ForcedBOSTokenLogitsProcessor,
		    ForcedEOSTokenLogitsProcessor,
		    HammingDiversityLogitsProcessor,
		    InfNanRemoveLogitsProcessor,
		    LogitNormalization,
		    LogitsProcessor,
		    LogitsProcessorList,
		    LogitsWarper,
		    MinLengthLogitsProcessor,
		    MinNewTokensLengthLogitsProcessor,
		    NoBadWordsLogitsProcessor,
		    NoRepeatNGramLogitsProcessor,
		    PrefixConstrainedLogitsProcessor,
		    RepetitionPenaltyLogitsProcessor,
		    SequenceBiasLogitsProcessor,
		    TemperatureLogitsWarper,
		    TopKLogitsWarper,
		    TopPLogitsWarper,
		    TypicalLogitsWarper,
		)
		from .stopping_criteria import (
		    MaxLengthCriteria,
		    MaxNewTokensCriteria,
		    MaxTimeCriteria,
		    StoppingCriteria,
		    StoppingCriteriaList,
		    validate_stopping_criteria,
		)
		from .utils import (
		    BeamSampleDecoderOnlyOutput,
		    BeamSampleEncoderDecoderOutput,
		    BeamSearchDecoderOnlyOutput,
		    BeamSearchEncoderDecoderOutput,
		    ContrastiveSearchDecoderOnlyOutput,
		    ContrastiveSearchEncoderDecoderOutput,
		    GenerationMixin,
		    GreedySearchDecoderOnlyOutput,
		    GreedySearchEncoderDecoderOutput,
		    SampleDecoderOnlyOutput,
		    SampleEncoderDecoderOutput,
		    top_k_top_p_filtering,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tf_logits_process import (
		    TFForcedBOSTokenLogitsProcessor,
		    TFForcedEOSTokenLogitsProcessor,
		    TFForceTokensLogitsProcessor,
		    TFLogitsProcessor,
		    TFLogitsProcessorList,
		    TFLogitsWarper,
		    TFMinLengthLogitsProcessor,
		    TFNoBadWordsLogitsProcessor,
		    TFNoRepeatNGramLogitsProcessor,
		    TFRepetitionPenaltyLogitsProcessor,
		    TFSuppressTokensAtBeginLogitsProcessor,
		    TFSuppressTokensLogitsProcessor,
		    TFTemperatureLogitsWarper,
		    TFTopKLogitsWarper,
		    TFTopPLogitsWarper,
		)
		from .tf_utils import (
		    TFBeamSampleDecoderOnlyOutput,
		    TFBeamSampleEncoderDecoderOutput,
		    TFBeamSearchDecoderOnlyOutput,
		    TFBeamSearchEncoderDecoderOutput,
		    TFContrastiveSearchDecoderOnlyOutput,
		    TFContrastiveSearchEncoderDecoderOutput,
		    TFGenerationMixin,
		    TFGreedySearchDecoderOnlyOutput,
		    TFGreedySearchEncoderDecoderOutput,
		    TFSampleDecoderOnlyOutput,
		    TFSampleEncoderDecoderOutput,
		    tf_top_k_top_p_filtering,
		)

	try:
		if not is_flax_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .flax_logits_process import (
		    FlaxForcedBOSTokenLogitsProcessor,
		    FlaxForcedEOSTokenLogitsProcessor,
		    FlaxLogitsProcessor,
		    FlaxLogitsProcessorList,
		    FlaxLogitsWarper,
		    FlaxMinLengthLogitsProcessor,
		    FlaxTemperatureLogitsWarper,
		    FlaxTopKLogitsWarper,
		    FlaxTopPLogitsWarper,
		)
		from .flax_utils import FlaxBeamSearchOutput, FlaxGenerationMixin, FlaxGreedySearchOutput, FlaxSampleOutput
else:
	import sys

	_lowerCamelCase							=     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)