import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import BlipImageProcessor







class __snake_case							(		unittest.TestCase						):




   def __init__(       self     :							List[Any]			,      _lowercase     :							Union[str, Any]			,      _lowercase     :							int=7			,      _lowercase     :							Optional[int]=3			,      _lowercase     :							Optional[int]=18			,      _lowercase     :							Any=30			,      _lowercase     :							Union[str, Any]=4_00			,      _lowercase     :							Optional[int]=True			,      _lowercase     :							Optional[int]=None			,      _lowercase     :							str=True			,      _lowercase     :							Any=False			,      _lowercase     :							List[str]=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]			,      _lowercase     :							Optional[Any]=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]			,      _lowercase     :							List[str]=True			,      ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= size if size is not None else {"""height""": 20, """width""": 20}
     SCREAMING_SNAKE_CASE__     				= parent
     SCREAMING_SNAKE_CASE__     				= batch_size
     SCREAMING_SNAKE_CASE__     				= num_channels
     SCREAMING_SNAKE_CASE__     				= image_size
     SCREAMING_SNAKE_CASE__     				= min_resolution
     SCREAMING_SNAKE_CASE__     				= max_resolution
     SCREAMING_SNAKE_CASE__     				= do_resize
     SCREAMING_SNAKE_CASE__     				= size
     SCREAMING_SNAKE_CASE__     				= do_normalize
     SCREAMING_SNAKE_CASE__     				= image_mean
     SCREAMING_SNAKE_CASE__     				= image_std
     SCREAMING_SNAKE_CASE__     				= do_pad
     SCREAMING_SNAKE_CASE__     				= do_convert_rgb




   def       __a		(       self     :							List[str] ):



     """simple docstring"""






     return {
         "do_resize": self.do_resize,
         "size": self.size,
         "do_normalize": self.do_normalize,
         "image_mean": self.image_mean,
         "image_std": self.image_std,
         "do_convert_rgb": self.do_convert_rgb,
         "do_pad": self.do_pad,
     }




   def       __a		(       self     :							List[str]			,      _lowercase     :							Optional[int]=False			,      _lowercase     :							Any=False			,      _lowercase     :							Dict=False ):



     """simple docstring"""






     assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

     if equal_resolution:
       SCREAMING_SNAKE_CASE__     				= []
       for i in range(self.batch_size ):
         image_inputs.append(
             np.random.randint(
                 2_55			,      size=(self.num_channels, self.max_resolution, self.max_resolution)			,      dtype=np.uinta ) )
     else:
       SCREAMING_SNAKE_CASE__     				= []
       for i in range(self.batch_size ):
         SCREAMING_SNAKE_CASE__				,	SCREAMING_SNAKE_CASE__     				= np.random.choice(np.arange(self.min_resolution			,      self.max_resolution )			,      2 )
         image_inputs.append(np.random.randint(2_55			,      size=(self.num_channels, width, height)			,      dtype=np.uinta ) )

     if not numpify and not torchify:
       # PIL expects the channel dimension as last dimension
       SCREAMING_SNAKE_CASE__     				= [Image.fromarray(np.moveaxis(_lowercase			,      0			,      -1 ) ) for x in image_inputs]

     if torchify:
       SCREAMING_SNAKE_CASE__     				= [torch.from_numpy(_lowercase ) for x in image_inputs]

     return image_inputs







