
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,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
     import PIL


lowerCamelCase__    :		Optional[Any]          =   logging.get_logger(__name__)

def 		UpperCamelCase	(      lowercase_   )		->	List[List[ImageInput]]:


  '''simple docstring'''






  if isinstance(lowercase_ , (list, tuple)   ) and isinstance(videos[0] , (list, tuple)   ) and is_valid_image(videos[0][0]   ):
    return videos

  elif isinstance(lowercase_ , (list, tuple)   ) and is_valid_image(videos[0]   ):
    return [videos]

  elif is_valid_image(lowercase_   ):
    return [[videos]]

  raise ValueError(F'Could not make batched video from {videos}'   )



class       _snake_case   (	UpperCAmelCase_							):
 __lowerCAmelCase  :     List[Any]        =			['pixel_values']


 def __init__(					self					,  SCREAMING_SNAKE_CASE_ = True					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = PILImageResampling.BILINEAR					,  SCREAMING_SNAKE_CASE_ = True					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = True					,  SCREAMING_SNAKE_CASE_ = 1 / 2_55					,  SCREAMING_SNAKE_CASE_ = True					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  **SCREAMING_SNAKE_CASE_					,  ):


   '''simple docstring'''




   super().__init__(**SCREAMING_SNAKE_CASE_)
   lowercase__  :   Dict    		=      size if size is not None else {"""shortest_edge""": 2_24}
   lowercase__  :   Optional[Any]    		=      get_size_dict(SCREAMING_SNAKE_CASE_					,  default_to_square=SCREAMING_SNAKE_CASE_)
   lowercase__  :   Union[str, Any]    		=      crop_size if crop_size is not None else {"""height""": 2_24, """width""": 2_24}
   lowercase__  :   int    		=      get_size_dict(SCREAMING_SNAKE_CASE_					,  param_name="""crop_size""")

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


 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_ = PILImageResampling.BILINEAR					,  SCREAMING_SNAKE_CASE_ = None					,  **SCREAMING_SNAKE_CASE_					,  ):


   '''simple docstring'''




   lowercase__  :   str    		=      get_size_dict(SCREAMING_SNAKE_CASE_					,  default_to_square=SCREAMING_SNAKE_CASE_)
   if "shortest_edge" in size:
     lowercase__  :   List[Any]    		=      get_resize_output_image_size(SCREAMING_SNAKE_CASE_					,  size["""shortest_edge"""]					,  default_to_square=SCREAMING_SNAKE_CASE_)
   elif "height" in size and "width" in size:
     lowercase__  :   Any    		=      (size["""height"""], size["""width"""])
   else:
     raise ValueError(f'Size must have \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}')
   return resize(SCREAMING_SNAKE_CASE_					,  size=SCREAMING_SNAKE_CASE_					,  resample=SCREAMING_SNAKE_CASE_					,  data_format=SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_)


 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_ = None					,  **SCREAMING_SNAKE_CASE_					,  ):


   '''simple docstring'''




   lowercase__  :   List[Any]    		=      get_size_dict(SCREAMING_SNAKE_CASE_)
   if "height" not in size or "width" not in size:
     raise ValueError(f'Size must have \'height\' and \'width\' as keys. Got {size.keys()}')
   return center_crop(SCREAMING_SNAKE_CASE_					,  size=(size["""height"""], size["""width"""])					,  data_format=SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_)


 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_ = None					,  **SCREAMING_SNAKE_CASE_					,  ):


   '''simple docstring'''




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


 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_ = None					,  **SCREAMING_SNAKE_CASE_					,  ):


   '''simple docstring'''




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


 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = ChannelDimension.FIRST					,  ):


   '''simple docstring'''




   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.
   lowercase__  :   Optional[Any]    		=      to_numpy_array(SCREAMING_SNAKE_CASE_)

   if do_resize:
     lowercase__  :   Tuple    		=      self.resize(image=SCREAMING_SNAKE_CASE_					,  size=SCREAMING_SNAKE_CASE_					,  resample=SCREAMING_SNAKE_CASE_)

   if do_center_crop:
     lowercase__  :   Tuple    		=      self.center_crop(SCREAMING_SNAKE_CASE_					,  size=SCREAMING_SNAKE_CASE_)

   if do_rescale:
     lowercase__  :   Tuple    		=      self.rescale(image=SCREAMING_SNAKE_CASE_					,  scale=SCREAMING_SNAKE_CASE_)

   if do_normalize:
     lowercase__  :   List[Any]    		=      self.normalize(image=SCREAMING_SNAKE_CASE_					,  mean=SCREAMING_SNAKE_CASE_					,  std=SCREAMING_SNAKE_CASE_)

   lowercase__  :   Optional[int]    		=      to_channel_dimension_format(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_)
   return image



 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = ChannelDimension.FIRST					,  **SCREAMING_SNAKE_CASE_					,  ):


   '''simple docstring'''




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

   lowercase__  :   List[Any]    		=      size if size is not None else self.size
   lowercase__  :   List[str]    		=      get_size_dict(SCREAMING_SNAKE_CASE_					,  default_to_square=SCREAMING_SNAKE_CASE_)
   lowercase__  :   List[Any]    		=      crop_size if crop_size is not None else self.crop_size
   lowercase__  :   Any    		=      get_size_dict(SCREAMING_SNAKE_CASE_					,  param_name="""crop_size""")

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

   lowercase__  :   Optional[Any]    		=      make_batched(SCREAMING_SNAKE_CASE_)

   lowercase__  :   Optional[Any]    		=      [
       [
           self._preprocess_image(
               image=SCREAMING_SNAKE_CASE_					,  do_resize=SCREAMING_SNAKE_CASE_					,  size=SCREAMING_SNAKE_CASE_					,  resample=SCREAMING_SNAKE_CASE_					,  do_center_crop=SCREAMING_SNAKE_CASE_					,  crop_size=SCREAMING_SNAKE_CASE_					,  do_rescale=SCREAMING_SNAKE_CASE_					,  rescale_factor=SCREAMING_SNAKE_CASE_					,  do_normalize=SCREAMING_SNAKE_CASE_					,  image_mean=SCREAMING_SNAKE_CASE_					,  image_std=SCREAMING_SNAKE_CASE_					,  data_format=SCREAMING_SNAKE_CASE_					,  )
           for img in video
       ]
       for video in videos
   ]

   lowercase__  :   str    		=      {"""pixel_values""": videos}
   return BatchFeature(data=SCREAMING_SNAKE_CASE_					,  tensor_type=SCREAMING_SNAKE_CASE_)








