





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 	lowerCAmelCase__    (	self:						List[str]       )						->    Union[str, Any]:
         '''simple docstring'''

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



      def 	lowerCAmelCase__    (	self:						Tuple		,  **_lowerCAmelCase:						List[Any]       )						->    int:
         '''simple docstring'''

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



      def 	lowerCAmelCase__    (	self:						Optional[Any]		,  **_lowerCAmelCase:						Tuple       )						->    Any:
         '''simple docstring'''

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



      def 	lowerCAmelCase__    (	self:						Optional[Any]       )						->    Any:
         '''simple docstring'''

         shutil.rmtree(self.tmpdirname       )



      def 	lowerCAmelCase__    (	self:						List[str]       )						->    List[str]:
         '''simple docstring'''

         UpperCAmelCase_											=self.get_image_processor()
         UpperCAmelCase_											=self.get_feature_extractor()

         UpperCAmelCase_											=TvltProcessor(image_processor=_lowerCAmelCase		,  feature_extractor=_lowerCAmelCase       )
         processor.save_pretrained(self.tmpdirname       )
         UpperCAmelCase_											=TvltProcessor.from_pretrained(self.tmpdirname       )

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



      def 	lowerCAmelCase__    (	self:						Union[str, Any]       )						->    Tuple:
         '''simple docstring'''

         UpperCAmelCase_											=self.get_image_processor()
         UpperCAmelCase_											=self.get_feature_extractor()

         UpperCAmelCase_											=TvltProcessor(image_processor=_lowerCAmelCase		,  feature_extractor=_lowerCAmelCase       )

         UpperCAmelCase_											=np.ones([1_2000]       )

         UpperCAmelCase_											=feature_extractor(_lowerCAmelCase		,  return_tensors="np"       )
         UpperCAmelCase_											=processor(audio=_lowerCAmelCase		,  return_tensors="np"       )

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



      def 	lowerCAmelCase__    (	self:						Optional[int]       )						->    Union[str, Any]:
         '''simple docstring'''

         UpperCAmelCase_											=self.get_image_processor()
         UpperCAmelCase_											=self.get_feature_extractor()

         UpperCAmelCase_											=TvltProcessor(image_processor=_lowerCAmelCase		,  feature_extractor=_lowerCAmelCase       )

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

         UpperCAmelCase_											=image_processor(_lowerCAmelCase		,  return_tensors="np"       )
         UpperCAmelCase_											=processor(images=_lowerCAmelCase		,  return_tensors="np"       )

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



      def 	lowerCAmelCase__    (	self:						Dict       )						->    List[Any]:
         '''simple docstring'''

         UpperCAmelCase_											=self.get_image_processor()
         UpperCAmelCase_											=self.get_feature_extractor()

         UpperCAmelCase_											=TvltProcessor(image_processor=_lowerCAmelCase		,  feature_extractor=_lowerCAmelCase       )

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

         UpperCAmelCase_											=processor(audio=_lowerCAmelCase		,  images=_lowerCAmelCase       )

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






      def 	lowerCAmelCase__    (	self:						Union[str, Any]       )						->    str:
         '''simple docstring'''

         UpperCAmelCase_											=self.get_image_processor()
         UpperCAmelCase_											=self.get_feature_extractor()

         UpperCAmelCase_											=TvltProcessor(image_processor=_lowerCAmelCase		,  feature_extractor=_lowerCAmelCase       )

         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_tf_available, is_torch_available


__lowercase  :   Optional[Any]						      ={
    """configuration_groupvit""": [
        """GROUPVIT_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """GroupViTConfig""",
        """GroupViTOnnxConfig""",
        """GroupViTTextConfig""",
        """GroupViTVisionConfig""",
    ],
}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     __lowercase  :   List[Any]						      =[
         """GROUPVIT_PRETRAINED_MODEL_ARCHIVE_LIST""",
         """GroupViTModel""",
         """GroupViTPreTrainedModel""",
         """GroupViTTextModel""",
         """GroupViTVisionModel""",
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     __lowercase  :   List[str]						      =[
         """TF_GROUPVIT_PRETRAINED_MODEL_ARCHIVE_LIST""",
         """TFGroupViTModel""",
         """TFGroupViTPreTrainedModel""",
         """TFGroupViTTextModel""",
         """TFGroupViTVisionModel""",
     ]

if TYPE_CHECKING:
     from .configuration_groupvit import (
         GROUPVIT_PRETRAINED_CONFIG_ARCHIVE_MAP,
         GroupViTConfig,
         GroupViTOnnxConfig,
         GroupViTTextConfig,
         GroupViTVisionConfig,
     )

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_groupvit import (
              GROUPVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
              GroupViTModel,
              GroupViTPreTrainedModel,
              GroupViTTextModel,
              GroupViTVisionModel,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_groupvit import (
              TF_GROUPVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
              TFGroupViTModel,
              TFGroupViTPreTrainedModel,
              TFGroupViTTextModel,
              TFGroupViTVisionModel,
          )

else:
     import sys

     __lowercase  :   str						      =_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




