




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


UpperCamelCase__ :   str						=							'''CompVis/stable-diffusion-v1-1'''
UpperCamelCase__ :   Optional[Any]						=							'''CompVis/stable-diffusion-v1-2'''
UpperCamelCase__ :   Optional[int]						=							'''CompVis/stable-diffusion-v1-3'''
UpperCamelCase__ :   Union[str, Any]						=							'''CompVis/stable-diffusion-v1-4'''







class 				lowerCAmelCase_       (					lowerCamelCase_							):






				def __init__(			self      ,snake_case__      ,snake_case__      ,snake_case__      ,snake_case__      ,snake_case__      ,snake_case__      ,snake_case__      ,snake_case__ = True      ,):
							super()._init_()

							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      StableDiffusionPipeline.from_pretrained(snake_case__ )
							SCREAMING_SNAKE_CASE_   : str					  =      StableDiffusionPipeline.from_pretrained(snake_case__ )
							SCREAMING_SNAKE_CASE_   : Dict					  =      StableDiffusionPipeline.from_pretrained(snake_case__ )
							SCREAMING_SNAKE_CASE_   : Tuple					  =      StableDiffusionPipeline(
							    vae=snake_case__      ,text_encoder=snake_case__      ,tokenizer=snake_case__      ,unet=snake_case__      ,scheduler=snake_case__      ,safety_checker=snake_case__      ,feature_extractor=snake_case__      ,requires_safety_checker=snake_case__      ,)

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






				@property
				def 		snake_case	(			self ):
							return {k: getattr(self      ,snake_case__ ) for k in self.config.keys() if not k.startswith('_' )}






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






				def 		snake_case	(			self ):
							self.enable_attention_slicing(snake_case__ )






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							return self.pipea(
							    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__      ,**snake_case__      ,)






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							return self.pipea(
							    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__      ,**snake_case__      ,)






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							return self.pipea(
							    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__      ,**snake_case__      ,)






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							return self.pipea(
							    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__      ,**snake_case__      ,)






				@torch.no_grad()
				def 		snake_case	(			self      ,snake_case__      ,snake_case__ = 512      ,snake_case__ = 512      ,snake_case__ = 50      ,snake_case__ = 7.5      ,snake_case__ = None      ,snake_case__ = 1      ,snake_case__ = 0.0      ,snake_case__ = None      ,snake_case__ = None      ,snake_case__ = "pil"      ,snake_case__ = True      ,snake_case__ = None      ,snake_case__ = 1      ,**snake_case__      ,):
							SCREAMING_SNAKE_CASE_   : Optional[int]					  =      'cuda' if torch.cuda.is_available() else 'cpu'
							self.to(snake_case__ )

							# 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
							SCREAMING_SNAKE_CASE_   : Any					  =      self.textaimg_sda_a(
							    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__      ,**snake_case__      ,)

							# Get first result from Stable Diffusion Checkpoint v1.2
							SCREAMING_SNAKE_CASE_   : Tuple					  =      self.textaimg_sda_a(
							    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__      ,**snake_case__      ,)

							# Get first result from Stable Diffusion Checkpoint v1.3
							SCREAMING_SNAKE_CASE_   : str					  =      self.textaimg_sda_a(
							    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__      ,**snake_case__      ,)

							# Get first result from Stable Diffusion Checkpoint v1.4
							SCREAMING_SNAKE_CASE_   : str					  =      self.textaimg_sda_a(
							    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__      ,**snake_case__      ,)

							# 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]] )





"""simple docstring"""


class 	__a	:






       def __init__(	self			:				Any							,   UpperCAmelCase_			:				List[str]							,   UpperCAmelCase_			:				Optional[Any]							,   UpperCAmelCase_			:				Optional[Any]      )->	Optional[int]:







              """simple docstring"""
              UpperCamelCase       			=		name
              UpperCamelCase       			=		value
              UpperCamelCase       			=		weight






       def __repr__(	self			:				int      )->	Any:







              """simple docstring"""
              return f"{self.__class__.__name__}({self.name}, {self.value}, {self.weight})"






       def 						_SCREAMING_SNAKE_CASE							(	self			:				int      )->	Union[str, Any]:







              """simple docstring"""
              return self.value






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[int]      )->	int:







              """simple docstring"""
              return self.name






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Tuple      )->	List[Any]:







              """simple docstring"""
              return self.weight






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Any      )->	Union[str, Any]:







              """simple docstring"""
              return self.value / self.weight





def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Union[str, Any]:







       """simple docstring"""
       UpperCamelCase       			=		[]
       for i in range(len(UpperCAmelCase_					)					):
              menu.append(Things(name[i]		,   value[i]		,   weight[i]					)					)
       return menu



def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Dict:







       """simple docstring"""
       UpperCamelCase       			=		sorted(UpperCAmelCase_		,   key=UpperCAmelCase_		,   reverse=UpperCAmelCase_					)
       UpperCamelCase       			=		[]
       UpperCamelCase			,							UpperCamelCase       			=		0.0, 0.0
       for i in range(len(UpperCAmelCase_					)					):
              if (total_cost + items_copy[i].get_weight()) <= max_cost:
                     result.append(items_copy[i]					)
                     total_cost += items_copy[i].get_weight()
                     total_value += items_copy[i].get_value()
       return (result, total_value)



def 						lowerCamelCase__      (				)->				Dict:







       """simple docstring"""


if __name__ == "__main__":
      import doctest

      doctest.testmod()





