





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




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    '''ZinengTang/tvlt-base'''
    __lowerCamelCase													=    tempfile.mkdtemp()




 def        lowerCamelCase      (						self	,				**__UpperCAmelCase				):



    '''simple docstring'''
    return TvltImageProcessor.from_pretrained(self.checkpoint	,				**__lowerCAmelCase				)




 def        lowerCamelCase      (						self	,				**__UpperCAmelCase				):



    '''simple docstring'''
    return TvltFeatureExtractor.from_pretrained(self.checkpoint	,				**__lowerCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    shutil.rmtree(self.tmpdirname				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.get_image_processor()
    __lowerCamelCase													=    self.get_feature_extractor()

    __lowerCamelCase													=    TvltProcessor(image_processor=__lowerCAmelCase	,				feature_extractor=__lowerCAmelCase				)
    processor.save_pretrained(self.tmpdirname				)
    __lowerCamelCase													=    TvltProcessor.from_pretrained(self.tmpdirname				)

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




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.get_image_processor()
    __lowerCamelCase													=    self.get_feature_extractor()

    __lowerCamelCase													=    TvltProcessor(image_processor=__lowerCAmelCase	,				feature_extractor=__lowerCAmelCase				)

    __lowerCamelCase													=    np.ones([12000]				)

    __lowerCamelCase													=    feature_extractor(__lowerCAmelCase	,				return_tensors='''np'''				)
    __lowerCamelCase													=    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				):



    '''simple docstring'''
    __lowerCamelCase													=    self.get_image_processor()
    __lowerCamelCase													=    self.get_feature_extractor()

    __lowerCamelCase													=    TvltProcessor(image_processor=__lowerCAmelCase	,				feature_extractor=__lowerCAmelCase				)

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

    __lowerCamelCase													=    image_processor(__lowerCAmelCase	,				return_tensors='''np'''				)
    __lowerCamelCase													=    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				):



    '''simple docstring'''
    __lowerCamelCase													=    self.get_image_processor()
    __lowerCamelCase													=    self.get_feature_extractor()

    __lowerCamelCase													=    TvltProcessor(image_processor=__lowerCAmelCase	,				feature_extractor=__lowerCAmelCase				)

    __lowerCamelCase													=    np.ones([12000]				)
    __lowerCamelCase													=    np.ones([3, 224, 224]				)

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



    '''simple docstring'''
    __lowerCamelCase													=    self.get_image_processor()
    __lowerCamelCase													=    self.get_feature_extractor()

    __lowerCamelCase													=    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_torch_available


a_			=					{
    """configuration_clipseg""": [
        """CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """CLIPSegConfig""",
        """CLIPSegTextConfig""",
        """CLIPSegVisionConfig""",
    ],
    """processing_clipseg""": ["""CLIPSegProcessor"""],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a_			=					[
      """CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """CLIPSegModel""",
      """CLIPSegPreTrainedModel""",
      """CLIPSegTextModel""",
      """CLIPSegVisionModel""",
      """CLIPSegForImageSegmentation""",
  ]

if TYPE_CHECKING:
  from .configuration_clipseg import (
      CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP,
      CLIPSegConfig,
      CLIPSegTextConfig,
      CLIPSegVisionConfig,
  )
  from .processing_clipseg import CLIPSegProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_clipseg import (
        CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST,
        CLIPSegForImageSegmentation,
        CLIPSegModel,
        CLIPSegPreTrainedModel,
        CLIPSegTextModel,
        CLIPSegVisionModel,
    )

else:
  import sys

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






