

"""simple docstring"""

# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

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


a__ :	List[Any]						= {
    """configuration_tvlt""": ["""TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """TvltConfig"""],
    """feature_extraction_tvlt""": ["""TvltFeatureExtractor"""],
    """processing_tvlt""": ["""TvltProcessor"""],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							a__ :	Optional[int]						= [
							    """TVLT_PRETRAINED_MODEL_ARCHIVE_LIST""",
							    """TvltModel""",
							    """TvltForPreTraining""",
							    """TvltForAudioVisualClassification""",
							    """TvltPreTrainedModel""",
							]

try:
							if not is_vision_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							a__ :	Union[str, Any]						= ["""TvltImageProcessor"""]


if TYPE_CHECKING:
							from .configuration_tvlt import TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP, TvltConfig
							from .processing_tvlt import TvltProcessor
							from .feature_extraction_tvlt import TvltFeatureExtractor

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tvlt import (
														    TVLT_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TvltForAudioVisualClassification,
														    TvltForPreTraining,
														    TvltModel,
														    TvltPreTrainedModel,
														)

							try:
														if not is_vision_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .image_processing_tvlt import TvltImageProcessor


else:
							import sys

							a__ :	Dict						= _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)





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


class 			_snake_case     (						UpperCamelCase       ):
						__snake_case 			=     ['safety_checker', 'feature_extractor']







						def __init__(self     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_ = True     ,							)			->						Optional[int]:
											super().__init__()
											if hasattr(scheduler.config     ,							'''steps_offset'''							) and scheduler.config.steps_offset != 1:
																__lowercase												=			(
																    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'''     ,							UpperCAmelCase_     ,							standard_warn=UpperCAmelCase_							)
																__lowercase												=			dict(scheduler.config							)
																__lowercase												=			1
																__lowercase												=			FrozenDict(UpperCAmelCase_							)

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







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







						def        _UpperCamelCase    (self     ,							UpperCAmelCase_ = "auto"							)			->						str:
											if slice_size == "auto":
																# half the attention head size is usually a good trade-off between
																# speed and memory
																__lowercase												=			self.unet.config.attention_head_dim // 2
											self.unet.set_attention_slice(UpperCAmelCase_							)







						def        _UpperCamelCase    (self							)			->						int:
											self.enable_attention_slicing(UpperCAmelCase_							)







						@torch.no_grad()
						def        _UpperCamelCase    (self     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_ = 0.8     ,							UpperCAmelCase_ = 5_0     ,							UpperCAmelCase_ = 7.5     ,							UpperCAmelCase_ = None     ,							UpperCAmelCase_ = 1     ,							UpperCAmelCase_ = 0.0     ,							UpperCAmelCase_ = None     ,							UpperCAmelCase_ = "pil"     ,							UpperCAmelCase_ = True     ,							UpperCAmelCase_ = None     ,							UpperCAmelCase_ = 1     ,							)			->						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=UpperCAmelCase_     ,							image=UpperCAmelCase_     ,							mask_image=UpperCAmelCase_     ,							strength=UpperCAmelCase_     ,							num_inference_steps=UpperCAmelCase_     ,							guidance_scale=UpperCAmelCase_     ,							negative_prompt=UpperCAmelCase_     ,							num_images_per_prompt=UpperCAmelCase_     ,							eta=UpperCAmelCase_     ,							generator=UpperCAmelCase_     ,							output_type=UpperCAmelCase_     ,							return_dict=UpperCAmelCase_     ,							callback=UpperCAmelCase_     ,							)







						@torch.no_grad()
						def        _UpperCamelCase    (self     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_ = 0.8     ,							UpperCAmelCase_ = 5_0     ,							UpperCAmelCase_ = 7.5     ,							UpperCAmelCase_ = None     ,							UpperCAmelCase_ = 1     ,							UpperCAmelCase_ = 0.0     ,							UpperCAmelCase_ = None     ,							UpperCAmelCase_ = "pil"     ,							UpperCAmelCase_ = True     ,							UpperCAmelCase_ = None     ,							UpperCAmelCase_ = 1     ,							**UpperCAmelCase_     ,							)			->						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=UpperCAmelCase_     ,							image=UpperCAmelCase_     ,							strength=UpperCAmelCase_     ,							num_inference_steps=UpperCAmelCase_     ,							guidance_scale=UpperCAmelCase_     ,							negative_prompt=UpperCAmelCase_     ,							num_images_per_prompt=UpperCAmelCase_     ,							eta=UpperCAmelCase_     ,							generator=UpperCAmelCase_     ,							output_type=UpperCAmelCase_     ,							return_dict=UpperCAmelCase_     ,							callback=UpperCAmelCase_     ,							callback_steps=UpperCAmelCase_     ,							)







						@torch.no_grad()
						def        _UpperCamelCase    (self     ,							UpperCAmelCase_     ,							UpperCAmelCase_ = 5_1_2     ,							UpperCAmelCase_ = 5_1_2     ,							UpperCAmelCase_ = 5_0     ,							UpperCAmelCase_ = 7.5     ,							UpperCAmelCase_ = None     ,							UpperCAmelCase_ = 1     ,							UpperCAmelCase_ = 0.0     ,							UpperCAmelCase_ = None     ,							UpperCAmelCase_ = None     ,							UpperCAmelCase_ = "pil"     ,							UpperCAmelCase_ = True     ,							UpperCAmelCase_ = None     ,							UpperCAmelCase_ = 1     ,							)			->						Optional[int]:
											# For more information on how this function https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionPipeline
											return StableDiffusionPipeline(**self.components							)(
											    prompt=UpperCAmelCase_     ,							height=UpperCAmelCase_     ,							width=UpperCAmelCase_     ,							num_inference_steps=UpperCAmelCase_     ,							guidance_scale=UpperCAmelCase_     ,							negative_prompt=UpperCAmelCase_     ,							num_images_per_prompt=UpperCAmelCase_     ,							eta=UpperCAmelCase_     ,							generator=UpperCAmelCase_     ,							latents=UpperCAmelCase_     ,							output_type=UpperCAmelCase_     ,							return_dict=UpperCAmelCase_     ,							callback=UpperCAmelCase_     ,							callback_steps=UpperCAmelCase_     ,							)


