






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





				"""simple docstring"""







				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Union[str, Any]       		="ZinengTang/tvlt-base"
									__UpperCamelCase      :					Dict       		=tempfile.mkdtemp()


				def       __lowercase							( self							,  **lowerCamelCase__    ):




									"""simple docstring"""

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


				def       __lowercase							( self							,  **lowerCamelCase__    ):




									"""simple docstring"""

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


				def       __lowercase							( self    ):




									"""simple docstring"""

									shutil.rmtree(self.tmpdirname    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Tuple       		=self.get_image_processor()
									__UpperCamelCase      :					List[Any]       		=self.get_feature_extractor()

									__UpperCamelCase      :					Any       		=TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE							,  feature_extractor=_SCREAMING_SNAKE_CASE    )
									processor.save_pretrained(self.tmpdirname    )
									__UpperCamelCase      :					int       		=TvltProcessor.from_pretrained(self.tmpdirname    )

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


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					str       		=self.get_image_processor()
									__UpperCamelCase      :					Tuple       		=self.get_feature_extractor()

									__UpperCamelCase      :					str       		=TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE							,  feature_extractor=_SCREAMING_SNAKE_CASE    )

									__UpperCamelCase      :					Tuple       		=np.ones([12000]    )

									__UpperCamelCase      :					List[Any]       		=feature_extractor(_SCREAMING_SNAKE_CASE							,  return_tensors='np'    )
									__UpperCamelCase      :					List[str]       		=processor(audio=_SCREAMING_SNAKE_CASE							,  return_tensors='np'    )

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


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Optional[Any]       		=self.get_image_processor()
									__UpperCamelCase      :					Any       		=self.get_feature_extractor()

									__UpperCamelCase      :					Dict       		=TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE							,  feature_extractor=_SCREAMING_SNAKE_CASE    )

									__UpperCamelCase      :					List[str]       		=np.ones([3, 224, 224]    )

									__UpperCamelCase      :					Union[str, Any]       		=image_processor(_SCREAMING_SNAKE_CASE							,  return_tensors='np'    )
									__UpperCamelCase      :					Optional[int]       		=processor(images=_SCREAMING_SNAKE_CASE							,  return_tensors='np'    )

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


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Dict       		=self.get_image_processor()
									__UpperCamelCase      :					List[str]       		=self.get_feature_extractor()

									__UpperCamelCase      :					int       		=TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE							,  feature_extractor=_SCREAMING_SNAKE_CASE    )

									__UpperCamelCase      :					Tuple       		=np.ones([12000]    )
									__UpperCamelCase      :					Any       		=np.ones([3, 224, 224]    )

									__UpperCamelCase      :					int       		=processor(audio=_SCREAMING_SNAKE_CASE							,  images=_SCREAMING_SNAKE_CASE    )

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







				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Optional[Any]       		=self.get_image_processor()
									__UpperCamelCase      :					Dict       		=self.get_feature_extractor()

									__UpperCamelCase      :					int       		=TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE							,  feature_extractor=_SCREAMING_SNAKE_CASE    )

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






from typing import TYPE_CHECKING

from ..utils import _LazyModule


__snake_case							:   Optional[int]      =    {
    'config': [
        'EXTERNAL_DATA_FORMAT_SIZE_LIMIT',
        'OnnxConfig',
        'OnnxConfigWithPast',
        'OnnxSeq2SeqConfigWithPast',
        'PatchingSpec',
    ],
    'convert': ['export', 'validate_model_outputs'],
    'features': ['FeaturesManager'],
    'utils': ['ParameterFormat', 'compute_serialized_parameters_size'],
}


if TYPE_CHECKING:
	from .config import (
	    EXTERNAL_DATA_FORMAT_SIZE_LIMIT,
	    OnnxConfig,
	    OnnxConfigWithPast,
	    OnnxSeqaSeqConfigWithPast,
	    PatchingSpec,
	)
	from .convert import export, validate_model_outputs
	from .features import FeaturesManager
	from .utils import ParameterFormat, compute_serialized_parameters_size

else:
	import sys

	__snake_case							:   Any      =    _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)