






'''simple docstring'''





import functools
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


_UpperCamelCase						:						Dict  =					threading.Lock()
_UpperCamelCase						:						Optional[logging.Handler]  =					None

_UpperCamelCase						:						List[Any]  =					{
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

_UpperCamelCase						:						List[str]  =					logging.WARNING

_UpperCamelCase						:						Optional[int]  =					True
def __UpperCAmelCase   (					)    ->   Optional[Any]:
			UpperCAmelCase_      :       List[str]          =       os.getenv('''TRANSFORMERS_VERBOSITY'''			,       UpperCamelCase_		)
			if env_level_str:
						if env_level_str in log_levels:
									return log_levels[env_level_str]
						else:
									logging.getLogger().warning(
									    F"Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, "
									    F"has to be one of: { ', '.join(log_levels.keys()		) }"		)
			return _default_log_level
def __UpperCAmelCase   (					)    ->   Tuple:
			return __name__.split('''.'''		)[0]
def __UpperCAmelCase   (					)    ->   Optional[int]:
			return logging.getLogger(_get_library_name()		)
def __UpperCAmelCase   (					)    ->   List[str]:
			global _default_handler

			with _lock:
						if _default_handler:
									# This library has already configured the library root logger.
									return
						UpperCAmelCase_      :       Optional[int]          =       logging.StreamHandler()  # Set sys.stderr as stream.
						UpperCAmelCase_      :       Optional[Any]          =       sys.stderr.flush

						# Apply our default configuration to the library root logger.
						UpperCAmelCase_      :       int          =       _get_library_root_logger()
						library_root_logger.addHandler(_default_handler		)
						library_root_logger.setLevel(_get_default_logging_level()		)
						UpperCAmelCase_      :       Optional[Any]          =       False
def __UpperCAmelCase   (					)    ->   int:
			global _default_handler

			with _lock:
						if not _default_handler:
									return

						UpperCAmelCase_      :       str          =       _get_library_root_logger()
						library_root_logger.removeHandler(_default_handler		)
						library_root_logger.setLevel(logging.NOTSET		)
						UpperCAmelCase_      :       int          =       None
def __UpperCAmelCase   (					)    ->   int:
			return log_levels
def __UpperCAmelCase   (					A					:			Union[str, Any] = None		)    ->   List[str]:






			if name is None:
						UpperCAmelCase_      :       List[Any]          =       _get_library_name()

			_configure_library_root_logger()
			return logging.getLogger(UpperCamelCase_		)
def __UpperCAmelCase   (					)    ->   str:
			_configure_library_root_logger()
			return _get_library_root_logger().getEffectiveLevel()
def __UpperCAmelCase   (					A					:			Optional[int]		)    ->   List[str]:
			_configure_library_root_logger()
			_get_library_root_logger().setLevel(UpperCamelCase_		)
def __UpperCAmelCase   (					)    ->   Tuple:
			return set_verbosity(UpperCamelCase_		)
def __UpperCAmelCase   (					)    ->   Optional[int]:
			return set_verbosity(UpperCamelCase_		)
def __UpperCAmelCase   (					)    ->   str:
			return set_verbosity(UpperCamelCase_		)
def __UpperCAmelCase   (					)    ->   Tuple:
			return set_verbosity(UpperCamelCase_		)
def __UpperCAmelCase   (					)    ->   Tuple:
			_configure_library_root_logger()

			assert _default_handler is not None
			_get_library_root_logger().removeHandler(_default_handler		)
def __UpperCAmelCase   (					)    ->   Dict:
			_configure_library_root_logger()

			assert _default_handler is not None
			_get_library_root_logger().addHandler(_default_handler		)
def __UpperCAmelCase   (					A					:			int		)    ->   str:
			_configure_library_root_logger()

			assert handler is not None
			_get_library_root_logger().addHandler(UpperCamelCase_		)
def __UpperCAmelCase   (					A					:			Optional[Any]		)    ->   List[str]:
			_configure_library_root_logger()

			assert handler is not None and handler not in _get_library_root_logger().handlers
			_get_library_root_logger().removeHandler(UpperCamelCase_		)
def __UpperCAmelCase   (					)    ->   Union[str, Any]:
			_configure_library_root_logger()
			UpperCAmelCase_      :       str          =       False
def __UpperCAmelCase   (					)    ->   Tuple:
			_configure_library_root_logger()
			UpperCAmelCase_      :       Union[str, Any]          =       True
def __UpperCAmelCase   (					)    ->   List[str]:
			UpperCAmelCase_      :       Any          =       _get_library_root_logger().handlers

			for handler in handlers:
						UpperCAmelCase_      :       int          =       logging.Formatter('''[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s'''		)
						handler.setFormatter(UpperCamelCase_		)
def __UpperCAmelCase   (					)    ->   Optional[Any]:
			UpperCAmelCase_      :       List[Any]          =       _get_library_root_logger().handlers

			for handler in handlers:
						handler.setFormatter(UpperCamelCase_		)
def __UpperCAmelCase   (					self					:			Optional[int]			,       *A					:			Union[str, Any]			,       **A					:			Optional[int]		)    ->   Tuple:
			UpperCAmelCase_      :       List[Any]          =       os.getenv('''TRANSFORMERS_NO_ADVISORY_WARNINGS'''			,       UpperCamelCase_		)
			if no_advisory_warnings:
						return
			self.warning(*UpperCamelCase_			,       **UpperCamelCase_		)


_UpperCamelCase						:						int  =					warning_advice
@functools.lru_cache(UpperCamelCase_		)
def __UpperCAmelCase   (					self					:			Optional[int]			,       *A					:			Any			,       **A					:			Optional[int]		)    ->   List[Any]:
			self.warning(*UpperCamelCase_			,       **UpperCamelCase_		)


_UpperCamelCase						:						Tuple  =					warning_once


class  snake_case__      :




					def __init__(  self  :		Optional[Any]				, *_A  :		Tuple				, **_A  :		List[str]      )    ->							Tuple:  # pylint: disable=unused-argument
								UpperCAmelCase_      :       Union[str, Any]          =       args[0] if args else None




					def __iter__(  self  :		Any      )    ->							List[str]:
								return iter(self._iterator      )




					def __getattr__(  self  :		str				, _A  :		str      )    ->							int:

								def empty_fn(*_A  :		int				, **_A  :		List[Any]      ):  # pylint: disable=unused-argument
											return

								return empty_fn




					def __enter__(  self  :		List[str]      )    ->							Tuple:
								return self





					def __exit__(  self  :		List[str]				, _A  :		int				, _A  :		Dict				, _A  :		Optional[int]      )    ->							int:
								return






class  snake_case__      :




					def __call__(  self  :		Union[str, Any]				, *_A  :		Optional[int]				, **_A  :		Optional[int]      )    ->							Dict:
								if _tqdm_active:
											return tqdm_lib.tqdm(*__snake_case				, **__snake_case      )
								else:
											return EmptyTqdm(*__snake_case				, **__snake_case      )




					def 		A      (  self  :		Optional[int]				, *_A  :		List[str]				, **_A  :		Optional[int]      )    ->							Optional[Any]:
								UpperCAmelCase_      :       Tuple          =       None
								if _tqdm_active:
											return tqdm_lib.tqdm.set_lock(*__snake_case				, **__snake_case      )





					def 		A      (  self  :		int      )    ->							int:
								if _tqdm_active:
											return tqdm_lib.tqdm.get_lock()






_UpperCamelCase						:						int  =					_tqdm_cls()
def __UpperCAmelCase   (					)    ->   int:
			global _tqdm_active
			return bool(_tqdm_active		)
def __UpperCAmelCase   (					)    ->   Tuple:
			global _tqdm_active
			UpperCAmelCase_      :       List[Any]          =       True
			hf_hub_utils.enable_progress_bars()







def __UpperCAmelCase   (					)    ->   Any:
			global _tqdm_active
			UpperCAmelCase_      :       List[str]          =       False
			hf_hub_utils.disable_progress_bars()






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







    """simple docstring"""

    def 						a_     (			self       ):
         snake_case											=							'''ZinengTang/tvlt-base'''
         snake_case											=							tempfile.mkdtemp()
    def 						a_     (			self     ,   **__snake_case       ):
         return TvltImageProcessor.from_pretrained(self.checkpoint     ,   **__snake_case       )
    def 						a_     (			self     ,   **__snake_case       ):
         return TvltFeatureExtractor.from_pretrained(self.checkpoint     ,   **__snake_case       )
    def 						a_     (			self       ):
         shutil.rmtree(self.tmpdirname       )
    def 						a_     (			self       ):
         snake_case											=							self.get_image_processor()
         snake_case											=							self.get_feature_extractor()

         snake_case											=							TvltProcessor(image_processor=__snake_case     ,   feature_extractor=__snake_case       )
         processor.save_pretrained(self.tmpdirname       )
         snake_case											=							TvltProcessor.from_pretrained(self.tmpdirname       )

         self.assertIsInstance(processor.feature_extractor     ,   __snake_case       )
         self.assertIsInstance(processor.image_processor     ,   __snake_case       )
    def 						a_     (			self       ):
         snake_case											=							self.get_image_processor()
         snake_case											=							self.get_feature_extractor()

         snake_case											=							TvltProcessor(image_processor=__snake_case     ,   feature_extractor=__snake_case       )

         snake_case											=							np.ones([1_2_0_0_0]       )

         snake_case											=							feature_extractor(__snake_case     ,   return_tensors='''np'''       )
         snake_case											=							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 						a_     (			self       ):
         snake_case											=							self.get_image_processor()
         snake_case											=							self.get_feature_extractor()

         snake_case											=							TvltProcessor(image_processor=__snake_case     ,   feature_extractor=__snake_case       )

         snake_case											=							np.ones([3, 2_2_4, 2_2_4]       )

         snake_case											=							image_processor(__snake_case     ,   return_tensors='''np'''       )
         snake_case											=							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 						a_     (			self       ):
         snake_case											=							self.get_image_processor()
         snake_case											=							self.get_feature_extractor()

         snake_case											=							TvltProcessor(image_processor=__snake_case     ,   feature_extractor=__snake_case       )

         snake_case											=							np.ones([1_2_0_0_0]       )
         snake_case											=							np.ones([3, 2_2_4, 2_2_4]       )

         snake_case											=							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 						a_     (			self       ):
         snake_case											=							self.get_image_processor()
         snake_case											=							self.get_feature_extractor()

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




