






'''simple docstring'''




import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import is_speech_available, is_vision_available
from transformers.testing_utils import require_torch


if is_vision_available():
		from transformers import TvltImageProcessor

if is_speech_available():
		from transformers import TvltFeatureExtractor

from transformers import TvltProcessor







@require_torch
class       __lowercase					(unittest.TestCase    ):

	def      __UpperCamelCase							(      self   :						Any):
			UpperCamelCase__				:					Optional[int]					=					'ZinengTang/tvlt-base'
			UpperCamelCase__				:					Optional[int]					=					tempfile.mkdtemp()

	def      __UpperCamelCase							(      self   :						Tuple  ,					**UpperCAmelCase_   :						Any):
			return TvltImageProcessor.from_pretrained(self.checkpoint  ,					**UpperCAmelCase_)

	def      __UpperCamelCase							(      self   :						str  ,					**UpperCAmelCase_   :						int):
			return TvltFeatureExtractor.from_pretrained(self.checkpoint  ,					**UpperCAmelCase_)

	def      __UpperCamelCase							(      self   :						Dict):
			shutil.rmtree(self.tmpdirname)

	def      __UpperCamelCase							(      self   :						Tuple):
			UpperCamelCase__				:					Dict					=					self.get_image_processor()
			UpperCamelCase__				:					Union[str, Any]					=					self.get_feature_extractor()

			UpperCamelCase__				:					Any					=					TvltProcessor(image_processor=UpperCAmelCase_  ,					feature_extractor=UpperCAmelCase_)
			processor.save_pretrained(self.tmpdirname)
			UpperCamelCase__				:					Union[str, Any]					=					TvltProcessor.from_pretrained(self.tmpdirname)

			self.assertIsInstance(processor.feature_extractor  ,					UpperCAmelCase_)
			self.assertIsInstance(processor.image_processor  ,					UpperCAmelCase_)

	def      __UpperCamelCase							(      self   :						Optional[int]):
			UpperCamelCase__				:					Optional[int]					=					self.get_image_processor()
			UpperCamelCase__				:					Tuple					=					self.get_feature_extractor()

			UpperCamelCase__				:					Union[str, Any]					=					TvltProcessor(image_processor=UpperCAmelCase_  ,					feature_extractor=UpperCAmelCase_)

			UpperCamelCase__				:					List[str]					=					np.ones([12_000])

			UpperCamelCase__				:					Optional[Any]					=					feature_extractor(UpperCAmelCase_  ,					return_tensors='np')
			UpperCamelCase__				:					Optional[Any]					=					processor(audio=UpperCAmelCase_  ,					return_tensors='np')

			for key in audio_dict.keys():
					self.assertAlmostEqual(audio_dict[key].sum()  ,					input_processor[key].sum()  ,					delta=1e-2)

	def      __UpperCamelCase							(      self   :						Optional[int]):
			UpperCamelCase__				:					int					=					self.get_image_processor()
			UpperCamelCase__				:					Optional[int]					=					self.get_feature_extractor()

			UpperCamelCase__				:					Union[str, Any]					=					TvltProcessor(image_processor=UpperCAmelCase_  ,					feature_extractor=UpperCAmelCase_)

			UpperCamelCase__				:					Dict					=					np.ones([3, 224, 224])

			UpperCamelCase__				:					str					=					image_processor(UpperCAmelCase_  ,					return_tensors='np')
			UpperCamelCase__				:					Any					=					processor(images=UpperCAmelCase_  ,					return_tensors='np')

			for key in image_dict.keys():
					self.assertAlmostEqual(image_dict[key].sum()  ,					input_processor[key].sum()  ,					delta=1e-2)

	def      __UpperCamelCase							(      self   :						Union[str, Any]):
			UpperCamelCase__				:					List[Any]					=					self.get_image_processor()
			UpperCamelCase__				:					List[Any]					=					self.get_feature_extractor()

			UpperCamelCase__				:					Tuple					=					TvltProcessor(image_processor=UpperCAmelCase_  ,					feature_extractor=UpperCAmelCase_)

			UpperCamelCase__				:					int					=					np.ones([12_000])
			UpperCamelCase__				:					Optional[Any]					=					np.ones([3, 224, 224])

			UpperCamelCase__				:					str					=					processor(audio=UpperCAmelCase_  ,					images=UpperCAmelCase_)

			self.assertListEqual(list(inputs.keys())  ,					['audio_values', 'audio_mask', 'pixel_values', 'pixel_mask'])

			# test if it raises when no input is passed
			with pytest.raises(UpperCAmelCase_):
					processor()





	def      __UpperCamelCase							(      self   :						Any):
			UpperCamelCase__				:					Tuple					=					self.get_image_processor()
			UpperCamelCase__				:					Dict					=					self.get_feature_extractor()

			UpperCamelCase__				:					Dict					=					TvltProcessor(image_processor=UpperCAmelCase_  ,					feature_extractor=UpperCAmelCase_)

			self.assertListEqual(
			    processor.model_input_names  ,					image_processor.model_input_names + feature_extractor.model_input_names  ,					msg='`processor` and `image_processor`+`feature_extractor` model input names do not match'  ,					)












'''simple docstring'''




def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_)							->     list[str]:
		return [sentence[i : i + ngram_size] for i in range(len(lowerCamelCase_) - ngram_size + 1)]


if __name__ == "__main__":
		from doctest import testmod

		testmod()




