





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


      def    a (self       :      Optional[int]      ):





         """simple docstring"""



         __snake_case							       =   '''ZinengTang/tvlt-base'''
         __snake_case							       =   tempfile.mkdtemp()


      def    a (self       :      str				,			**a__       :      Union[str, Any]      ):





         """simple docstring"""



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


      def    a (self       :      List[Any]				,			**a__       :      List[Any]      ):





         """simple docstring"""



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


      def    a (self       :      Dict      ):





         """simple docstring"""



         shutil.rmtree(self.tmpdirname      )


      def    a (self       :      Optional[int]      ):





         """simple docstring"""



         __snake_case							       =   self.get_image_processor()
         __snake_case							       =   self.get_feature_extractor()

         __snake_case							       =   TvltProcessor(image_processor=a__				,			feature_extractor=a__      )
         processor.save_pretrained(self.tmpdirname      )
         __snake_case							       =   TvltProcessor.from_pretrained(self.tmpdirname      )

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


      def    a (self       :      Any      ):





         """simple docstring"""



         __snake_case							       =   self.get_image_processor()
         __snake_case							       =   self.get_feature_extractor()

         __snake_case							       =   TvltProcessor(image_processor=a__				,			feature_extractor=a__      )

         __snake_case							       =   np.ones([1_2000]      )

         __snake_case							       =   feature_extractor(a__				,			return_tensors='''np'''      )
         __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    a (self       :      Dict      ):





         """simple docstring"""



         __snake_case							       =   self.get_image_processor()
         __snake_case							       =   self.get_feature_extractor()

         __snake_case							       =   TvltProcessor(image_processor=a__				,			feature_extractor=a__      )

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

         __snake_case							       =   image_processor(a__				,			return_tensors='''np'''      )
         __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    a (self       :      List[Any]      ):





         """simple docstring"""



         __snake_case							       =   self.get_image_processor()
         __snake_case							       =   self.get_feature_extractor()

         __snake_case							       =   TvltProcessor(image_processor=a__				,			feature_extractor=a__      )

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

         __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    a (self       :      Dict      ):





         """simple docstring"""



         __snake_case							       =   self.get_image_processor()
         __snake_case							       =   self.get_feature_extractor()

         __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'''				,			)








'''simple docstring'''







from ....utils import logging


lowerCAmelCase_					:    Union[str, Any]      	=			logging.get_logger(__name__)
class 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







				def __init__(  self     :					Tuple					,				__a     :					int					,				__a     :					Any=None					,				__a     :					Optional[int]=20_48					):
								_a								= config.__dict__
								_a								= modal_hidden_size
								if num_labels:
												_a								= num_labels
