
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			):




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Union[str, Any]:


								'''simple docstring'''




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




				def 				SCREAMING_SNAKE_CASE_		(     self		,     **_snake_case				)    ->      List[str]:


								'''simple docstring'''




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




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


								'''simple docstring'''




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




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


								'''simple docstring'''




								shutil.rmtree(self.tmpdirname				)




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Union[str, Any]:


								'''simple docstring'''




								__a										=    self.get_image_processor()
								__a										=    self.get_feature_extractor()

								__a										=    TvltProcessor(image_processor=_snake_case		,     feature_extractor=_snake_case				)
								processor.save_pretrained(self.tmpdirname				)
								__a										=    TvltProcessor.from_pretrained(self.tmpdirname				)

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




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Union[str, Any]:


								'''simple docstring'''




								__a										=    self.get_image_processor()
								__a										=    self.get_feature_extractor()

								__a										=    TvltProcessor(image_processor=_snake_case		,     feature_extractor=_snake_case				)

								__a										=    np.ones([12_000]				)

								__a										=    feature_extractor(_snake_case		,     return_tensors='''np'''				)
								__a										=    processor(audio=_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 				SCREAMING_SNAKE_CASE_		(     self				)    ->      str:


								'''simple docstring'''




								__a										=    self.get_image_processor()
								__a										=    self.get_feature_extractor()

								__a										=    TvltProcessor(image_processor=_snake_case		,     feature_extractor=_snake_case				)

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

								__a										=    image_processor(_snake_case		,     return_tensors='''np'''				)
								__a										=    processor(images=_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 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[Any]:


								'''simple docstring'''




								__a										=    self.get_image_processor()
								__a										=    self.get_feature_extractor()

								__a										=    TvltProcessor(image_processor=_snake_case		,     feature_extractor=_snake_case				)

								__a										=    np.ones([12_000]				)
								__a										=    np.ones([3, 224, 224]				)

								__a										=    processor(audio=_snake_case		,     images=_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(_snake_case				):
												processor()




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Optional[Any]:


								'''simple docstring'''




								__a										=    self.get_image_processor()
								__a										=    self.get_feature_extractor()

								__a										=    TvltProcessor(image_processor=_snake_case		,     feature_extractor=_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 (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


_snake_case          =   {
    'configuration_perceiver': ['PERCEIVER_PRETRAINED_CONFIG_ARCHIVE_MAP', 'PerceiverConfig', 'PerceiverOnnxConfig'],
    'tokenization_perceiver': ['PerceiverTokenizer'],
}

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _snake_case          =   ['PerceiverFeatureExtractor']
 _snake_case          =   ['PerceiverImageProcessor']

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _snake_case          =   [
     'PERCEIVER_PRETRAINED_MODEL_ARCHIVE_LIST',
     'PerceiverForImageClassificationConvProcessing',
     'PerceiverForImageClassificationFourier',
     'PerceiverForImageClassificationLearned',
     'PerceiverForMaskedLM',
     'PerceiverForMultimodalAutoencoding',
     'PerceiverForOpticalFlow',
     'PerceiverForSequenceClassification',
     'PerceiverLayer',
     'PerceiverModel',
     'PerceiverPreTrainedModel',
 ]


if TYPE_CHECKING:
 from .configuration_perceiver import PERCEIVER_PRETRAINED_CONFIG_ARCHIVE_MAP, PerceiverConfig, PerceiverOnnxConfig
 from .tokenization_perceiver import PerceiverTokenizer

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_perceiver import PerceiverFeatureExtractor
  from .image_processing_perceiver import PerceiverImageProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_perceiver import (
      PERCEIVER_PRETRAINED_MODEL_ARCHIVE_LIST,
      PerceiverForImageClassificationConvProcessing,
      PerceiverForImageClassificationFourier,
      PerceiverForImageClassificationLearned,
      PerceiverForMaskedLM,
      PerceiverForMultimodalAutoencoding,
      PerceiverForOpticalFlow,
      PerceiverForSequenceClassification,
      PerceiverLayer,
      PerceiverModel,
      PerceiverPreTrainedModel,
  )

else:
 import sys

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

