

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, prepare_video_inputs


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import VivitImageProcessor



class    _a						(unittest.TestCase    ):


					'''simple docstring'''






					def __init__(			self   ,	A__   ,	A__=7   ,	A__=3   ,	A__=10   ,	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__=None   ,	):
						A__							:   List[str]					       =		size if size is not None else {'shortest_edge': 18}
						A__							:   Union[str, Any]					       =		crop_size if crop_size is not None else {'height': 18, 'width': 18}

						A__							:   List[str]					       =		parent
						A__							:   Dict					       =		batch_size
						A__							:   Tuple					       =		num_channels
						A__							:   Optional[Any]					       =		num_frames
						A__							:   List[Any]					       =		image_size
						A__							:   Optional[int]					       =		min_resolution
						A__							:   Dict					       =		max_resolution
						A__							:   Dict					       =		do_resize
						A__							:   Any					       =		size
						A__							:   int					       =		do_normalize
						A__							:   Optional[int]					       =		image_mean
						A__							:   List[str]					       =		image_std
						A__							:   Optional[int]					       =		crop_size






					def   __A      (			self      ):
						return {
						    "image_mean": self.image_mean,
						    "image_std": self.image_std,
						    "do_normalize": self.do_normalize,
						    "do_resize": self.do_resize,
						    "size": self.size,
						    "crop_size": self.crop_size,
						}



