





'''simple docstring'''





from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding



class    _a     (				lowercase__							):






							"""simple docstring"""

							snake_case_							 =						["image_processor", "tokenizer"]
							snake_case_							 =						"AutoImageProcessor"
							snake_case_							 =						"AutoTokenizer"

							def __init__(      self				:     str							,	a				:     Union[str, Any]							,	a				:     Union[str, Any]    )	->List[str]:
													super().__init__(UpperCamelCase__							,	UpperCamelCase__    )
													SCREAMING_SNAKE_CASE__     :				Dict   =					self.image_processor

							def __call__(      self				:     List[Any]							,	a				:     List[Any]=None							,	a				:     Optional[int]=None							,	a				:     List[Any]=None							,	**a				:     Dict    )	->Dict:





													if text is None and images is None:
																			raise ValueError("You have to specify either text or images. Both cannot be none."    )

													if text is not None:
																			SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					self.tokenizer(UpperCamelCase__							,	return_tensors=UpperCamelCase__							,	**UpperCamelCase__    )

													if images is not None:
																			SCREAMING_SNAKE_CASE__     :				str   =					self.image_processor(UpperCamelCase__							,	return_tensors=UpperCamelCase__							,	**UpperCamelCase__    )

													if text is not None and images is not None:
																			SCREAMING_SNAKE_CASE__     :				Tuple   =					image_features.pixel_values
																			return encoding
													elif text is not None:
																			return encoding
													else:
																			return BatchEncoding(data=dict(**UpperCamelCase__    )							,	tensor_type=UpperCamelCase__    )

							def      A_  (      self				:     Dict							,	*a				:     Optional[int]							,	**a				:     Dict    )	->Union[str, Any]:
													return self.tokenizer.batch_decode(*UpperCamelCase__							,	**UpperCamelCase__    )

							def      A_  (      self				:     Dict							,	*a				:     Optional[Any]							,	**a				:     Optional[int]    )	->Any:
													return self.tokenizer.decode(*UpperCamelCase__							,	**UpperCamelCase__    )






							@property
							def      A_  (      self				:     Dict    )	->Optional[Any]:
													return ["input_ids", "attention_mask", "pixel_values"]






import unittest

from datasets import load_dataset

from transformers.pipelines import pipeline
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_torch, slow



@is_pipeline_test
@require_torch
class    _a     (				unittest.TestCase							):






							"""simple docstring"""

							@require_torch
							def      A_  (      self				:     Dict    )	->str:
													SCREAMING_SNAKE_CASE__     :				Any   =					pipeline(
													    task="zero-shot-audio-classification"							,	model="hf-internal-testing/tiny-clap-htsat-unfused"    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					load_dataset("ashraq/esc50"    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					dataset["train"]["audio"][-1]["array"]
													SCREAMING_SNAKE_CASE__     :				int   =					audio_classifier(a							,	candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"]    )
													self.assertEqual(
													    nested_simplify(a    )							,	[{"score": 0.501, "label": "Sound of a dog"}, {"score": 0.499, "label": "Sound of vaccum cleaner"}]							,	)

							@unittest.skip("No models are available in TF"    )
							def      A_  (      self				:     int    )	->Union[str, Any]:
													pass

							@slow
							@require_torch
							def      A_  (      self				:     int    )	->str:
													SCREAMING_SNAKE_CASE__     :				List[str]   =					pipeline(
													    task="zero-shot-audio-classification"							,	model="laion/clap-htsat-unfused"							,	)
													# This is an audio of a dog
													SCREAMING_SNAKE_CASE__     :				int   =					load_dataset("ashraq/esc50"    )
													SCREAMING_SNAKE_CASE__     :				str   =					dataset["train"]["audio"][-1]["array"]
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					audio_classifier(a							,	candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"]    )

													self.assertEqual(
													    nested_simplify(a    )							,	[
													        {"score": 0.999, "label": "Sound of a dog"},
													        {"score": 0.001, "label": "Sound of vaccum cleaner"},
													    ]							,	)

													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					audio_classifier([audio] * 5							,	candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"]    )
													self.assertEqual(
													    nested_simplify(a    )							,	[
													        [
													            {"score": 0.999, "label": "Sound of a dog"},
													            {"score": 0.001, "label": "Sound of vaccum cleaner"},
													        ],
													    ]
													    * 5							,	)
													SCREAMING_SNAKE_CASE__     :				int   =					audio_classifier(
													    [audio] * 5							,	candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"]							,	batch_size=5    )
													self.assertEqual(
													    nested_simplify(a    )							,	[
													        [
													            {"score": 0.999, "label": "Sound of a dog"},
													            {"score": 0.001, "label": "Sound of vaccum cleaner"},
													        ],
													    ]
													    * 5							,	)






							@unittest.skip("No models are available in TF"    )
							def      A_  (      self				:     Optional[int]    )	->Union[str, Any]:
													pass