lowerCamelCase__    :		Any          =   """0.18.2"""

from .configuration_utils import ConfigMixin
from .utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_inflect_available,
    is_invisible_watermark_available,
    is_k_diffusion_available,
    is_k_diffusion_version,
    is_librosa_available,
    is_note_seq_available,
    is_onnx_available,
    is_scipy_available,
    is_torch_available,
    is_torchsde_available,
    is_transformers_available,
    is_transformers_version,
    is_unidecode_available,
    logging,
)


try:
     if not is_onnx_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from .utils.dummy_onnx_objects import *  # noqa F403
else:
     from .pipelines import OnnxRuntimeModel

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from .utils.dummy_pt_objects import *  # noqa F403
else:
     from .models import (
         AutoencoderKL,
         ControlNetModel,
         ModelMixin,
         PriorTransformer,
         TaFilmDecoder,
         TransformeraDModel,
         UNetaDModel,
         UNetaDConditionModel,
         UNetaDModel,
         UNetaDConditionModel,
         VQModel,
     )
     from .optimization import (
         get_constant_schedule,
         get_constant_schedule_with_warmup,
         get_cosine_schedule_with_warmup,
         get_cosine_with_hard_restarts_schedule_with_warmup,
         get_linear_schedule_with_warmup,
         get_polynomial_decay_schedule_with_warmup,
         get_scheduler,
     )
     from .pipelines import (
         AudioPipelineOutput,
         ConsistencyModelPipeline,
         DanceDiffusionPipeline,
         DDIMPipeline,
         DDPMPipeline,
         DiffusionPipeline,
         DiTPipeline,
         ImagePipelineOutput,
         KarrasVePipeline,
         LDMPipeline,
         LDMSuperResolutionPipeline,
         PNDMPipeline,
         RePaintPipeline,
         ScoreSdeVePipeline,
     )
     from .schedulers import (
         CMStochasticIterativeScheduler,
         DDIMInverseScheduler,
         DDIMParallelScheduler,
         DDIMScheduler,
         DDPMParallelScheduler,
         DDPMScheduler,
         DEISMultistepScheduler,
         DPMSolverMultistepInverseScheduler,
         DPMSolverMultistepScheduler,
         DPMSolverSinglestepScheduler,
         EulerAncestralDiscreteScheduler,
         EulerDiscreteScheduler,
         HeunDiscreteScheduler,
         IPNDMScheduler,
         KarrasVeScheduler,
         KDPMaAncestralDiscreteScheduler,
         KDPMaDiscreteScheduler,
         PNDMScheduler,
         RePaintScheduler,
         SchedulerMixin,
         ScoreSdeVeScheduler,
         UnCLIPScheduler,
         UniPCMultistepScheduler,
         VQDiffusionScheduler,
     )
     from .training_utils import EMAModel

try:
     if not (is_torch_available() and is_scipy_available()):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from .utils.dummy_torch_and_scipy_objects import *  # noqa F403
else:
     from .schedulers import LMSDiscreteScheduler

try:
     if not (is_torch_available() and is_torchsde_available()):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from .utils.dummy_torch_and_torchsde_objects import *  # noqa F403
else:
     from .schedulers import DPMSolverSDEScheduler

