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





     def 						UpperCAmelCase (     self				):

      '''simple docstring'''




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





     def 						UpperCAmelCase (     self     ,					**__UpperCAmelCase				):

      '''simple docstring'''




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





     def 						UpperCAmelCase (     self     ,					**__UpperCAmelCase				):

      '''simple docstring'''




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





     def 						UpperCAmelCase (     self				):

      '''simple docstring'''




      shutil.rmtree(self.tmpdirname				)





     def 						UpperCAmelCase (     self				):

      '''simple docstring'''




      __UpperCamelCase      =	self.get_image_processor()
      __UpperCamelCase      =	self.get_feature_extractor()

      __UpperCamelCase      =	TvltProcessor(image_processor=__UpperCAmelCase     ,					feature_extractor=__UpperCAmelCase				)
      processor.save_pretrained(self.tmpdirname				)
      __UpperCamelCase      =	TvltProcessor.from_pretrained(self.tmpdirname				)

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





     def 						UpperCAmelCase (     self				):

      '''simple docstring'''




      __UpperCamelCase      =	self.get_image_processor()
      __UpperCamelCase      =	self.get_feature_extractor()

      __UpperCamelCase      =	TvltProcessor(image_processor=__UpperCAmelCase     ,					feature_extractor=__UpperCAmelCase				)

      __UpperCamelCase      =	np.ones([1_2000]				)

      __UpperCamelCase      =	feature_extractor(__UpperCAmelCase     ,					return_tensors='np'				)
      __UpperCamelCase      =	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 						UpperCAmelCase (     self				):

      '''simple docstring'''




      __UpperCamelCase      =	self.get_image_processor()
      __UpperCamelCase      =	self.get_feature_extractor()

      __UpperCamelCase      =	TvltProcessor(image_processor=__UpperCAmelCase     ,					feature_extractor=__UpperCAmelCase				)

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

      __UpperCamelCase      =	image_processor(__UpperCAmelCase     ,					return_tensors='np'				)
      __UpperCamelCase      =	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 						UpperCAmelCase (     self				):

      '''simple docstring'''




      __UpperCamelCase      =	self.get_image_processor()
      __UpperCamelCase      =	self.get_feature_extractor()

      __UpperCamelCase      =	TvltProcessor(image_processor=__UpperCAmelCase     ,					feature_extractor=__UpperCAmelCase				)

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

      __UpperCamelCase      =	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 						UpperCAmelCase (     self				):

      '''simple docstring'''




      __UpperCamelCase      =	self.get_image_processor()
      __UpperCamelCase      =	self.get_feature_extractor()

      __UpperCamelCase      =	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'     ,					)





"""simple docstring"""

from argparse import ArgumentParser

from .add_new_model import AddNewModelCommand
from .add_new_model_like import AddNewModelLikeCommand
from .convert import ConvertCommand
from .download import DownloadCommand
from .env import EnvironmentCommand
from .lfs import LfsCommands
from .pt_to_tf import PTtoTFCommand
from .run import RunCommand
from .serving import ServeCommand
from .user import UserCommands






def 							A						(    )				->     Union[str, Any]:
 __UpperCamelCase      =	ArgumentParser('Transformers CLI tool'    , usage='transformers-cli <command> [<args>]'		)
 __UpperCamelCase      =	parser.add_subparsers(help='transformers-cli command helpers'		)

 # Register commands
 ConvertCommand.register_subcommand(snake_case		)
 DownloadCommand.register_subcommand(snake_case		)
 EnvironmentCommand.register_subcommand(snake_case		)
 RunCommand.register_subcommand(snake_case		)
 ServeCommand.register_subcommand(snake_case		)
 UserCommands.register_subcommand(snake_case		)
 AddNewModelCommand.register_subcommand(snake_case		)
 AddNewModelLikeCommand.register_subcommand(snake_case		)
 LfsCommands.register_subcommand(snake_case		)
 PTtoTFCommand.register_subcommand(snake_case		)

 # Let's go
 __UpperCamelCase      =	parser.parse_args()

 if not hasattr(snake_case    , 'func'		):
  parser.print_help()
  exit(1		)

 # Run
 __UpperCamelCase      =	args.func(snake_case		)
 service.run()


if __name__ == "__main__":
      main()