@require_torch
@require_vision
class __snake_case							(		lowerCamelCase_  ,						unittest.TestCase						):
   lowerCAmelCase_								=				BlipImageProcessor if is_vision_available() else None




   def       __a		(       self     :							int ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= BlipImageProcessingTester(self )




   @property
   def       __a		(       self     :							Optional[int] ):



     """simple docstring"""






     return self.image_processor_tester.prepare_image_processor_dict()




   def       __a		(       self     :							Tuple ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= self.image_processing_class(**self.image_processor_dict )
     self.assertTrue(hasattr(_lowercase			,      """do_resize""" ) )
     self.assertTrue(hasattr(_lowercase			,      """size""" ) )
     self.assertTrue(hasattr(_lowercase			,      """do_normalize""" ) )
     self.assertTrue(hasattr(_lowercase			,      """image_mean""" ) )
     self.assertTrue(hasattr(_lowercase			,      """image_std""" ) )
     self.assertTrue(hasattr(_lowercase			,      """do_convert_rgb""" ) )




   def       __a		(       self     :							List[str] ):



     """simple docstring"""






     pass




   def       __a		(       self     :							Optional[int] ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= self.image_processing_class(**self.image_processor_dict )
     # create random PIL images
     SCREAMING_SNAKE_CASE__     				= self.image_processor_tester.prepare_inputs(equal_resolution=_lowercase )
     for image in image_inputs:
       self.assertIsInstance(_lowercase			,      Image.Image )

     # Test not batched input
     SCREAMING_SNAKE_CASE__     				= image_processor(image_inputs[0]			,      return_tensors="""pt""" ).pixel_values
     self.assertEqual(
         encoded_images.shape			,      (
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size["""height"""],
             self.image_processor_tester.size["""width"""],
         )			,      )

     # Test batched
     SCREAMING_SNAKE_CASE__     				= image_processor(_lowercase			,      return_tensors="""pt""" ).pixel_values
     self.assertEqual(
         encoded_images.shape			,      (
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size["""height"""],
             self.image_processor_tester.size["""width"""],
         )			,      )




   def       __a		(       self     :							Tuple ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= self.image_processing_class(**self.image_processor_dict )
     # create random numpy tensors
     SCREAMING_SNAKE_CASE__     				= self.image_processor_tester.prepare_inputs(equal_resolution=_lowercase			,      numpify=_lowercase )
     for image in image_inputs:
       self.assertIsInstance(_lowercase			,      np.ndarray )

     # Test not batched input
     SCREAMING_SNAKE_CASE__     				= image_processor(image_inputs[0]			,      return_tensors="""pt""" ).pixel_values
     self.assertEqual(
         encoded_images.shape			,      (
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size["""height"""],
             self.image_processor_tester.size["""width"""],
         )			,      )

     # Test batched
     SCREAMING_SNAKE_CASE__     				= image_processor(_lowercase			,      return_tensors="""pt""" ).pixel_values
     self.assertEqual(
         encoded_images.shape			,      (
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size["""height"""],
             self.image_processor_tester.size["""width"""],
         )			,      )




   def       __a		(       self     :							Any ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= self.image_processing_class(**self.image_processor_dict )
     # create random PyTorch tensors
     SCREAMING_SNAKE_CASE__     				= self.image_processor_tester.prepare_inputs(equal_resolution=_lowercase			,      torchify=_lowercase )
     for image in image_inputs:
       self.assertIsInstance(_lowercase			,      torch.Tensor )

     # Test not batched input
     SCREAMING_SNAKE_CASE__     				= image_processor(image_inputs[0]			,      return_tensors="""pt""" ).pixel_values
     self.assertEqual(
         encoded_images.shape			,      (
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size["""height"""],
             self.image_processor_tester.size["""width"""],
         )			,      )

     # Test batched
     SCREAMING_SNAKE_CASE__     				= image_processor(_lowercase			,      return_tensors="""pt""" ).pixel_values
     self.assertEqual(
         encoded_images.shape			,      (
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size["""height"""],
             self.image_processor_tester.size["""width"""],
         )			,      )







@require_torch
@require_vision
class __snake_case							(		lowerCamelCase_  ,						unittest.TestCase						):
   lowerCAmelCase_								=				BlipImageProcessor if is_vision_available() else None




   def       __a		(       self     :							str ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= BlipImageProcessingTester(self			,      num_channels=4 )
     SCREAMING_SNAKE_CASE__     				= 3




   @property
   def       __a		(       self     :							Optional[Any] ):



     """simple docstring"""






     return self.image_processor_tester.prepare_image_processor_dict()




   def       __a		(       self     :							List[str] ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= self.image_processing_class(**self.image_processor_dict )
     self.assertTrue(hasattr(_lowercase			,      """do_resize""" ) )
     self.assertTrue(hasattr(_lowercase			,      """size""" ) )
     self.assertTrue(hasattr(_lowercase			,      """do_normalize""" ) )
     self.assertTrue(hasattr(_lowercase			,      """image_mean""" ) )
     self.assertTrue(hasattr(_lowercase			,      """image_std""" ) )
     self.assertTrue(hasattr(_lowercase			,      """do_convert_rgb""" ) )




   def       __a		(       self     :							Union[str, Any] ):



     """simple docstring"""






     pass




   def       __a		(       self     :							int ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= self.image_processing_class(**self.image_processor_dict )
     # create random PIL images
     SCREAMING_SNAKE_CASE__     				= self.image_processor_tester.prepare_inputs(equal_resolution=_lowercase )
     for image in image_inputs:
       self.assertIsInstance(_lowercase			,      Image.Image )

     # Test not batched input
     SCREAMING_SNAKE_CASE__     				= image_processor(image_inputs[0]			,      return_tensors="""pt""" ).pixel_values
     self.assertEqual(
         encoded_images.shape			,      (
             1,
             self.expected_encoded_image_num_channels,
             self.image_processor_tester.size["""height"""],
             self.image_processor_tester.size["""width"""],
         )			,      )

     # Test batched
     SCREAMING_SNAKE_CASE__     				= image_processor(_lowercase			,      return_tensors="""pt""" ).pixel_values
     self.assertEqual(
         encoded_images.shape			,      (
             self.image_processor_tester.batch_size,
             self.expected_encoded_image_num_channels,
             self.image_processor_tester.size["""height"""],
             self.image_processor_tester.size["""width"""],
         )			,      )

import unittest

import torch

from diffusers import DDIMScheduler, TextToVideoZeroPipeline
from diffusers.utils import load_pt, require_torch_gpu, slow

from ..test_pipelines_common import assert_mean_pixel_difference







@slow
@require_torch_gpu
class __snake_case							(		unittest.TestCase						):




   def       __a		(       self     :							List[Any] ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= """runwayml/stable-diffusion-v1-5"""
     SCREAMING_SNAKE_CASE__     				= TextToVideoZeroPipeline.from_pretrained(_lowercase			,      torch_dtype=torch.floataa ).to("""cuda""" )
     SCREAMING_SNAKE_CASE__     				= DDIMScheduler.from_config(pipe.scheduler.config )
     SCREAMING_SNAKE_CASE__     				= torch.Generator(device="""cuda""" ).manual_seed(0 )

     SCREAMING_SNAKE_CASE__     				= """A bear is playing a guitar on Times Square"""
     SCREAMING_SNAKE_CASE__     				= pipe(prompt=_lowercase			,      generator=_lowercase ).images

     SCREAMING_SNAKE_CASE__     				= load_pt(
         """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text-to-video/A bear is playing a guitar on Times Square.pt""" )

     assert_mean_pixel_difference(_lowercase			,      _lowercase )
