



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





				'''simple docstring'''





				def  __lowerCamelCase   (							self     :     Any):







											'''simple docstring'''

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

				def  __lowerCamelCase   (							self     :     Dict     ,				**_lowerCAmelCase     :     List[Any]):







											'''simple docstring'''

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

				def  __lowerCamelCase   (							self     :     str     ,				**_lowerCAmelCase     :     Any):







											'''simple docstring'''

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

				def  __lowerCamelCase   (							self     :     Optional[Any]):







											'''simple docstring'''

											shutil.rmtree(self.tmpdirname)

				def  __lowerCamelCase   (							self     :     List[Any]):







											'''simple docstring'''

											__lowercase						=self.get_image_processor()
											__lowercase						=self.get_feature_extractor()

											__lowercase						=TvltProcessor(image_processor=A_     ,				feature_extractor=A_)
											processor.save_pretrained(self.tmpdirname)
											__lowercase						=TvltProcessor.from_pretrained(self.tmpdirname)

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

				def  __lowerCamelCase   (							self     :     str):







											'''simple docstring'''

											__lowercase						=self.get_image_processor()
											__lowercase						=self.get_feature_extractor()

											__lowercase						=TvltProcessor(image_processor=A_     ,				feature_extractor=A_)

											__lowercase						=np.ones([1_2_0_0_0])

											__lowercase						=feature_extractor(A_     ,				return_tensors='np')
											__lowercase						=processor(audio=A_     ,				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     :     int):







											'''simple docstring'''

											__lowercase						=self.get_image_processor()
											__lowercase						=self.get_feature_extractor()

											__lowercase						=TvltProcessor(image_processor=A_     ,				feature_extractor=A_)

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

											__lowercase						=image_processor(A_     ,				return_tensors='np')
											__lowercase						=processor(images=A_     ,				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     :     Union[str, Any]):







											'''simple docstring'''

											__lowercase						=self.get_image_processor()
											__lowercase						=self.get_feature_extractor()

											__lowercase						=TvltProcessor(image_processor=A_     ,				feature_extractor=A_)

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

											__lowercase						=processor(audio=A_     ,				images=A_)

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

				def  __lowerCamelCase   (							self     :     Dict):







											'''simple docstring'''

											__lowercase						=self.get_image_processor()
											__lowercase						=self.get_feature_extractor()

											__lowercase						=TvltProcessor(image_processor=A_     ,				feature_extractor=A_)

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





import os

from huggingface_hub.constants import HUGGINGFACE_HUB_CACHE, hf_cache_home


_UpperCAmelCase					: Optional[int]      =       HUGGINGFACE_HUB_CACHE


_UpperCAmelCase					: List[str]      =       "config.json"
_UpperCAmelCase					: Union[str, Any]      =       "diffusion_pytorch_model.bin"
_UpperCAmelCase					: List[Any]      =       "diffusion_flax_model.msgpack"
_UpperCAmelCase					: Optional[Any]      =       "model.onnx"
_UpperCAmelCase					: int      =       "diffusion_pytorch_model.safetensors"
_UpperCAmelCase					: Optional[Any]      =       "weights.pb"
_UpperCAmelCase					: Tuple      =       "https://huggingface.co"
_UpperCAmelCase					: Union[str, Any]      =       default_cache_path
_UpperCAmelCase					: Optional[Any]      =       "diffusers_modules"
_UpperCAmelCase					: List[Any]      =       os.getenv("HF_MODULES_CACHE", os.path.join(hf_cache_home, "modules"))
_UpperCAmelCase					: Tuple      =       ["fp16", "non-ema"]
_UpperCAmelCase					: Any      =       ".self_attn"
