




'''simple docstring'''





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 TvltImageProcessor


def   UpperCamelCase_(			snake_case							: Optional[int]							,       snake_case							: Tuple=1_0							,       snake_case							: List[str]=1_0							,       snake_case							: int=False							,       snake_case							: Tuple=False  ):

       '''simple docstring'''






       snake_case_			      =   []
       for i in range(image_processor_tester.num_frames  ):
              video.append(np.random.randint(2_5_5							,       size=(image_processor_tester.num_channels, width, height)							,       dtype=np.uinta  )  )

       if not numpify and not torchify:
              # PIL expects the channel dimension as last dimension
              snake_case_			      =   [Image.fromarray(np.moveaxis(snake_case							,       0							,       -1  )  ) for frame in video]

       if torchify:
              snake_case_			      =   [torch.from_numpy(snake_case  ) for frame in video]

       return video


def   UpperCamelCase_(			snake_case							: str							,       snake_case							: Any=False							,       snake_case							: List[Any]=False							,       snake_case							: Any=False  ):

       '''simple docstring'''






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

       snake_case_			      =   []
       for i in range(image_processor_tester.batch_size  ):
              if equal_resolution:
                     snake_case_			      =   image_processor_tester.max_resolution
              else:
                     snake_case_			      =   np.random.choice(
                         np.arange(image_processor_tester.min_resolution							,       image_processor_tester.max_resolution  )							,       2  )
                     snake_case_			      =   prepare_video(
                         image_processor_tester=snake_case							,       width=snake_case							,       height=snake_case							,       numpify=snake_case							,       torchify=snake_case							,       )
              video_inputs.append(snake_case  )

       return video_inputs




class 				_snake_case	(			unittest.TestCase							):




   def __init__(      self       ,							a__       ,							a__=7       ,							a__=3       ,							a__=4       ,							a__=18       ,							a__=30       ,							a__=400       ,							a__=True       ,							a__=None       ,							a__=True       ,							a__=[0.5, 0.5, 0.5]       ,							a__=[0.5, 0.5, 0.5]       ,							a__=True       ,							a__=None       ,							)       ->       int:

          '''simple docstring'''




          snake_case_			      =   size if size is not None else {"""shortest_edge""": 18}
          snake_case_			      =   crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

          snake_case_			      =   parent
          snake_case_			      =   batch_size
          snake_case_			      =   num_channels
          snake_case_			      =   num_frames
          snake_case_			      =   image_size
          snake_case_			      =   min_resolution
          snake_case_			      =   max_resolution
          snake_case_			      =   do_resize
          snake_case_			      =   size
          snake_case_			      =   do_normalize
          snake_case_			      =   image_mean
          snake_case_			      =   image_std
          snake_case_			      =   do_center_crop
          snake_case_			      =   crop_size




   def      lowerCAmelCase__       (      self							)       ->       Dict:

          '''simple docstring'''




          return {
              "image_mean": self.image_mean,
              "image_std": self.image_std,
              "do_normalize": self.do_normalize,
              "do_resize": self.do_resize,
              "size": self.size,
              "do_center_crop": self.do_center_crop,
              "crop_size": self.crop_size,
          }




