


'''simple docstring'''


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 convert_to_rgb, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_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__    	=     logging.get_logger(__name__)






class 	lowerCAmelCase__			(			UpperCAmelCase__	):
			lowerCAmelCase :	List[str]          =     ["pixel_values"]




			def __init__(		self  :     Optional[Any]	,  lowerCamelCase__  :     bool = True	,  lowerCamelCase__  :     Dict[str, int] = None	,  lowerCamelCase__  :     PILImageResampling = PILImageResampling.BICUBIC	,  lowerCamelCase__  :     bool = True	,  lowerCamelCase__  :     Union[int, float] = 1 / 2_55	,  lowerCamelCase__  :     bool = True	,  lowerCamelCase__  :     Optional[Union[float, List[float]]] = None	,  lowerCamelCase__  :     Optional[Union[float, List[float]]] = None	,  lowerCamelCase__  :     bool = True	,  **lowerCamelCase__  :     Optional[int]	,  )   ->None:



					'''simple docstring'''







					super().__init__(**lowerCamelCase__ )
					_UpperCAmelCase		:       Optional[int]								=      size if size is not None else {"height": 3_84, "width": 3_84}
					_UpperCAmelCase		:       str								=      get_size_dict(lowerCamelCase__	,  default_to_square=lowerCamelCase__ )

					_UpperCAmelCase		:       Dict								=      do_resize
					_UpperCAmelCase		:       List[str]								=      size
					_UpperCAmelCase		:       List[str]								=      resample
					_UpperCAmelCase		:       Optional[Any]								=      do_rescale
					_UpperCAmelCase		:       List[str]								=      rescale_factor
					_UpperCAmelCase		:       Optional[int]								=      do_normalize
					_UpperCAmelCase		:       Union[str, Any]								=      image_mean if image_mean is not None else OPENAI_CLIP_MEAN
					_UpperCAmelCase		:       Tuple								=      image_std if image_std is not None else OPENAI_CLIP_STD
					_UpperCAmelCase		:       Tuple								=      do_convert_rgb




			def 							lowerCAmelCase__    (		self  :     Optional[int]	,  lowerCamelCase__  :     np.ndarray	,  lowerCamelCase__  :     Dict[str, int]	,  lowerCamelCase__  :     PILImageResampling = PILImageResampling.BICUBIC	,  lowerCamelCase__  :     Optional[Union[str, ChannelDimension]] = None	,  **lowerCamelCase__  :     str	,  )   ->np.ndarray:



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[int]								=      get_size_dict(lowerCamelCase__	,  default_to_square=lowerCamelCase__ )
					if "height" not in size or "width" not in size:
							raise ValueError(F"""The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}""" )
					_UpperCAmelCase		:       Optional[Any]								=      (size["height"], size["width"])
					return resize(lowerCamelCase__	,  size=lowerCamelCase__	,  resample=lowerCamelCase__	,  data_format=lowerCamelCase__	,  **lowerCamelCase__ )




			def 							lowerCAmelCase__    (		self  :     Dict	,  lowerCamelCase__  :     np.ndarray	,  lowerCamelCase__  :     Union[int, float]	,  lowerCamelCase__  :     Optional[Union[str, ChannelDimension]] = None	,  **lowerCamelCase__  :     Tuple	,  )   ->str:



					'''simple docstring'''







					return rescale(lowerCamelCase__	,  scale=lowerCamelCase__	,  data_format=lowerCamelCase__	,  **lowerCamelCase__ )




			def 							lowerCAmelCase__    (		self  :     str	,  lowerCamelCase__  :     np.ndarray	,  lowerCamelCase__  :     Union[float, List[float]]	,  lowerCamelCase__  :     Union[float, List[float]]	,  lowerCamelCase__  :     Optional[Union[str, ChannelDimension]] = None	,  **lowerCamelCase__  :     List[str]	,  )   ->np.ndarray:



					'''simple docstring'''







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






			def 							lowerCAmelCase__    (		self  :     Optional[int]	,  lowerCamelCase__  :     ImageInput	,  lowerCamelCase__  :     Optional[bool] = None	,  lowerCamelCase__  :     Optional[Dict[str, int]] = None	,  lowerCamelCase__  :     PILImageResampling = None	,  lowerCamelCase__  :     Optional[bool] = None	,  lowerCamelCase__  :     Optional[float] = None	,  lowerCamelCase__  :     Optional[bool] = None	,  lowerCamelCase__  :     Optional[Union[float, List[float]]] = None	,  lowerCamelCase__  :     Optional[Union[float, List[float]]] = None	,  lowerCamelCase__  :     Optional[Union[str, TensorType]] = None	,  lowerCamelCase__  :     bool = None	,  lowerCamelCase__  :     ChannelDimension = ChannelDimension.FIRST	,  **lowerCamelCase__  :     Dict	,  )   ->PIL.Image.Image:



					'''simple docstring'''







					_UpperCAmelCase		:       Any								=      do_resize if do_resize is not None else self.do_resize
					_UpperCAmelCase		:       Any								=      resample if resample is not None else self.resample
					_UpperCAmelCase		:       Any								=      do_rescale if do_rescale is not None else self.do_rescale
					_UpperCAmelCase		:       Tuple								=      rescale_factor if rescale_factor is not None else self.rescale_factor
					_UpperCAmelCase		:       List[Any]								=      do_normalize if do_normalize is not None else self.do_normalize
					_UpperCAmelCase		:       Union[str, Any]								=      image_mean if image_mean is not None else self.image_mean
					_UpperCAmelCase		:       Dict								=      image_std if image_std is not None else self.image_std
					_UpperCAmelCase		:       Optional[Any]								=      do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

					_UpperCAmelCase		:       List[Any]								=      size if size is not None else self.size
					_UpperCAmelCase		:       Dict								=      get_size_dict(lowerCamelCase__	,  default_to_square=lowerCamelCase__ )

					_UpperCAmelCase		:       List[Any]								=      make_list_of_images(lowerCamelCase__ )

					if not valid_images(lowerCamelCase__ ):
							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_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." )

					# PIL RGBA images are converted to RGB
					if do_convert_rgb:
							_UpperCAmelCase		:       List[Any]								=      [convert_to_rgb(lowerCamelCase__ ) for image in images]

					# All transformations expect numpy arrays.
					_UpperCAmelCase		:       Any								=      [to_numpy_array(lowerCamelCase__ ) for image in images]

					if do_resize:
							_UpperCAmelCase		:       Union[str, Any]								=      [self.resize(image=lowerCamelCase__	,  size=lowerCamelCase__	,  resample=lowerCamelCase__ ) for image in images]

					if do_rescale:
							_UpperCAmelCase		:       List[Any]								=      [self.rescale(image=lowerCamelCase__	,  scale=lowerCamelCase__ ) for image in images]

					if do_normalize:
							_UpperCAmelCase		:       Dict								=      [self.normalize(image=lowerCamelCase__	,  mean=lowerCamelCase__	,  std=lowerCamelCase__ ) for image in images]

					_UpperCAmelCase		:       List[str]								=      [to_channel_dimension_format(lowerCamelCase__	,  lowerCamelCase__ ) for image in images]

					_UpperCAmelCase		:       List[str]								=      BatchFeature(data={"pixel_values": images}	,  tensor_type=lowerCamelCase__ )

					return encoded_outputs







'''simple docstring'''


from ...utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_torch_available,
    is_transformers_available,
)


try:
						if not (is_transformers_available() and is_torch_available()):
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
						from .multicontrolnet import MultiControlNetModel
						from .pipeline_controlnet import StableDiffusionControlNetPipeline
						from .pipeline_controlnet_imgaimg import StableDiffusionControlNetImgaImgPipeline
						from .pipeline_controlnet_inpaint import StableDiffusionControlNetInpaintPipeline


if is_transformers_available() and is_flax_available():
						from .pipeline_flax_controlnet import FlaxStableDiffusionControlNetPipeline



