


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




				def 					a__(		self      :			List[Any]				)->					int:

										"""simple docstring"""




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




				def 					a__(		self      :			Dict				,   **lowerCAmelCase      :			Dict				)->					int:

										"""simple docstring"""




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




				def 					a__(		self      :			Optional[int]				,   **lowerCAmelCase      :			List[str]				)->					Tuple:

										"""simple docstring"""




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




				def 					a__(		self      :			List[str]				)->					Any:

										"""simple docstring"""




										shutil.rmtree(self.tmpdirname				)




				def 					a__(		self      :			str				)->					Any:

										"""simple docstring"""




										UpperCAmelCase					    =     self.get_image_processor()
										UpperCAmelCase					    =     self.get_feature_extractor()

										UpperCAmelCase					    =     TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE				,   feature_extractor=_SCREAMING_SNAKE_CASE				)
										processor.save_pretrained(self.tmpdirname				)
										UpperCAmelCase					    =     TvltProcessor.from_pretrained(self.tmpdirname				)

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




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

										"""simple docstring"""




										UpperCAmelCase					    =     self.get_image_processor()
										UpperCAmelCase					    =     self.get_feature_extractor()

										UpperCAmelCase					    =     TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE				,   feature_extractor=_SCREAMING_SNAKE_CASE				)

										UpperCAmelCase					    =     np.ones([12000]				)

										UpperCAmelCase					    =     feature_extractor(_SCREAMING_SNAKE_CASE				,   return_tensors='''np'''				)
										UpperCAmelCase					    =     processor(audio=_SCREAMING_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      :			Any				)->					Union[str, Any]:

										"""simple docstring"""




										UpperCAmelCase					    =     self.get_image_processor()
										UpperCAmelCase					    =     self.get_feature_extractor()

										UpperCAmelCase					    =     TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE				,   feature_extractor=_SCREAMING_SNAKE_CASE				)

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

										UpperCAmelCase					    =     image_processor(_SCREAMING_SNAKE_CASE				,   return_tensors='''np'''				)
										UpperCAmelCase					    =     processor(images=_SCREAMING_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      :			Optional[int]				)->					Optional[int]:

										"""simple docstring"""




										UpperCAmelCase					    =     self.get_image_processor()
										UpperCAmelCase					    =     self.get_feature_extractor()

										UpperCAmelCase					    =     TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE				,   feature_extractor=_SCREAMING_SNAKE_CASE				)

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

										UpperCAmelCase					    =     processor(audio=_SCREAMING_SNAKE_CASE				,   images=_SCREAMING_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(_SCREAMING_SNAKE_CASE				):
																processor()





				def 					a__(		self      :			List[Any]				)->					List[str]:

										"""simple docstring"""




										UpperCAmelCase					    =     self.get_image_processor()
										UpperCAmelCase					    =     self.get_feature_extractor()

										UpperCAmelCase					    =     TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE				,   feature_extractor=_SCREAMING_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'''				,   )









'''simple docstring'''



# limitations under the License.

# NOTE: This file is deprecated and will be removed in a future version.
# It only exists so that temporarely `from diffusers.pipelines import DiffusionPipeline` works

from .pipelines import DiffusionPipeline, ImagePipelineOutput  # noqa: F401
from .utils import deprecate


deprecate(
    """pipelines_utils""",
    """0.22.0""",
    """Importing `DiffusionPipeline` or `ImagePipelineOutput` from diffusers.pipeline_utils is deprecated. Please import from diffusers.pipelines.pipeline_utils instead.""",
    standard_warn=False,
    stacklevel=3,
)