@require_torch
@require_vision
class    _a						(__UpperCamelCase		,       unittest.TestCase    ):


					'''simple docstring'''






					UpperCAmelCase__:       Any  							=	VivitImageProcessor if is_vision_available() else None






					def   __A      (			self      ):
						A__							:   str					       =		VivitImageProcessingTester(self      )






					@property
					def   __A      (			self      ):
						return self.image_processor_tester.prepare_image_processor_dict()






					def   __A      (			self      ):
						A__							:   Union[str, Any]					       =		self.image_processing_class(**self.image_processor_dict      )
						self.assertTrue(hasattr(A__   ,	"""image_mean"""      )      )
						self.assertTrue(hasattr(A__   ,	"""image_std"""      )      )
						self.assertTrue(hasattr(A__   ,	"""do_normalize"""      )      )
						self.assertTrue(hasattr(A__   ,	"""do_resize"""      )      )
						self.assertTrue(hasattr(A__   ,	"""do_center_crop"""      )      )
						self.assertTrue(hasattr(A__   ,	"""size"""      )      )






					def   __A      (			self      ):
						A__							:   List[Any]					       =		self.image_processing_class.from_dict(self.image_processor_dict      )
						self.assertEqual(image_processor.size   ,	{"""shortest_edge""": 18}      )
						self.assertEqual(image_processor.crop_size   ,	{"""height""": 18, """width""": 18}      )

						A__							:   Optional[Any]					       =		self.image_processing_class.from_dict(self.image_processor_dict   ,	size=42   ,	crop_size=84      )
						self.assertEqual(image_processor.size   ,	{"""shortest_edge""": 42}      )
						self.assertEqual(image_processor.crop_size   ,	{"""height""": 84, """width""": 84}      )






					def   __A      (			self      ):
						# Initialize image_processing
						A__							:   int					       =		self.image_processing_class(**self.image_processor_dict      )
						# create random PIL videos
						A__							:   Optional[int]					       =		prepare_video_inputs(self.image_processor_tester   ,	equal_resolution=A__      )
						for video in video_inputs:
							self.assertIsInstance(A__   ,	A__      )
							self.assertIsInstance(video[0]   ,	Image.Image      )

						# Test not batched input
						A__							:   int					       =		image_processing(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
						A__							:   Any					       =		image_processing(A__   ,	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   __A      (			self      ):
						# Initialize image_processing
						A__							:   Dict					       =		self.image_processing_class(**self.image_processor_dict      )
						# create random numpy tensors
						A__							:   str					       =		prepare_video_inputs(self.image_processor_tester   ,	equal_resolution=A__   ,	numpify=A__      )
						for video in video_inputs:
							self.assertIsInstance(A__   ,	A__      )
							self.assertIsInstance(video[0]   ,	np.ndarray      )

						# Test not batched input
						A__							:   Optional[int]					       =		image_processing(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
						A__							:   List[Any]					       =		image_processing(A__   ,	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   __A      (			self      ):
						# Initialize image_processing
						A__							:   Tuple					       =		self.image_processing_class(**self.image_processor_dict      )
						# create random PyTorch tensors
						A__							:   int					       =		prepare_video_inputs(self.image_processor_tester   ,	equal_resolution=A__   ,	torchify=A__      )
						for video in video_inputs:
							self.assertIsInstance(A__   ,	A__      )
							self.assertIsInstance(video[0]   ,	torch.Tensor      )

						# Test not batched input
						A__							:   Tuple					       =		image_processing(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
						A__							:   str					       =		image_processing(A__   ,	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"""],
						    )   ,	)






import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin



class    _a						(__magic_name__    ):


					'''simple docstring'''






					UpperCAmelCase__:       Optional[Any]  							=	'''MCTCTFeatureExtractor'''
					UpperCAmelCase__:       Optional[int]  							=	'''AutoTokenizer'''






					def __init__(			self   ,	A__   ,	A__      ):
						super().__init__(A__   ,	A__      )
						A__							:   List[str]					       =		self.feature_extractor
						A__							:   Optional[int]					       =		False






					def __call__(			self   ,	*A__   ,	**A__      ):
						# For backward compatibility
						if self._in_target_context_manager:
							return self.current_processor(*A__   ,	**A__      )

						if "raw_speech" in kwargs:
							warnings.warn("""Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."""      )
							A__							:   Dict					       =		kwargs.pop("""raw_speech"""      )
						else:
							A__							:   Tuple					       =		kwargs.pop("""audio"""   ,	A__      )
						A__							:   Union[str, Any]					       =		kwargs.pop("""sampling_rate"""   ,	A__      )
						A__							:   int					       =		kwargs.pop("""text"""   ,	A__      )
						if len(A__      ) > 0:
							A__							:   Optional[int]					       =		args[0]
							A__							:   Dict					       =		args[1:]

						if audio is None and text is None:
							raise ValueError("""You need to specify either an `audio` or `text` input to process."""      )

						if audio is not None:
							A__							:   List[str]					       =		self.feature_extractor(A__   ,	*A__   ,	sampling_rate=A__   ,	**A__      )
						if text is not None:
							A__							:   Optional[Any]					       =		self.tokenizer(A__   ,	**A__      )

						if text is None:
							return inputs
						elif audio is None:
							return encodings
						else:
							A__							:   List[Any]					       =		encodings["""input_ids"""]
							return inputs






					def   __A      (			self   ,	*A__   ,	**A__      ):
						return self.tokenizer.batch_decode(*A__   ,	**A__      )






					def   __A      (			self   ,	*A__   ,	**A__      ):
						# For backward compatibility
						if self._in_target_context_manager:
							return self.current_processor.pad(*A__   ,	**A__      )

						A__							:   Optional[Any]					       =		kwargs.pop("""input_features"""   ,	A__      )
						A__							:   Union[str, Any]					       =		kwargs.pop("""labels"""   ,	A__      )
						if len(A__      ) > 0:
							A__							:   List[Any]					       =		args[0]
							A__							:   Optional[int]					       =		args[1:]

						if input_features is not None:
							A__							:   Union[str, Any]					       =		self.feature_extractor.pad(A__   ,	*A__   ,	**A__      )
						if labels is not None:
							A__							:   List[Any]					       =		self.tokenizer.pad(A__   ,	**A__      )

						if labels is None:
							return input_features
						elif input_features is None:
							return labels
						else:
							A__							:   Dict					       =		labels["""input_ids"""]
							return input_features






					def   __A      (			self   ,	*A__   ,	**A__      ):
						return self.tokenizer.decode(*A__   ,	**A__      )






					@contextmanager
					def   __A      (			self      ):
						warnings.warn(
						    """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
						    """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
						    """your audio inputs, or in a separate call."""      )
						A__							:   int					       =		True
						A__							:   List[Any]					       =		self.tokenizer
						yield
						A__							:   Tuple					       =		self.feature_extractor
						A__							:   Dict					       =		False