@require_torch
@require_vision
class 				_snake_case	(			lowerCAmelCase__		,		unittest.TestCase							):
   lowerCAmelCase_  :   Optional[Any]		 =					TvltImageProcessor if is_vision_available() else None




   def      lowerCAmelCase__       (      self							)       ->       Any:

          '''simple docstring'''




          snake_case_			      =   TvltImageProcessorTester(self							)




   @property
   def      lowerCAmelCase__       (      self							)       ->       List[Any]:

          '''simple docstring'''




          return self.image_processor_tester.prepare_image_processor_dict()




   def      lowerCAmelCase__       (      self							)       ->       List[str]:

          '''simple docstring'''




          snake_case_			      =   self.image_processing_class(**self.image_processor_dict							)
          self.assertTrue(hasattr(_lowerCamelCase       ,							"image_mean"							)							)
          self.assertTrue(hasattr(_lowerCamelCase       ,							"image_std"							)							)
          self.assertTrue(hasattr(_lowerCamelCase       ,							"do_normalize"							)							)
          self.assertTrue(hasattr(_lowerCamelCase       ,							"do_resize"							)							)
          self.assertTrue(hasattr(_lowerCamelCase       ,							"do_center_crop"							)							)
          self.assertTrue(hasattr(_lowerCamelCase       ,							"size"							)							)




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

          '''simple docstring'''




          snake_case_			      =   self.image_processing_class(**self.image_processor_dict							)
          # create random PIL videos
          snake_case_			      =   prepare_video_inputs(self.image_processor_tester       ,							equal_resolution=_lowerCamelCase							)
          for video in video_inputs:
                 self.assertIsInstance(_lowerCamelCase       ,							_lowerCamelCase							)
                 self.assertIsInstance(video[0]       ,							Image.Image							)

          # Test not batched input
          snake_case_			      =   image_processor(video_inputs[0]       ,							return_tensors="pt"							).pixel_values
          self.assertEqual(
              encoded_videos.shape       ,							(
                  1,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["height"],
                  self.image_processor_tester.crop_size["width"],
              )       ,							)

          # Test batched
          snake_case_			      =   image_processor(_lowerCamelCase       ,							return_tensors="pt"							).pixel_values
          self.assertEqual(
              encoded_videos.shape       ,							(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["height"],
                  self.image_processor_tester.crop_size["width"],
              )       ,							)




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

          '''simple docstring'''




          snake_case_			      =   self.image_processing_class(**self.image_processor_dict							)
          # create random numpy tensors
          snake_case_			      =   prepare_video_inputs(self.image_processor_tester       ,							equal_resolution=_lowerCamelCase       ,							numpify=_lowerCamelCase							)
          for video in video_inputs:
                 self.assertIsInstance(_lowerCamelCase       ,							_lowerCamelCase							)
                 self.assertIsInstance(video[0]       ,							np.ndarray							)

          # Test not batched input
          snake_case_			      =   image_processor(video_inputs[0]       ,							return_tensors="pt"							).pixel_values
          self.assertEqual(
              encoded_videos.shape       ,							(
                  1,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["height"],
                  self.image_processor_tester.crop_size["width"],
              )       ,							)

          # Test batched
          snake_case_			      =   image_processor(_lowerCamelCase       ,							return_tensors="pt"							).pixel_values
          self.assertEqual(
              encoded_videos.shape       ,							(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["height"],
                  self.image_processor_tester.crop_size["width"],
              )       ,							)




   def      lowerCAmelCase__       (      self							)       ->       Tuple:

          '''simple docstring'''




          snake_case_			      =   self.image_processing_class(**self.image_processor_dict							)
          # create random PyTorch tensors
          snake_case_			      =   prepare_video_inputs(self.image_processor_tester       ,							equal_resolution=_lowerCamelCase       ,							torchify=_lowerCamelCase							)
          for video in video_inputs:
                 self.assertIsInstance(_lowerCamelCase       ,							_lowerCamelCase							)
                 self.assertIsInstance(video[0]       ,							torch.Tensor							)

          # Test not batched input
          snake_case_			      =   image_processor(video_inputs[0]       ,							return_tensors="pt"							).pixel_values
          self.assertEqual(
              encoded_videos.shape       ,							(
                  1,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["height"],
                  self.image_processor_tester.crop_size["width"],
              )       ,							)

          # Test batched
          snake_case_			      =   image_processor(_lowerCamelCase       ,							return_tensors="pt"							).pixel_values
          self.assertEqual(
              encoded_videos.shape       ,							(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["height"],
                  self.image_processor_tester.crop_size["width"],
              )       ,							)










'''simple docstring'''





import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import Mock, patch

import diffusers.utils.hub_utils




class 				_snake_case	(			unittest.TestCase							):




			@patch("diffusers.utils.hub_utils.get_full_repo_name"							)
			def      lowerCAmelCase__       (      self       ,							a__							)       ->       None:

										'''simple docstring'''




										snake_case_			      =   "full_repo_name"
										with TemporaryDirectory() as tmpdir:
																	# Dummy args values
																	snake_case_			      =   Mock()
																	snake_case_			      =   tmpdir
																	snake_case_			      =   0
																	snake_case_			      =   "hub_token"
																	snake_case_			      =   "dataset_name"
																	snake_case_			      =   0.0_1
																	snake_case_			      =   100_000
																	snake_case_			      =   10_000
																	snake_case_			      =   0.0_1
																	snake_case_			      =   0.0_2
																	snake_case_			      =   0.0_3
																	snake_case_			      =   0.0_0_0_5
																	snake_case_			      =   0.0_0_0_0_0_1
																	snake_case_			      =   1
																	snake_case_			      =   10
																	snake_case_			      =   0.0_0_1
																	snake_case_			      =   0.1
																	snake_case_			      =   0.2
																	snake_case_			      =   True

																	# Model card mush be rendered and saved
																	diffusers.utils.hub_utils.create_model_card(a__       ,							model_name="model_name"							)
																	self.assertTrue((Path(a__							) / "README.md").is_file()							)




