



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






     '''simple docstring'''





     _A		:      Union[str, Any]						=					["""safety_checker""", """feature_extractor"""]






     def __init__(	self:							List[Any]						,					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						,					)       ->     List[str]:
           super().__init__()
           if hasattr(scheduler.config						,					"""steps_offset"""						) and scheduler.config.steps_offset != 1:
                 snake_case_			:List[str]						=      (
                     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						)
                 snake_case_			:Tuple						=      dict(scheduler.config						)
                 snake_case_			:Union[str, Any]						=      1
                 snake_case_			:Dict						=      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        lowerCAmelCase_    (	self:							str						)       ->     Dict[str, Any]:
           return {k: getattr(self						,					snake_case						) for k in self.config.keys() if not k.startswith("""_"""						)}






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






     def        lowerCAmelCase_    (	self:							int						)       ->     Any:
           self.enable_attention_slicing(snake_case						)






     @torch.no_grad()
     def        lowerCAmelCase_    (	self:							Optional[int]						,					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						,					)       ->     Optional[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=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        lowerCAmelCase_    (	self:							int						,					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:							Dict						,					)       ->     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=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        lowerCAmelCase_    (	self:							Dict						,					snake_case:							Union[str, List[str]]						,					snake_case:							int = 512						,					snake_case:							int = 512						,					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						,					)       ->     Any:
           # 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"""
import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import Mock, patch

import diffusers.utils.hub_utils
class     lowerCamelCase  (      unittest.TestCase    ):






					'''simple docstring'''





					@patch("""diffusers.utils.hub_utils.get_full_repo_name"""						)
					def        lowerCAmelCase_    (	self:							int						,					snake_case:							Mock						)       ->     None:
											snake_case_			:str						=      """full_repo_name"""
											with TemporaryDirectory() as tmpdir:
																	# Dummy args values
																	snake_case_			:int						=      Mock()
																	snake_case_			:Any						=      tmpdir
																	snake_case_			:int						=      0
																	snake_case_			:Optional[int]						=      """hub_token"""
																	snake_case_			:str						=      """dataset_name"""
																	snake_case_			:List[str]						=      0.0_1
																	snake_case_			:Dict						=      100_000
																	snake_case_			:Optional[Any]						=      10_000
																	snake_case_			:Optional[Any]						=      0.0_1
																	snake_case_			:Dict						=      0.0_2
																	snake_case_			:Dict						=      0.0_3
																	snake_case_			:Union[str, Any]						=      0.0_0_0_5
																	snake_case_			:Optional[Any]						=      0.0_0_0_0_0_1
																	snake_case_			:List[Any]						=      1
																	snake_case_			:Optional[Any]						=      10
																	snake_case_			:Dict						=      0.0_0_1
																	snake_case_			:Any						=      0.1
																	snake_case_			:List[Any]						=      0.2
																	snake_case_			:Any						=      True

																	# Model card mush be rendered and saved
																	diffusers.utils.hub_utils.create_model_card(snake_case						,					model_name="""model_name"""						)
																	self.assertTrue((Path(snake_case						) / """README.md""").is_file()						)
