






from __future__ import annotations

import collections
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import is_tf_available, is_vision_available

from ...test_modeling_tf_common import floats_tensor, ids_tensor, random_attention_mask
from ..bert.test_modeling_tf_bert import TFBertModelTester
from ..clip.test_modeling_tf_clip import TFCLIPVisionModelTester
from ..deit.test_modeling_tf_deit import TFDeiTModelTester
from ..roberta.test_modeling_tf_roberta import TFRobertaModelTester
from ..vit.test_modeling_tf_vit import TFViTModelTester


if is_tf_available():
		from transformers import (
		    TFBertModel,
		    TFCLIPVisionModel,
		    TFDeiTModel,
		    TFRobertaModel,
		    TFVisionTextDualEncoderModel,
		    TFViTModel,
		    VisionTextDualEncoderConfig,
		)

if is_vision_available():
		from PIL import Image

		from transformers import VisionTextDualEncoderProcessor






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		if isinstance(_lowerCamelCase     ,       collections.abc.Iterable	):
				return x
		return (x, x)





@require_tf
class  _a							:




	def 							UpperCAmelCase__( self						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		int		)->	str:
			pass




	def 							UpperCAmelCase__( self						:		Dict		)->	Tuple:
			pass




	def 							UpperCAmelCase__( self						:		List[Any]		)->	Tuple:
			pass




	def 							UpperCAmelCase__( self						:		str		, _SCREAMING_SNAKE_CASE						:		Dict		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		int		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]=None		, **_SCREAMING_SNAKE_CASE						:		List[Any]		)->	List[Any]:
			lowerCAmelCase__       :      List[Any]   					= VisionTextDualEncoderConfig.from_vision_text_configs(_SCREAMING_SNAKE_CASE		, _SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      List[str]   					= TFVisionTextDualEncoderModel(_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      int   					= model(input_ids=_SCREAMING_SNAKE_CASE		, pixel_values=_SCREAMING_SNAKE_CASE		, attention_mask=_SCREAMING_SNAKE_CASE		)

			self.assertEqual(output['''text_embeds'''].shape		, (input_ids.shape[0], config.projection_dim)		)
			self.assertEqual(output['''image_embeds'''].shape		, (pixel_values.shape[0], config.projection_dim)		)




	def 							UpperCAmelCase__( self						:		str		, _SCREAMING_SNAKE_CASE						:		str		, _SCREAMING_SNAKE_CASE						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		List[str]		, _SCREAMING_SNAKE_CASE						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		List[str]=None		, **_SCREAMING_SNAKE_CASE						:		Dict		)->	Optional[int]:
			lowerCAmelCase__       :      Union[str, Any]   					= self.get_vision_text_model(_SCREAMING_SNAKE_CASE		, _SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      Optional[Any]   					= TFVisionTextDualEncoderModel(vision_model=_SCREAMING_SNAKE_CASE		, text_model=_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      Optional[int]   					= model(input_ids=_SCREAMING_SNAKE_CASE		, pixel_values=_SCREAMING_SNAKE_CASE		, attention_mask=_SCREAMING_SNAKE_CASE		)

			self.assertEqual(output['''text_embeds'''].shape		, (input_ids.shape[0], model.config.projection_dim)		)
			self.assertEqual(output['''image_embeds'''].shape		, (pixel_values.shape[0], model.config.projection_dim)		)




	def 							UpperCAmelCase__( self						:		Any		, _SCREAMING_SNAKE_CASE						:		Dict		, _SCREAMING_SNAKE_CASE						:		int		, _SCREAMING_SNAKE_CASE						:		Tuple		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		str=None		, **_SCREAMING_SNAKE_CASE						:		Dict		)->	Tuple:
			lowerCAmelCase__       :      Optional[Any]   					= self.get_vision_text_model(_SCREAMING_SNAKE_CASE		, _SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      List[str]   					= {"""vision_model""": vision_model, """text_model""": text_model}
			lowerCAmelCase__       :      int   					= TFVisionTextDualEncoderModel.from_vision_text_pretrained(**_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      Union[str, Any]   					= model(input_ids=_SCREAMING_SNAKE_CASE		, pixel_values=_SCREAMING_SNAKE_CASE		, attention_mask=_SCREAMING_SNAKE_CASE		)

			self.assertEqual(output['''text_embeds'''].shape		, (input_ids.shape[0], model.config.projection_dim)		)
			self.assertEqual(output['''image_embeds'''].shape		, (pixel_values.shape[0], model.config.projection_dim)		)




	def 							UpperCAmelCase__( self						:		List[str]		, _SCREAMING_SNAKE_CASE						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Dict		, _SCREAMING_SNAKE_CASE						:		int		, _SCREAMING_SNAKE_CASE						:		int=None		, **_SCREAMING_SNAKE_CASE						:		Tuple		)->	List[Any]:
			lowerCAmelCase__       :      Dict   					= self.get_vision_text_model(_SCREAMING_SNAKE_CASE		, _SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      Tuple   					= TFVisionTextDualEncoderModel(vision_model=_SCREAMING_SNAKE_CASE		, text_model=_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      Any   					= model(input_ids=_SCREAMING_SNAKE_CASE		, pixel_values=_SCREAMING_SNAKE_CASE		, attention_mask=_SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      str   					= output[0].numpy()

			with tempfile.TemporaryDirectory() as tmpdirname:
					model.save_pretrained(_SCREAMING_SNAKE_CASE		)
					lowerCAmelCase__       :      str   					= TFVisionTextDualEncoderModel.from_pretrained(_SCREAMING_SNAKE_CASE		)

					lowerCAmelCase__       :      Optional[int]   					= model(input_ids=_SCREAMING_SNAKE_CASE		, pixel_values=_SCREAMING_SNAKE_CASE		, attention_mask=_SCREAMING_SNAKE_CASE		)
					lowerCAmelCase__       :      int   					= after_output[0].numpy()
					lowerCAmelCase__       :      Tuple   					= np.amax(np.abs(out_a - out_a		)		)
					self.assertLessEqual(_SCREAMING_SNAKE_CASE		, 1E-5		)




	def 							UpperCAmelCase__( self						:		str		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		List[str]		, _SCREAMING_SNAKE_CASE						:		Optional[Any]=None		, **_SCREAMING_SNAKE_CASE						:		Dict		)->	str:
			lowerCAmelCase__       :      Dict   					= self.get_vision_text_model(_SCREAMING_SNAKE_CASE		, _SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      List[Any]   					= TFVisionTextDualEncoderModel(vision_model=_SCREAMING_SNAKE_CASE		, text_model=_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      Dict   					= model(
			    input_ids=_SCREAMING_SNAKE_CASE		, pixel_values=_SCREAMING_SNAKE_CASE		, attention_mask=_SCREAMING_SNAKE_CASE		, output_attentions=_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      Optional[Any]   					= output.vision_model_output.attentions
			self.assertEqual(len(_SCREAMING_SNAKE_CASE		)		, vision_config.num_hidden_layers		)

			# in ViT, the seq_len equals the number of patches + 1 (we add 1 for the [CLS] token)
			lowerCAmelCase__       :      Any   					= to_atuple(vision_model.config.image_size		)
			lowerCAmelCase__       :      Tuple   					= to_atuple(vision_model.config.patch_size		)
			lowerCAmelCase__       :      int   					= (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
			lowerCAmelCase__       :      Union[str, Any]   					= num_patches + 1
			self.assertEqual(vision_attentions[0].shape[-3:]		, (vision_config.num_attention_heads, seq_len, seq_len)		)

			lowerCAmelCase__       :      Any   					= output.text_model_output.attentions
			self.assertEqual(len(_SCREAMING_SNAKE_CASE		)		, text_config.num_hidden_layers		)

			self.assertEqual(
			    text_attentions[0].shape[-3:]		, (text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])		, )




	def 							UpperCAmelCase__( self						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		np.ndarray		, _SCREAMING_SNAKE_CASE						:		np.ndarray		, _SCREAMING_SNAKE_CASE						:		float		)->	Union[str, Any]:
			lowerCAmelCase__       :      Tuple   					= np.abs((a - b)		).max()
			self.assertLessEqual(_SCREAMING_SNAKE_CASE		, _SCREAMING_SNAKE_CASE		, F'Difference between torch and flax is {diff} (>= {tol}).'		)




	def 							UpperCAmelCase__( self						:		List[str]		)->	str:
			lowerCAmelCase__       :      Dict   					= self.prepare_config_and_inputs()
			self.check_vision_text_dual_encoder_model(**_SCREAMING_SNAKE_CASE		)




	def 							UpperCAmelCase__( self						:		List[str]		)->	Optional[Any]:
			lowerCAmelCase__       :      Tuple   					= self.prepare_config_and_inputs()
			self.check_model_from_pretrained_configs(**_SCREAMING_SNAKE_CASE		)




	def 							UpperCAmelCase__( self						:		Tuple		)->	Optional[Any]:
			lowerCAmelCase__       :      Tuple   					= self.prepare_config_and_inputs()
			self.check_vision_text_dual_encoder_from_pretrained(**_SCREAMING_SNAKE_CASE		)




	def 							UpperCAmelCase__( self						:		Dict		)->	Union[str, Any]:
			lowerCAmelCase__       :      int   					= self.prepare_config_and_inputs()
			self.check_save_load(**_SCREAMING_SNAKE_CASE		)




	def 							UpperCAmelCase__( self						:		Union[str, Any]		)->	Tuple:
			lowerCAmelCase__       :      Optional[Any]   					= self.prepare_config_and_inputs()
			self.check_vision_text_output_attention(**_SCREAMING_SNAKE_CASE		)




	@slow
	def 							UpperCAmelCase__( self						:		List[Any]		)->	Dict:
			lowerCAmelCase__       :      List[str]   					= self.get_pretrained_model_and_inputs()

			lowerCAmelCase__       :      Any   					= model_a(**_SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      Any   					= outputs[0].numpy()

			with tempfile.TemporaryDirectory() as tmp_dirname:
					model_a.save_pretrained(_SCREAMING_SNAKE_CASE		)
					lowerCAmelCase__       :      List[str]   					= TFVisionTextDualEncoderModel.from_pretrained(_SCREAMING_SNAKE_CASE		)

					lowerCAmelCase__       :      Optional[int]   					= model_a(**_SCREAMING_SNAKE_CASE		)
					lowerCAmelCase__       :      Union[str, Any]   					= after_outputs[0].numpy()
					lowerCAmelCase__       :      Dict   					= np.amax(np.abs(out_a - out_a		)		)
					self.assertLessEqual(_SCREAMING_SNAKE_CASE		, 1E-5		)





@require_tf
class  _a							(    __lowercase					,						unittest.TestCase):




	def 							UpperCAmelCase__( self						:		Any		)->	Dict:
			lowerCAmelCase__       :      Union[str, Any]   					= TFVisionTextDualEncoderModel.from_vision_text_pretrained(
			    '''hf-internal-testing/tiny-random-vit'''		, '''hf-internal-testing/tiny-random-bert'''		)
			lowerCAmelCase__       :      Tuple   					= 13
			lowerCAmelCase__       :      List[str]   					= floats_tensor(
			    [
			        batch_size,
			        model.vision_model.config.num_channels,
			        model.vision_model.config.image_size,
			        model.vision_model.config.image_size,
			    ]		)
			lowerCAmelCase__       :      Union[str, Any]   					= ids_tensor([batch_size, 4]		, model.text_model.config.vocab_size		)
			lowerCAmelCase__       :      Optional[Any]   					= random_attention_mask([batch_size, 4]		)
			lowerCAmelCase__       :      str   					= {"""pixel_values""": pixel_values, """input_ids""": input_ids, """attention_mask""": attention_mask}

			return model, inputs




	def 							UpperCAmelCase__( self						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		str		)->	List[Any]:
			lowerCAmelCase__       :      Optional[int]   					= TFViTModel(_SCREAMING_SNAKE_CASE		, name='''vision_model'''		)
			lowerCAmelCase__       :      int   					= TFBertModel(_SCREAMING_SNAKE_CASE		, name='''text_model'''		)
			return vision_model, text_model




	def 							UpperCAmelCase__( self						:		Tuple		)->	Optional[Any]:
			lowerCAmelCase__       :      Any   					= TFViTModelTester(self		)
			lowerCAmelCase__       :      Optional[Any]   					= TFBertModelTester(self		)
			lowerCAmelCase__       :      List[str]   					= vit_model_tester.prepare_config_and_inputs()
			lowerCAmelCase__       :      Tuple   					= bert_model_tester.prepare_config_and_inputs()

			lowerCAmelCase__       :      Optional[Any]   					= vision_config_and_inputs

			(
			    lowerCAmelCase__      
			)       :      List[str]   					= text_config_and_inputs

			return {
			    "text_config": text_config,
			    "vision_config": vision_config,
			    "pixel_values": pixel_values,
			    "attention_mask": input_mask,
			    "input_ids": input_ids,
			    "text_token_type_ids": token_type_ids,
			    "text_sequence_labels": sequence_labels,
			    "text_token_labels": token_labels,
			    "text_choice_labels": choice_labels,
			}





@require_tf
class  _a							(    __lowercase					,						unittest.TestCase):




	def 							UpperCAmelCase__( self						:		Union[str, Any]		)->	Optional[Any]:
			lowerCAmelCase__       :      Tuple   					= TFVisionTextDualEncoderModel.from_vision_text_pretrained(
			    '''Rocketknight1/tiny-random-deit-tf'''		, '''hf-internal-testing/tiny-random-roberta'''		)
			lowerCAmelCase__       :      int   					= 13
			lowerCAmelCase__       :      List[str]   					= floats_tensor(
			    [
			        batch_size,
			        model.vision_model.config.num_channels,
			        model.vision_model.config.image_size,
			        model.vision_model.config.image_size,
			    ]		)
			lowerCAmelCase__       :      Any   					= ids_tensor([batch_size, 4]		, model.text_model.config.vocab_size		)
			lowerCAmelCase__       :      Tuple   					= random_attention_mask([batch_size, 4]		)
			lowerCAmelCase__       :      Optional[Any]   					= {"""pixel_values""": pixel_values, """input_ids""": input_ids, """attention_mask""": attention_mask}

			return model, inputs




	def 							UpperCAmelCase__( self						:		int		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		int		, _SCREAMING_SNAKE_CASE						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		Dict		, _SCREAMING_SNAKE_CASE						:		Tuple=None		, **_SCREAMING_SNAKE_CASE						:		List[str]		)->	Optional[int]:
			lowerCAmelCase__       :      Any   					= self.get_vision_text_model(_SCREAMING_SNAKE_CASE		, _SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      int   					= TFVisionTextDualEncoderModel(vision_model=_SCREAMING_SNAKE_CASE		, text_model=_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      Any   					= model(
			    input_ids=_SCREAMING_SNAKE_CASE		, pixel_values=_SCREAMING_SNAKE_CASE		, attention_mask=_SCREAMING_SNAKE_CASE		, output_attentions=_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      List[str]   					= output.vision_model_output.attentions
			self.assertEqual(len(_SCREAMING_SNAKE_CASE		)		, vision_config.num_hidden_layers		)

			# in DEiT, the seq_len equals the number of patches + 2 (we add 2 for the [CLS] and distillation tokens)
			lowerCAmelCase__       :      Optional[int]   					= to_atuple(vision_model.config.image_size		)
			lowerCAmelCase__       :      Optional[int]   					= to_atuple(vision_model.config.patch_size		)
			lowerCAmelCase__       :      Union[str, Any]   					= (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
			lowerCAmelCase__       :      List[str]   					= num_patches + 2
			self.assertEqual(vision_attentions[0].shape[-3:]		, (vision_config.num_attention_heads, seq_len, seq_len)		)

			lowerCAmelCase__       :      Union[str, Any]   					= output.text_model_output.attentions
			self.assertEqual(len(_SCREAMING_SNAKE_CASE		)		, text_config.num_hidden_layers		)

			self.assertEqual(
			    text_attentions[0].shape[-3:]		, (text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])		, )




	def 							UpperCAmelCase__( self						:		Tuple		, _SCREAMING_SNAKE_CASE						:		int		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		)->	List[str]:
			lowerCAmelCase__       :      int   					= TFDeiTModel(_SCREAMING_SNAKE_CASE		, name='''vision_model'''		)
			lowerCAmelCase__       :      Optional[Any]   					= TFRobertaModel(_SCREAMING_SNAKE_CASE		, name='''text_model'''		)
			return vision_model, text_model




	def 							UpperCAmelCase__( self						:		Union[str, Any]		)->	Any:
			lowerCAmelCase__       :      Dict   					= TFDeiTModelTester(self		)
			lowerCAmelCase__       :      Optional[int]   					= TFRobertaModelTester(self		)
			lowerCAmelCase__       :      Dict   					= vit_model_tester.prepare_config_and_inputs()
			lowerCAmelCase__       :      Optional[int]   					= bert_model_tester.prepare_config_and_inputs()

			lowerCAmelCase__       :      int   					= vision_config_and_inputs

			(
			    lowerCAmelCase__      
			)       :      Optional[int]   					= text_config_and_inputs

			return {
			    "text_config": text_config,
			    "vision_config": vision_config,
			    "pixel_values": pixel_values,
			    "attention_mask": input_mask,
			    "input_ids": input_ids,
			    "text_token_type_ids": token_type_ids,
			    "text_sequence_labels": sequence_labels,
			    "text_token_labels": token_labels,
			    "text_choice_labels": choice_labels,
			}





@require_tf
class  _a							(    __lowercase					,						unittest.TestCase):




	def 							UpperCAmelCase__( self						:		Tuple		)->	Optional[int]:
			lowerCAmelCase__       :      Optional[Any]   					= TFVisionTextDualEncoderModel.from_vision_text_pretrained(
			    '''Rocketknight1/tiny-random-clip-tf'''		, '''hf-internal-testing/tiny-random-bert'''		)
			lowerCAmelCase__       :      Optional[int]   					= 13
			lowerCAmelCase__       :      List[Any]   					= floats_tensor(
			    [
			        batch_size,
			        model.vision_model.config.num_channels,
			        model.vision_model.config.image_size,
			        model.vision_model.config.image_size,
			    ]		)
			lowerCAmelCase__       :      int   					= ids_tensor([batch_size, 4]		, model.text_model.config.vocab_size		)
			lowerCAmelCase__       :      Optional[int]   					= random_attention_mask([batch_size, 4]		)
			lowerCAmelCase__       :      Dict   					= {"""pixel_values""": pixel_values, """input_ids""": input_ids, """attention_mask""": attention_mask}

			return model, inputs




	def 							UpperCAmelCase__( self						:		int		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		Any		)->	Any:
			lowerCAmelCase__       :      Tuple   					= TFCLIPVisionModel(_SCREAMING_SNAKE_CASE		, name='''vision_model'''		)
			lowerCAmelCase__       :      str   					= TFBertModel(_SCREAMING_SNAKE_CASE		, name='''text_model'''		)
			return vision_model, text_model




	def 							UpperCAmelCase__( self						:		Optional[Any]		)->	Dict:
			lowerCAmelCase__       :      List[Any]   					= TFCLIPVisionModelTester(self		)
			lowerCAmelCase__       :      Dict   					= TFBertModelTester(self		)
			lowerCAmelCase__       :      str   					= clip_model_tester.prepare_config_and_inputs()
			lowerCAmelCase__       :      Tuple   					= bert_model_tester.prepare_config_and_inputs()

			lowerCAmelCase__       :      Optional[int]   					= vision_config_and_inputs

			(
			    lowerCAmelCase__      
			)       :      List[Any]   					= text_config_and_inputs

			return {
			    "text_config": text_config,
			    "vision_config": vision_config,
			    "pixel_values": pixel_values,
			    "attention_mask": input_mask,
			    "input_ids": input_ids,
			    "text_token_type_ids": token_type_ids,
			    "text_sequence_labels": sequence_labels,
			    "text_token_labels": token_labels,
			    "text_choice_labels": choice_labels,
			}





@require_vision
@require_tf
class  _a							(    unittest.TestCase):




	@slow
	def 							UpperCAmelCase__( self						:		Optional[Any]		)->	Any:
			lowerCAmelCase__       :      int   					= TFVisionTextDualEncoderModel.from_pretrained(
			    '''clip-italian/clip-italian'''		, logit_scale_init_value=1.0		, from_pt=_SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      Optional[int]   					= VisionTextDualEncoderProcessor.from_pretrained('''clip-italian/clip-italian'''		)

			lowerCAmelCase__       :      List[Any]   					= Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
			lowerCAmelCase__       :      Optional[int]   					= processor(
			    text=['''una foto di un gatto''', '''una foto di un cane''']		, images=_SCREAMING_SNAKE_CASE		, padding=_SCREAMING_SNAKE_CASE		, return_tensors='''np'''		)

			lowerCAmelCase__       :      str   					= model(**_SCREAMING_SNAKE_CASE		)

			# verify the logits
			self.assertEqual(outputs.logits_per_image.shape		, (inputs.pixel_values.shape[0], inputs.input_ids.shape[0])		)
			self.assertEqual(
			    outputs.logits_per_text.shape		, (inputs.input_ids.shape[0], inputs.pixel_values.shape[0])		, )

			lowerCAmelCase__       :      Optional[Any]   					= np.array([[1.228_4727, 0.310_4122]]		)

			self.assertTrue(np.allclose(outputs.logits_per_image.numpy()		, _SCREAMING_SNAKE_CASE		, atol=1E-3		)		)








from ...utils import is_note_seq_available, is_transformers_available, is_torch_available
from ...utils import OptionalDependencyNotAvailable


try:
		if not (is_transformers_available() and is_torch_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
		from .notes_encoder import SpectrogramNotesEncoder
		from .continous_encoder import SpectrogramContEncoder
		from .pipeline_spectrogram_diffusion import (
		    SpectrogramContEncoder,
		    SpectrogramDiffusionPipeline,
		    TaFilmDecoder,
		)

try:
		if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ...utils.dummy_transformers_and_torch_and_note_seq_objects import *  # noqa F403
else:
		from .midi_utils import MidiProcessor




