





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 	UpperCamelCase_							(  unittest.TestCase     ):


							def   _snake_case	(				self     :Dict		) -> List[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   """ZinengTang/tvlt-base"""
									SCREAMING_SNAKE_CASE__								=   tempfile.mkdtemp()


							def   _snake_case	(				self     :Optional[int]				,					**__A     :List[str]		) -> Union[str, Any]:



									"""simple docstring"""



									return TvltImageProcessor.from_pretrained(self.checkpoint				,					**__A		)


							def   _snake_case	(				self     :Dict				,					**__A     :Union[str, Any]		) -> str:



									"""simple docstring"""



									return TvltFeatureExtractor.from_pretrained(self.checkpoint				,					**__A		)


							def   _snake_case	(				self     :List[Any]		) -> List[Any]:



									"""simple docstring"""



									shutil.rmtree(self.tmpdirname		)


							def   _snake_case	(				self     :Tuple		) -> Optional[int]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.get_image_processor()
									SCREAMING_SNAKE_CASE__								=   self.get_feature_extractor()

									SCREAMING_SNAKE_CASE__								=   TvltProcessor(image_processor=__A				,					feature_extractor=__A		)
									processor.save_pretrained(self.tmpdirname		)
									SCREAMING_SNAKE_CASE__								=   TvltProcessor.from_pretrained(self.tmpdirname		)

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


							def   _snake_case	(				self     :List[Any]		) -> Dict:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.get_image_processor()
									SCREAMING_SNAKE_CASE__								=   self.get_feature_extractor()

									SCREAMING_SNAKE_CASE__								=   TvltProcessor(image_processor=__A				,					feature_extractor=__A		)

									SCREAMING_SNAKE_CASE__								=   np.ones([1_2000]		)

									SCREAMING_SNAKE_CASE__								=   feature_extractor(__A				,					return_tensors="""np"""		)
									SCREAMING_SNAKE_CASE__								=   processor(audio=__A				,					return_tensors="""np"""		)

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


							def   _snake_case	(				self     :Dict		) -> int:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.get_image_processor()
									SCREAMING_SNAKE_CASE__								=   self.get_feature_extractor()

									SCREAMING_SNAKE_CASE__								=   TvltProcessor(image_processor=__A				,					feature_extractor=__A		)

									SCREAMING_SNAKE_CASE__								=   np.ones([3, 224, 224]		)

									SCREAMING_SNAKE_CASE__								=   image_processor(__A				,					return_tensors="""np"""		)
									SCREAMING_SNAKE_CASE__								=   processor(images=__A				,					return_tensors="""np"""		)

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


							def   _snake_case	(				self     :Tuple		) -> int:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.get_image_processor()
									SCREAMING_SNAKE_CASE__								=   self.get_feature_extractor()

									SCREAMING_SNAKE_CASE__								=   TvltProcessor(image_processor=__A				,					feature_extractor=__A		)

									SCREAMING_SNAKE_CASE__								=   np.ones([1_2000]		)
									SCREAMING_SNAKE_CASE__								=   np.ones([3, 224, 224]		)

									SCREAMING_SNAKE_CASE__								=   processor(audio=__A				,					images=__A		)

									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(__A		):
											processor()


							def   _snake_case	(				self     :Dict		) -> Optional[int]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.get_image_processor()
									SCREAMING_SNAKE_CASE__								=   self.get_feature_extractor()

									SCREAMING_SNAKE_CASE__								=   TvltProcessor(image_processor=__A				,					feature_extractor=__A		)

									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"""				,					)






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_flax_available, is_torch_available


_lowerCamelCase 					=      {'configuration_speech_encoder_decoder': ['SpeechEncoderDecoderConfig']}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowerCamelCase 					=      ['SpeechEncoderDecoderModel']

try:
	if not is_flax_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowerCamelCase 					=      ['FlaxSpeechEncoderDecoderModel']

if TYPE_CHECKING:
	from .configuration_speech_encoder_decoder import SpeechEncoderDecoderConfig

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_speech_encoder_decoder import SpeechEncoderDecoderModel

	try:
		if not is_flax_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_flax_speech_encoder_decoder import FlaxSpeechEncoderDecoderModel

else:
	import sys

	_lowerCamelCase 					=      _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)