try:
     if not (is_torch_available() and is_transformers_available()):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from .utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
     from .pipelines import (
         AltDiffusionImgaImgPipeline,
         AltDiffusionPipeline,
         AudioLDMPipeline,
         CycleDiffusionPipeline,
         IFImgaImgPipeline,
         IFImgaImgSuperResolutionPipeline,
         IFInpaintingPipeline,
         IFInpaintingSuperResolutionPipeline,
         IFPipeline,
         IFSuperResolutionPipeline,
         ImageTextPipelineOutput,
         KandinskyImgaImgPipeline,
         KandinskyInpaintPipeline,
         KandinskyPipeline,
         KandinskyPriorPipeline,
         KandinskyVaaControlnetImgaImgPipeline,
         KandinskyVaaControlnetPipeline,
         KandinskyVaaImgaImgPipeline,
         KandinskyVaaInpaintPipeline,
         KandinskyVaaPipeline,
         KandinskyVaaPriorEmbaEmbPipeline,
         KandinskyVaaPriorPipeline,
         LDMTextToImagePipeline,
         PaintByExamplePipeline,
         SemanticStableDiffusionPipeline,
         ShapEImgaImgPipeline,
         ShapEPipeline,
         StableDiffusionAttendAndExcitePipeline,
         StableDiffusionControlNetImgaImgPipeline,
         StableDiffusionControlNetInpaintPipeline,
         StableDiffusionControlNetPipeline,
         StableDiffusionDepthaImgPipeline,
         StableDiffusionDiffEditPipeline,
         StableDiffusionImageVariationPipeline,
         StableDiffusionImgaImgPipeline,
         StableDiffusionInpaintPipeline,
         StableDiffusionInpaintPipelineLegacy,
         StableDiffusionInstructPixaPixPipeline,
         StableDiffusionLatentUpscalePipeline,
         StableDiffusionLDMaDPipeline,
         StableDiffusionModelEditingPipeline,
         StableDiffusionPanoramaPipeline,
         StableDiffusionParadigmsPipeline,
         StableDiffusionPipeline,
         StableDiffusionPipelineSafe,
         StableDiffusionPixaPixZeroPipeline,
         StableDiffusionSAGPipeline,
         StableDiffusionUpscalePipeline,
         StableUnCLIPImgaImgPipeline,
         StableUnCLIPPipeline,
         TextToVideoSDPipeline,
         TextToVideoZeroPipeline,
         UnCLIPImageVariationPipeline,
         UnCLIPPipeline,
         UniDiffuserModel,
         UniDiffuserPipeline,
         UniDiffuserTextDecoder,
         VersatileDiffusionDualGuidedPipeline,
         VersatileDiffusionImageVariationPipeline,
         VersatileDiffusionPipeline,
         VersatileDiffusionTextToImagePipeline,
         VideoToVideoSDPipeline,
         VQDiffusionPipeline,
     )

try:
     if not (is_torch_available() and is_transformers_available() and is_invisible_watermark_available()):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from .utils.dummy_torch_and_transformers_and_invisible_watermark_objects import *  # noqa F403
else:
     from .pipelines import StableDiffusionXLImgaImgPipeline, StableDiffusionXLPipeline

try:
     if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from .utils.dummy_torch_and_transformers_and_k_diffusion_objects import *  # noqa F403
else:
     from .pipelines import StableDiffusionKDiffusionPipeline

try:
     if not (is_torch_available() and is_transformers_available() and is_onnx_available()):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from .utils.dummy_torch_and_transformers_and_onnx_objects import *  # noqa F403
else:
     from .pipelines import (
         OnnxStableDiffusionImgaImgPipeline,
         OnnxStableDiffusionInpaintPipeline,
         OnnxStableDiffusionInpaintPipelineLegacy,
         OnnxStableDiffusionPipeline,
         OnnxStableDiffusionUpscalePipeline,
         StableDiffusionOnnxPipeline,
     )

try:
     if not (is_torch_available() and is_librosa_available()):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from .utils.dummy_torch_and_librosa_objects import *  # noqa F403
else:
     from .pipelines import AudioDiffusionPipeline, Mel

try:
     if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from .utils.dummy_transformers_and_torch_and_note_seq_objects import *  # noqa F403
else:
     from .pipelines import SpectrogramDiffusionPipeline

try:
     if not is_flax_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from .utils.dummy_flax_objects import *  # noqa F403
else:
     from .models.controlnet_flax import FlaxControlNetModel
     from .models.modeling_flax_utils import FlaxModelMixin
     from .models.unet_ad_condition_flax import FlaxUNetaDConditionModel
     from .models.vae_flax import FlaxAutoencoderKL
     from .pipelines import FlaxDiffusionPipeline
     from .schedulers import (
         FlaxDDIMScheduler,
         FlaxDDPMScheduler,
         FlaxDPMSolverMultistepScheduler,
         FlaxKarrasVeScheduler,
         FlaxLMSDiscreteScheduler,
         FlaxPNDMScheduler,
         FlaxSchedulerMixin,
         FlaxScoreSdeVeScheduler,
     )


try:
     if not (is_flax_available() and is_transformers_available()):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from .utils.dummy_flax_and_transformers_objects import *  # noqa F403
else:
     from .pipelines import (
         FlaxStableDiffusionControlNetPipeline,
         FlaxStableDiffusionImgaImgPipeline,
         FlaxStableDiffusionInpaintPipeline,
         FlaxStableDiffusionPipeline,
     )

try:
     if not (is_note_seq_available()):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from .utils.dummy_note_seq_objects import *  # noqa F403
else:
     from .pipelines import MidiProcessor






