


from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import center_crop, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
						import PIL


__lowerCamelCase       :       Any				   =			logging.get_logger(__name__)



class 			a      (      UpperCamelCase_   ):
		__lowercase													=		["""pixel_values"""]






		def __init__(  self	,     __UpperCamelCase = True	,     __UpperCamelCase = None	,     __UpperCamelCase = PIL.Image.NEAREST	,     __UpperCamelCase = False	,     __UpperCamelCase = None	,     __UpperCamelCase = 1 / 2_55	,     __UpperCamelCase = False	,     __UpperCamelCase = True	,     __UpperCamelCase = True	,     __UpperCamelCase = None	,     __UpperCamelCase = None	,     __UpperCamelCase = True	,     **__UpperCamelCase	,     )->			None:
						'''simple docstring'''


						super().__init__(**__UpperCamelCase							)
						A__     :							str   				=size if size is not None else {'''height''': 3_46, '''width''': 3_46}
						A__     :							List[Any]   				=get_size_dict(__UpperCamelCase							)
						A__     :							Dict   				=crop_size if crop_size is not None else {'''height''': 2_89, '''width''': 2_89}
						A__     :							Optional[int]   				=get_size_dict(__UpperCamelCase	,     param_name='''crop_size'''							)

						A__     :							Union[str, Any]   				=do_resize
						A__     :							Tuple   				=size
						A__     :							Dict   				=resample
						A__     :							Optional[int]   				=do_center_crop
						A__     :							Optional[int]   				=crop_size
						A__     :							Optional[Any]   				=do_rescale
						A__     :							Dict   				=rescale_factor
						A__     :							List[str]   				=rescale_offset
						A__     :							str   				=do_normalize
						A__     :							Optional[int]   				=image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
						A__     :							Dict   				=image_std if image_std is not None else IMAGENET_STANDARD_STD
						A__     :							Union[str, Any]   				=include_top






		def       lowerCAmelCase_  (  self	,     __UpperCamelCase	,     __UpperCamelCase	,     __UpperCamelCase = PIL.Image.NEAREST	,     __UpperCamelCase = None	,     **__UpperCamelCase	,     )->			np.ndarray:
						'''simple docstring'''


						A__     :							Optional[int]   				=get_size_dict(__UpperCamelCase							)
						if "height" not in size or "width" not in size:
										raise ValueError(F'The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'							)
						return resize(
						    __UpperCamelCase	,     size=(size['''height'''], size['''width'''])	,     resample=__UpperCamelCase	,     data_format=__UpperCamelCase	,     **__UpperCamelCase							)






		def       lowerCAmelCase_  (  self	,     __UpperCamelCase	,     __UpperCamelCase	,     __UpperCamelCase = None	,     **__UpperCamelCase	,     )->			np.ndarray:
						'''simple docstring'''


						A__     :							Tuple   				=get_size_dict(__UpperCamelCase							)
						if "height" not in size or "width" not in size:
										raise ValueError(F'The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'							)
						return center_crop(__UpperCamelCase	,     size=(size['''height'''], size['''width'''])	,     data_format=__UpperCamelCase	,     **__UpperCamelCase							)






		def       lowerCAmelCase_  (  self	,     __UpperCamelCase	,     __UpperCamelCase	,     __UpperCamelCase = True	,     __UpperCamelCase = None	,     **__UpperCamelCase	,     )->			List[str]:
						'''simple docstring'''


						if offset:
										A__     :							str   				=(image - 127.5) * scale
										if data_format is not None:
														A__     :							Optional[Any]   				=to_channel_dimension_format(__UpperCamelCase	,     __UpperCamelCase							)
										A__     :							Any   				=rescaled_image.astype(np.floataa							)
						else:
										A__     :							List[Any]   				=rescale(__UpperCamelCase	,     scale=__UpperCamelCase	,     data_format=__UpperCamelCase	,     **__UpperCamelCase							)
						return rescaled_image






		def       lowerCAmelCase_  (  self	,     __UpperCamelCase	,     __UpperCamelCase	,     __UpperCamelCase	,     __UpperCamelCase = None	,     **__UpperCamelCase	,     )->			np.ndarray:
						'''simple docstring'''


						return normalize(__UpperCamelCase	,     mean=__UpperCamelCase	,     std=__UpperCamelCase	,     data_format=__UpperCamelCase	,     **__UpperCamelCase							)






		def       lowerCAmelCase_  (  self	,     __UpperCamelCase	,     __UpperCamelCase = None	,     __UpperCamelCase = None	,     __UpperCamelCase=None	,     __UpperCamelCase = None	,     __UpperCamelCase = None	,     __UpperCamelCase = None	,     __UpperCamelCase = None	,     __UpperCamelCase = None	,     __UpperCamelCase = None	,     __UpperCamelCase = None	,     __UpperCamelCase = None	,     __UpperCamelCase = None	,     __UpperCamelCase = None	,     __UpperCamelCase = ChannelDimension.FIRST	,     **__UpperCamelCase	,     )->			PIL.Image.Image:
						'''simple docstring'''


						A__     :							List[str]   				=do_resize if do_resize is not None else self.do_resize
						A__     :							List[Any]   				=resample if resample is not None else self.resample
						A__     :							int   				=do_center_crop if do_center_crop is not None else self.do_center_crop
						A__     :							int   				=do_rescale if do_rescale is not None else self.do_rescale
						A__     :							Optional[Any]   				=rescale_factor if rescale_factor is not None else self.rescale_factor
						A__     :							Optional[Any]   				=rescale_offset if rescale_offset is not None else self.rescale_offset
						A__     :							Optional[int]   				=do_normalize if do_normalize is not None else self.do_normalize
						A__     :							int   				=image_mean if image_mean is not None else self.image_mean
						A__     :							Optional[Any]   				=image_std if image_std is not None else self.image_std
						A__     :							Dict   				=include_top if include_top is not None else self.include_top

						A__     :							List[Any]   				=size if size is not None else self.size
						A__     :							Union[str, Any]   				=get_size_dict(__UpperCamelCase							)
						A__     :							Optional[Any]   				=crop_size if crop_size is not None else self.crop_size
						A__     :							Union[str, Any]   				=get_size_dict(__UpperCamelCase	,     param_name='''crop_size'''							)

						A__     :							Tuple   				=make_list_of_images(__UpperCamelCase							)

						if not valid_images(__UpperCamelCase							):
										raise ValueError(
										    '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
										    '''torch.Tensor, tf.Tensor or jax.ndarray.'''							)

						if do_resize and size is None or resample is None:
										raise ValueError('''Size and resample must be specified if do_resize is True.'''							)

						if do_center_crop and crop_size is None:
										raise ValueError('''Crop size must be specified if do_center_crop is True.'''							)

						if do_rescale and rescale_factor is None:
										raise ValueError('''Rescale factor must be specified if do_rescale is True.'''							)

						if do_normalize and (image_mean is None or image_std is None):
										raise ValueError('''Image mean and std must be specified if do_normalize is True.'''							)

						# All transformations expect numpy arrays.
						A__     :							int   				=[to_numpy_array(__UpperCamelCase							) for image in images]

						if do_resize:
										A__     :							Dict   				=[self.resize(image=__UpperCamelCase	,     size=__UpperCamelCase	,     resample=__UpperCamelCase							) for image in images]

						if do_center_crop:
										A__     :							int   				=[self.center_crop(image=__UpperCamelCase	,     size=__UpperCamelCase							) for image in images]

						if do_rescale:
										A__     :							Union[str, Any]   				=[self.rescale(image=__UpperCamelCase	,     scale=__UpperCamelCase	,     offset=__UpperCamelCase							) for image in images]

						if do_normalize:
										A__     :							Union[str, Any]   				=[self.normalize(image=__UpperCamelCase	,     mean=__UpperCamelCase	,     std=__UpperCamelCase							) for image in images]

						if include_top:
										A__     :							Tuple   				=[self.normalize(image=__UpperCamelCase	,     mean=[0, 0, 0]	,     std=__UpperCamelCase							) for image in images]

						A__     :							Optional[int]   				=[to_channel_dimension_format(__UpperCamelCase	,     __UpperCamelCase							) for image in images]

						A__     :							Optional[int]   				={'''pixel_values''': images}
						return BatchFeature(data=__UpperCamelCase	,     tensor_type=__UpperCamelCase							)







