




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






      def 							lowercase_						( self   :  List[Any]       ):


           '''simple docstring'''

           a_     :							Tuple     						=  "ZinengTang/tvlt-base"
           a_     :							Tuple     						=  tempfile.mkdtemp()






      def 							lowercase_						( self   :  Any						,						**lowercase__   :  Dict       ):


           '''simple docstring'''

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






      def 							lowercase_						( self   :  str						,						**lowercase__   :  int       ):


           '''simple docstring'''

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






      def 							lowercase_						( self   :  Union[str, Any]       ):


           '''simple docstring'''

           shutil.rmtree(self.tmpdirname       )






      def 							lowercase_						( self   :  Dict       ):


           '''simple docstring'''

           a_     :							List[str]     						=  self.get_image_processor()
           a_     :							Optional[int]     						=  self.get_feature_extractor()

           a_     :							int     						=  TvltProcessor(image_processor=__UpperCAmelCase						,						feature_extractor=__UpperCAmelCase       )
           processor.save_pretrained(self.tmpdirname       )
           a_     :							List[Any]     						=  TvltProcessor.from_pretrained(self.tmpdirname       )

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






      def 							lowercase_						( self   :  Union[str, Any]       ):


           '''simple docstring'''

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

           a_     :							Union[str, Any]     						=  TvltProcessor(image_processor=__UpperCAmelCase						,						feature_extractor=__UpperCAmelCase       )

           a_     :							Union[str, Any]     						=  np.ones([1_2000]       )

           a_     :							int     						=  feature_extractor(__UpperCAmelCase						,						return_tensors="""np"""       )
           a_     :							List[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 							lowercase_						( self   :  Optional[int]       ):


           '''simple docstring'''

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

           a_     :							str     						=  TvltProcessor(image_processor=__UpperCAmelCase						,						feature_extractor=__UpperCAmelCase       )

           a_     :							List[Any]     						=  np.ones([3, 224, 224]       )

           a_     :							Dict     						=  image_processor(__UpperCAmelCase						,						return_tensors="""np"""       )
           a_     :							Tuple     						=  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 							lowercase_						( self   :  str       ):


           '''simple docstring'''

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

           a_     :							Tuple     						=  TvltProcessor(image_processor=__UpperCAmelCase						,						feature_extractor=__UpperCAmelCase       )

           a_     :							List[str]     						=  np.ones([1_2000]       )
           a_     :							List[Any]     						=  np.ones([3, 224, 224]       )

           a_     :							Optional[Any]     						=  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 							lowercase_						( self   :  str       ):


           '''simple docstring'''

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

           a_     :							Any     						=  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"""						,						)





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available


lowerCamelCase		       =      {}


try:
						if not is_sentencepiece_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase		       =      ["""MLukeTokenizer"""]

if TYPE_CHECKING:
						try:
												if not is_sentencepiece_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_mluke import MLukeTokenizer


else:
						import sys

						lowerCamelCase		       =      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


