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







							def       UpperCAmelCase__					(						self  :  Dict ):
								"""simple docstring"""







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







							def       UpperCAmelCase__					(						self  :  List[Any]      ,				**snake_case__  :  Optional[Any] ):
								"""simple docstring"""







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







							def       UpperCAmelCase__					(						self  :  Optional[int]      ,				**snake_case__  :  Dict ):
								"""simple docstring"""







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







							def       UpperCAmelCase__					(						self  :  Optional[Any] ):
								"""simple docstring"""







								shutil.rmtree(self.tmpdirname )







							def       UpperCAmelCase__					(						self  :  Tuple ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.get_image_processor()
								__lowerCAmelCase         =							self.get_feature_extractor()

								__lowerCAmelCase         =							TvltProcessor(image_processor=__a      ,				feature_extractor=__a )
								processor.save_pretrained(self.tmpdirname )
								__lowerCAmelCase         =							TvltProcessor.from_pretrained(self.tmpdirname )

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







							def       UpperCAmelCase__					(						self  :  Any ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.get_image_processor()
								__lowerCAmelCase         =							self.get_feature_extractor()

								__lowerCAmelCase         =							TvltProcessor(image_processor=__a      ,				feature_extractor=__a )

								__lowerCAmelCase         =							np.ones([12_000] )

								__lowerCAmelCase         =							feature_extractor(__a      ,				return_tensors="np" )
								__lowerCAmelCase         =							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       UpperCAmelCase__					(						self  :  Tuple ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.get_image_processor()
								__lowerCAmelCase         =							self.get_feature_extractor()

								__lowerCAmelCase         =							TvltProcessor(image_processor=__a      ,				feature_extractor=__a )

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

								__lowerCAmelCase         =							image_processor(__a      ,				return_tensors="np" )
								__lowerCAmelCase         =							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       UpperCAmelCase__					(						self  :  List[Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.get_image_processor()
								__lowerCAmelCase         =							self.get_feature_extractor()

								__lowerCAmelCase         =							TvltProcessor(image_processor=__a      ,				feature_extractor=__a )

								__lowerCAmelCase         =							np.ones([12_000] )
								__lowerCAmelCase         =							np.ones([3, 224, 224] )

								__lowerCAmelCase         =							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       UpperCAmelCase__					(						self  :  Tuple ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.get_image_processor()
								__lowerCAmelCase         =							self.get_feature_extractor()

								__lowerCAmelCase         =							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 unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionImageVariationPipeline
from diffusers.utils.testing_utils import load_image, require_torch_gpu, slow, torch_device


UpperCamelCase_   	=	False

class       a		(   unittest.TestCase					):
							pass

@slow
@require_torch_gpu
class       a		(   unittest.TestCase					):







							def       UpperCAmelCase__					(						self  :  Dict ):
								"""simple docstring"""







								__lowerCAmelCase         =							VersatileDiffusionImageVariationPipeline.from_pretrained("shi-labs/versatile-diffusion" )
								pipe.to(snake_case__ )
								pipe.set_progress_bar_config(disable=snake_case__ )

								__lowerCAmelCase         =							load_image(
								    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg" )
								__lowerCAmelCase         =							torch.manual_seed(0 )
								__lowerCAmelCase         =							pipe(
								    image=snake_case__      ,				generator=snake_case__      ,				guidance_scale=7.5      ,				num_inference_steps=50      ,				output_type="numpy"      ,				).images

								__lowerCAmelCase         =							image[0, 253:256, 253:256, -1]

								assert image.shape == (1, 512, 512, 3)
								__lowerCAmelCase         =							np.array([0.0_4_4_1, 0.0_4_6_9, 0.0_5_0_7, 0.0_5_7_5, 0.0_6_3_2, 0.0_6_5_0, 0.0_8_6_5, 0.0_9_0_9, 0.0_9_4_5] )

								assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-2