from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available



@dataclass
class 			a      (      UpperCamelCase_   ):
		__lowercase													=		{
		    """sld_warmup_steps""": 15,
		    """sld_guidance_scale""": 20,
		    """sld_threshold""": 0.0,
		    """sld_momentum_scale""": 0.0,
		    """sld_mom_beta""": 0.0,
		}
		__lowercase													=		{
		    """sld_warmup_steps""": 10,
		    """sld_guidance_scale""": 1_000,
		    """sld_threshold""": 0.01,
		    """sld_momentum_scale""": 0.3,
		    """sld_mom_beta""": 0.4,
		}
		__lowercase													=		{
		    """sld_warmup_steps""": 7,
		    """sld_guidance_scale""": 2_000,
		    """sld_threshold""": 0.0_25,
		    """sld_momentum_scale""": 0.5,
		    """sld_mom_beta""": 0.7,
		}
		__lowercase													=		{
		    """sld_warmup_steps""": 0,
		    """sld_guidance_scale""": 5_000,
		    """sld_threshold""": 1.0,
		    """sld_momentum_scale""": 0.5,
		    """sld_mom_beta""": 0.7,
		}







@dataclass
class 			a      (      UpperCamelCase_   ):
		__lowercase													=		42
		__lowercase													=		42
		__lowercase													=		42
		__lowercase													=		42


if is_transformers_available() and is_torch_available():
						from .pipeline_stable_diffusion_safe import StableDiffusionPipelineSafe
						from .safety_checker import SafeStableDiffusionSafetyChecker



