

'''simple docstring'''






from typing import Any, Callable, Dict, List, Optional, Union

import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker


lowerCAmelCase__											=	'''CompVis/stable-diffusion-v1-1'''
lowerCAmelCase__											=	'''CompVis/stable-diffusion-v1-2'''
lowerCAmelCase__											=	'''CompVis/stable-diffusion-v1-3'''
lowerCAmelCase__											=	'''CompVis/stable-diffusion-v1-4'''






class 			lowercase_	(A_      ):




  """simple docstring"""




  def __init__(      self   :     Union[str, Any]					,lowercase__   :     Dict					,lowercase__   :     Dict					,lowercase__   :     Union[str, Any]					,lowercase__   :     Any					,lowercase__   :     Tuple					,lowercase__   :     int					,lowercase__   :     List[str]					,lowercase__   :     Dict = True					,):
   super()._init_()

   __lowercase							  = StableDiffusionPipeline.from_pretrained(lowercase__			)
   __lowercase							  = StableDiffusionPipeline.from_pretrained(lowercase__			)
   __lowercase							  = StableDiffusionPipeline.from_pretrained(lowercase__			)
   __lowercase							  = StableDiffusionPipeline(
       vae=lowercase__					,text_encoder=lowercase__					,tokenizer=lowercase__					,unet=lowercase__					,scheduler=lowercase__					,safety_checker=lowercase__					,feature_extractor=lowercase__					,requires_safety_checker=lowercase__					,)

   self.register_modules(pipelinea=self.pipea					,pipelinea=self.pipea					,pipelinea=self.pipea					,pipelinea=self.pipea			)






  @property
  def 					SCREAMING_SNAKE_CASE      (      self   :     Union[str, Any]			):
   return {k: getattr(self					,lowercase__			) for k in self.config.keys() if not k.startswith('''_'''			)}






  def 					SCREAMING_SNAKE_CASE      (      self   :     List[str]					,lowercase__   :     Dict = "auto"			):
   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(lowercase__			)






  def 					SCREAMING_SNAKE_CASE      (      self   :     Optional[Any]			):
   self.enable_attention_slicing(lowercase__			)






  @torch.no_grad()
  def 					SCREAMING_SNAKE_CASE      (      self   :     Optional[int]					,lowercase__   :     str					,lowercase__   :     Tuple = 5_1_2					,lowercase__   :     Optional[Any] = 5_1_2					,lowercase__   :     str = 5_0					,lowercase__   :     Any = 7.5					,lowercase__   :     Any = None					,lowercase__   :     Union[str, Any] = 1					,lowercase__   :     Union[str, Any] = 0.0					,lowercase__   :     List[str] = None					,lowercase__   :     str = None					,lowercase__   :     Dict = "pil"					,lowercase__   :     Any = True					,lowercase__   :     Optional[int] = None					,lowercase__   :     Dict = 1					,**lowercase__   :     Tuple					,):
   return self.pipea(
       prompt=lowercase__					,height=lowercase__					,width=lowercase__					,num_inference_steps=lowercase__					,guidance_scale=lowercase__					,negative_prompt=lowercase__					,num_images_per_prompt=lowercase__					,eta=lowercase__					,generator=lowercase__					,latents=lowercase__					,output_type=lowercase__					,return_dict=lowercase__					,callback=lowercase__					,callback_steps=lowercase__					,**lowercase__					,)






  @torch.no_grad()
  def 					SCREAMING_SNAKE_CASE      (      self   :     Optional[Any]					,lowercase__   :     Union[str, Any]					,lowercase__   :     List[str] = 5_1_2					,lowercase__   :     Any = 5_1_2					,lowercase__   :     str = 5_0					,lowercase__   :     Any = 7.5					,lowercase__   :     Optional[int] = None					,lowercase__   :     Any = 1					,lowercase__   :     List[Any] = 0.0					,lowercase__   :     str = None					,lowercase__   :     List[Any] = None					,lowercase__   :     str = "pil"					,lowercase__   :     Optional[Any] = True					,lowercase__   :     Union[str, Any] = None					,lowercase__   :     List[str] = 1					,**lowercase__   :     Optional[Any]					,):
   return self.pipea(
       prompt=lowercase__					,height=lowercase__					,width=lowercase__					,num_inference_steps=lowercase__					,guidance_scale=lowercase__					,negative_prompt=lowercase__					,num_images_per_prompt=lowercase__					,eta=lowercase__					,generator=lowercase__					,latents=lowercase__					,output_type=lowercase__					,return_dict=lowercase__					,callback=lowercase__					,callback_steps=lowercase__					,**lowercase__					,)






  @torch.no_grad()
  def 					SCREAMING_SNAKE_CASE      (      self   :     Any					,lowercase__   :     Union[str, Any]					,lowercase__   :     Dict = 5_1_2					,lowercase__   :     List[Any] = 5_1_2					,lowercase__   :     List[str] = 5_0					,lowercase__   :     Optional[Any] = 7.5					,lowercase__   :     Optional[int] = None					,lowercase__   :     Optional[int] = 1					,lowercase__   :     Tuple = 0.0					,lowercase__   :     Union[str, Any] = None					,lowercase__   :     Tuple = None					,lowercase__   :     str = "pil"					,lowercase__   :     Dict = True					,lowercase__   :     Dict = None					,lowercase__   :     Any = 1					,**lowercase__   :     List[str]					,):
   return self.pipea(
       prompt=lowercase__					,height=lowercase__					,width=lowercase__					,num_inference_steps=lowercase__					,guidance_scale=lowercase__					,negative_prompt=lowercase__					,num_images_per_prompt=lowercase__					,eta=lowercase__					,generator=lowercase__					,latents=lowercase__					,output_type=lowercase__					,return_dict=lowercase__					,callback=lowercase__					,callback_steps=lowercase__					,**lowercase__					,)






  @torch.no_grad()
  def 					SCREAMING_SNAKE_CASE      (      self   :     List[Any]					,lowercase__   :     str					,lowercase__   :     Optional[int] = 5_1_2					,lowercase__   :     Any = 5_1_2					,lowercase__   :     Optional[Any] = 5_0					,lowercase__   :     List[str] = 7.5					,lowercase__   :     List[Any] = None					,lowercase__   :     int = 1					,lowercase__   :     List[str] = 0.0					,lowercase__   :     Any = None					,lowercase__   :     Any = None					,lowercase__   :     Any = "pil"					,lowercase__   :     List[Any] = True					,lowercase__   :     Optional[Any] = None					,lowercase__   :     Optional[int] = 1					,**lowercase__   :     int					,):
   return self.pipea(
       prompt=lowercase__					,height=lowercase__					,width=lowercase__					,num_inference_steps=lowercase__					,guidance_scale=lowercase__					,negative_prompt=lowercase__					,num_images_per_prompt=lowercase__					,eta=lowercase__					,generator=lowercase__					,latents=lowercase__					,output_type=lowercase__					,return_dict=lowercase__					,callback=lowercase__					,callback_steps=lowercase__					,**lowercase__					,)






  @torch.no_grad()
  def 					SCREAMING_SNAKE_CASE      (      self   :     str					,lowercase__   :     Any					,lowercase__   :     Dict = 5_1_2					,lowercase__   :     Tuple = 5_1_2					,lowercase__   :     Dict = 5_0					,lowercase__   :     Tuple = 7.5					,lowercase__   :     str = None					,lowercase__   :     Any = 1					,lowercase__   :     List[str] = 0.0					,lowercase__   :     Optional[Any] = None					,lowercase__   :     Tuple = None					,lowercase__   :     Optional[int] = "pil"					,lowercase__   :     Dict = True					,lowercase__   :     Optional[int] = None					,lowercase__   :     Any = 1					,**lowercase__   :     List[Any]					,):
   __lowercase							  = '''cuda''' if torch.cuda.is_available() else '''cpu'''
   self.to(lowercase__			)

   # Checks if the height and width are divisible by 8 or not
   if height % 8 != 0 or width % 8 != 0:
    raise ValueError(F"`height` and `width` must be divisible by 8 but are {height} and {width}."			)

   # Get first result from Stable Diffusion Checkpoint v1.1
   __lowercase							  = self.textaimg_sda_a(
       prompt=lowercase__					,height=lowercase__					,width=lowercase__					,num_inference_steps=lowercase__					,guidance_scale=lowercase__					,negative_prompt=lowercase__					,num_images_per_prompt=lowercase__					,eta=lowercase__					,generator=lowercase__					,latents=lowercase__					,output_type=lowercase__					,return_dict=lowercase__					,callback=lowercase__					,callback_steps=lowercase__					,**lowercase__					,)

   # Get first result from Stable Diffusion Checkpoint v1.2
   __lowercase							  = self.textaimg_sda_a(
       prompt=lowercase__					,height=lowercase__					,width=lowercase__					,num_inference_steps=lowercase__					,guidance_scale=lowercase__					,negative_prompt=lowercase__					,num_images_per_prompt=lowercase__					,eta=lowercase__					,generator=lowercase__					,latents=lowercase__					,output_type=lowercase__					,return_dict=lowercase__					,callback=lowercase__					,callback_steps=lowercase__					,**lowercase__					,)

   # Get first result from Stable Diffusion Checkpoint v1.3
   __lowercase							  = self.textaimg_sda_a(
       prompt=lowercase__					,height=lowercase__					,width=lowercase__					,num_inference_steps=lowercase__					,guidance_scale=lowercase__					,negative_prompt=lowercase__					,num_images_per_prompt=lowercase__					,eta=lowercase__					,generator=lowercase__					,latents=lowercase__					,output_type=lowercase__					,return_dict=lowercase__					,callback=lowercase__					,callback_steps=lowercase__					,**lowercase__					,)

   # Get first result from Stable Diffusion Checkpoint v1.4
   __lowercase							  = self.textaimg_sda_a(
       prompt=lowercase__					,height=lowercase__					,width=lowercase__					,num_inference_steps=lowercase__					,guidance_scale=lowercase__					,negative_prompt=lowercase__					,num_images_per_prompt=lowercase__					,eta=lowercase__					,generator=lowercase__					,latents=lowercase__					,output_type=lowercase__					,return_dict=lowercase__					,callback=lowercase__					,callback_steps=lowercase__					,**lowercase__					,)

   # Get all result images into a single list and pass it via StableDiffusionPipelineOutput for final result
   return StableDiffusionPipelineOutput([resa[0], resa[0], resa[0], resa[0]]			)





