



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





     def 	__snake_case    (       self :							Dict				)->List[str]:
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	"ZinengTang/tvlt-base"
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	tempfile.mkdtemp()





     def 	__snake_case    (       self :							Optional[Any]     ,  **UpperCamelCase :							Optional[Any]				)->Dict:
      return TvltImageProcessor.from_pretrained(self.checkpoint     ,  **UpperCamelCase				)





     def 	__snake_case    (       self :							Any     ,  **UpperCamelCase :							Any				)->Optional[int]:
      return TvltFeatureExtractor.from_pretrained(self.checkpoint     ,  **UpperCamelCase				)





     def 	__snake_case    (       self :							List[str]				)->List[str]:
      shutil.rmtree(self.tmpdirname				)





     def 	__snake_case    (       self :							int				)->str:
      __SCREAMING_SNAKE_CASE       :    Any       =	self.get_image_processor()
      __SCREAMING_SNAKE_CASE       :    str       =	self.get_feature_extractor()

      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	TvltProcessor(image_processor=UpperCamelCase     ,  feature_extractor=UpperCamelCase				)
      processor.save_pretrained(self.tmpdirname				)
      __SCREAMING_SNAKE_CASE       :    int       =	TvltProcessor.from_pretrained(self.tmpdirname				)

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





     def 	__snake_case    (       self :							List[Any]				)->Union[str, Any]:
      __SCREAMING_SNAKE_CASE       :    Dict       =	self.get_image_processor()
      __SCREAMING_SNAKE_CASE       :    Dict       =	self.get_feature_extractor()

      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	TvltProcessor(image_processor=UpperCamelCase     ,  feature_extractor=UpperCamelCase				)

      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	np.ones([1_2_0_0_0]				)

      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	feature_extractor(UpperCamelCase     ,  return_tensors="np"				)
      __SCREAMING_SNAKE_CASE       :    str       =	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 	__snake_case    (       self :							Union[str, Any]				)->Optional[Any]:
      __SCREAMING_SNAKE_CASE       :    Any       =	self.get_image_processor()
      __SCREAMING_SNAKE_CASE       :    int       =	self.get_feature_extractor()

      __SCREAMING_SNAKE_CASE       :    int       =	TvltProcessor(image_processor=UpperCamelCase     ,  feature_extractor=UpperCamelCase				)

      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	np.ones([3, 2_2_4, 2_2_4]				)

      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	image_processor(UpperCamelCase     ,  return_tensors="np"				)
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	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 	__snake_case    (       self :							Tuple				)->Union[str, Any]:
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	self.get_image_processor()
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	self.get_feature_extractor()

      __SCREAMING_SNAKE_CASE       :    List[Any]       =	TvltProcessor(image_processor=UpperCamelCase     ,  feature_extractor=UpperCamelCase				)

      __SCREAMING_SNAKE_CASE       :    List[str]       =	np.ones([1_2_0_0_0]				)
      __SCREAMING_SNAKE_CASE       :    Any       =	np.ones([3, 2_2_4, 2_2_4]				)

      __SCREAMING_SNAKE_CASE       :    List[str]       =	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 	__snake_case    (       self :							Dict				)->Tuple:
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	self.get_image_processor()
      __SCREAMING_SNAKE_CASE       :    List[str]       =	self.get_feature_extractor()

      __SCREAMING_SNAKE_CASE       :    Any       =	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"     ,  )











from abc import ABC, abstractmethod
from typing import Optional, Union

from .. import Dataset, DatasetDict, Features, IterableDataset, IterableDatasetDict, NamedSplit
from ..utils.typing import NestedDataStructureLike, PathLike

class       _SCREAMING_SNAKE_CASE	(UpperCamelCase ):





     def __init__(       self :							List[str]     ,  UpperCamelCase :							Optional[NestedDataStructureLike[PathLike]] = None     ,  UpperCamelCase :							Optional[NamedSplit] = None     ,  UpperCamelCase :							Optional[Features] = None     ,  UpperCamelCase :							str = None     ,  UpperCamelCase :							bool = False     ,  UpperCamelCase :							bool = False     ,  UpperCamelCase :							Optional[int] = None     ,  **UpperCamelCase :							Dict     ,  )->int:
      __SCREAMING_SNAKE_CASE       :    List[str]       =	path_or_paths
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	split if split or isinstance(UpperCamelCase     ,  UpperCamelCase				) else "train"
      __SCREAMING_SNAKE_CASE       :    Dict       =	features
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	cache_dir
      __SCREAMING_SNAKE_CASE       :    Tuple       =	keep_in_memory
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	streaming
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	num_proc
      __SCREAMING_SNAKE_CASE       :    int       =	kwargs






     @abstractmethod
     def 	__snake_case    (       self :							Optional[int]				)->Union[Dataset, DatasetDict, IterableDataset, IterableDatasetDict]:
      pass






class       _SCREAMING_SNAKE_CASE	(UpperCamelCase ):





     def __init__(       self :							Optional[Any]     ,  UpperCamelCase :							Optional[Features] = None     ,  UpperCamelCase :							str = None     ,  UpperCamelCase :							bool = False     ,  UpperCamelCase :							bool = False     ,  UpperCamelCase :							Optional[int] = None     ,  **UpperCamelCase :							Dict     ,  )->Optional[int]:
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	features
      __SCREAMING_SNAKE_CASE       :    str       =	cache_dir
      __SCREAMING_SNAKE_CASE       :    Any       =	keep_in_memory
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	streaming
      __SCREAMING_SNAKE_CASE       :    int       =	num_proc
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	kwargs






     @abstractmethod
     def 	__snake_case    (       self :							str				)->Union[Dataset, IterableDataset]:
      pass