import os
import unittest

from huggingface_hub.utils import are_progress_bars_disabled

import transformers.models.bart.tokenization_bart
from transformers import logging
from transformers.testing_utils import CaptureLogger, mockenv, mockenv_context
from transformers.utils.logging import disable_progress_bar, enable_progress_bar





class       A    (   unittest.TestCase ):


							def 			_A       (self					):
									__lowercase=			logging.get_logger()

									# the current default level is logging.WARNING
									__lowercase=			logging.get_verbosity()

									logging.set_verbosity_error()
									self.assertEqual(logger.getEffectiveLevel()      ,				logging.get_verbosity()					)

									logging.set_verbosity_warning()
									self.assertEqual(logger.getEffectiveLevel()      ,				logging.get_verbosity()					)

									logging.set_verbosity_info()
									self.assertEqual(logger.getEffectiveLevel()      ,				logging.get_verbosity()					)

									logging.set_verbosity_debug()
									self.assertEqual(logger.getEffectiveLevel()      ,				logging.get_verbosity()					)

									# restore to the original level
									logging.set_verbosity(lowerCAmelCase					)


							def 			_A       (self					):
									__lowercase=			logging.get_verbosity()

									__lowercase=			logging.get_logger('transformers.models.bart.tokenization_bart'					)
									__lowercase=			'Testing 1, 2, 3'

									# should be able to log warnings (if default settings weren't overridden by `pytest --log-level-all`)
									if level_origin <= logging.WARNING:
											with CaptureLogger(lowerCAmelCase					) as cl:
													logger.warning(lowerCAmelCase					)
											self.assertEqual(cl.out      ,				msg + '\n'					)

									# this is setting the level for all of `transformers.*` loggers
									logging.set_verbosity_error()

									# should not be able to log warnings
									with CaptureLogger(lowerCAmelCase					) as cl:
											logger.warning(lowerCAmelCase					)
									self.assertEqual(cl.out      ,				''					)

									# should be able to log warnings again
									logging.set_verbosity_warning()
									with CaptureLogger(lowerCAmelCase					) as cl:
											logger.warning(lowerCAmelCase					)
									self.assertEqual(cl.out      ,				msg + '\n'					)

									# restore to the original level
									logging.set_verbosity(lowerCAmelCase					)


							@mockenv(TRANSFORMERS_VERBOSITY='error'					)
							def 			_A       (self					):
									# reset for the env var to take effect, next time some logger call is made
									transformers.utils.logging._reset_library_root_logger()
									# this action activates the env var
									__lowercase=			logging.get_logger('transformers.models.bart.tokenization_bart'					)

									__lowercase=			os.getenv('TRANSFORMERS_VERBOSITY'      ,				lowerCAmelCase					)
									__lowercase=			logging.log_levels[env_level_str]

									__lowercase=			logging.get_verbosity()
									self.assertEqual(
									    lowerCAmelCase      ,				lowerCAmelCase      ,				f'TRANSFORMERS_VERBOSITY={env_level_str}/{env_level}, but internal verbosity is {current_level}'      ,				)

									# restore to the original level
									__lowercase=			''
									transformers.utils.logging._reset_library_root_logger()


							@mockenv(TRANSFORMERS_VERBOSITY='super-error'					)
							def 			_A       (self					):
									# reset for the env var to take effect, next time some logger call is made
									transformers.utils.logging._reset_library_root_logger()
									__lowercase=			logging.logging.getLogger()
									with CaptureLogger(lowerCAmelCase					) as cl:
											# this action activates the env var
											logging.get_logger('transformers.models.bart.tokenization_bart'					)
									self.assertIn('Unknown option TRANSFORMERS_VERBOSITY=super-error'      ,				cl.out					)

									# no need to restore as nothing was changed







							def 			_A       (self					):
									# testing `logger.warning_advice()`
									transformers.utils.logging._reset_library_root_logger()

									__lowercase=			logging.get_logger('transformers.models.bart.tokenization_bart'					)
									__lowercase=			'Testing 1, 2, 3'

									with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS='1'					):
											# nothing should be logged as env var disables this method
											with CaptureLogger(lowerCAmelCase					) as cl:
													logger.warning_advice(lowerCAmelCase					)
											self.assertEqual(cl.out      ,				''					)

									with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS=''					):
											# should log normally as TRANSFORMERS_NO_ADVISORY_WARNINGS is unset
											with CaptureLogger(lowerCAmelCase					) as cl:
													logger.warning_advice(lowerCAmelCase					)
											self.assertEqual(cl.out      ,				msg + '\n'					)







def        _lowerCamelCase(	)						->	Optional[int]:

		'''simple docstring'''







		disable_progress_bar()
		assert are_progress_bars_disabled()

		enable_progress_bar()
		assert not are_progress_bars_disabled()






