


import unittest

import numpy as np

from transformers import MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING, TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
from transformers.pipelines import AudioClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_torchaudio,
    slow,
)

from .test_pipelines_common import ANY


@is_pipeline_test
class 	_a							(      unittest.TestCase      ):
							_lowercase     :      List[str]  				=			MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
							_lowercase     :      List[Any]  				=			TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING

							def 				lowerCamelCase_			(							self:     List[str]   ,						UpperCamelCase_:     int   ,						UpperCamelCase_:     Dict   ,						UpperCamelCase_:     str							)      ->       List[Any]:





									"""simple docstring"""







									lowercase__						=				AudioClassificationPipeline(model=UpperCamelCase_   ,						feature_extractor=UpperCamelCase_							)

									# test with a raw waveform
									lowercase__						=				np.zeros((34_000,)							)
									lowercase__						=				np.zeros((14_000,)							)
									return audio_classifier, [audioa, audio]

							def 				lowerCamelCase_			(							self:     List[Any]   ,						UpperCamelCase_:     Dict   ,						UpperCamelCase_:     Union[str, Any]							)      ->       Optional[Any]:





									"""simple docstring"""







									lowercase__					,		lowercase__						=				examples
									lowercase__						=				audio_classifier(UpperCamelCase_							)
									# by default a model is initialized with num_labels=2
									self.assertEqual(
									    UpperCamelCase_   ,						[
									        {'''score''': ANY(UpperCamelCase_							), '''label''': ANY(UpperCamelCase_							)},
									        {'''score''': ANY(UpperCamelCase_							), '''label''': ANY(UpperCamelCase_							)},
									    ]   ,						)
									lowercase__						=				audio_classifier(UpperCamelCase_   ,						top_k=1							)
									self.assertEqual(
									    UpperCamelCase_   ,						[
									        {'''score''': ANY(UpperCamelCase_							), '''label''': ANY(UpperCamelCase_							)},
									    ]   ,						)

									self.run_torchaudio(UpperCamelCase_							)

							@require_torchaudio
							def 				lowerCamelCase_			(							self:     Tuple   ,						UpperCamelCase_:     List[Any]							)      ->       int:





									"""simple docstring"""







									import datasets

									# test with a local file
									lowercase__						=				datasets.load_dataset('''hf-internal-testing/librispeech_asr_dummy'''   ,						'''clean'''   ,						split='''validation'''							)
									lowercase__						=				dataset[0]['''audio''']['''array''']
									lowercase__						=				audio_classifier(UpperCamelCase_							)
									self.assertEqual(
									    UpperCamelCase_   ,						[
									        {'''score''': ANY(UpperCamelCase_							), '''label''': ANY(UpperCamelCase_							)},
									        {'''score''': ANY(UpperCamelCase_							), '''label''': ANY(UpperCamelCase_							)},
									    ]   ,						)

							@require_torch
							def 				lowerCamelCase_			(							self:     Optional[int]							)      ->       List[str]:





									"""simple docstring"""







									lowercase__						=				'''anton-l/wav2vec2-random-tiny-classifier'''

									lowercase__						=				pipeline('''audio-classification'''   ,						model=UpperCamelCase_							)

									lowercase__						=				np.ones((8_000,)							)
									lowercase__						=				audio_classifier(UpperCamelCase_   ,						top_k=4							)

									lowercase__						=				[
									    {'''score''': 0.0842, '''label''': '''no'''},
									    {'''score''': 0.0838, '''label''': '''up'''},
									    {'''score''': 0.0837, '''label''': '''go'''},
									    {'''score''': 0.0834, '''label''': '''right'''},
									]
									lowercase__						=				[
									    {'''score''': 0.0845, '''label''': '''stop'''},
									    {'''score''': 0.0844, '''label''': '''on'''},
									    {'''score''': 0.0841, '''label''': '''right'''},
									    {'''score''': 0.0834, '''label''': '''left'''},
									]
									self.assertIn(nested_simplify(UpperCamelCase_   ,						decimals=4							)   ,						[EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]							)

									lowercase__						=				{'''array''': np.ones((8_000,)							), '''sampling_rate''': audio_classifier.feature_extractor.sampling_rate}
									lowercase__						=				audio_classifier(UpperCamelCase_   ,						top_k=4							)
									self.assertIn(nested_simplify(UpperCamelCase_   ,						decimals=4							)   ,						[EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]							)

							@require_torch
							@slow
							def 				lowerCamelCase_			(							self:     Union[str, Any]							)      ->       List[Any]:





									"""simple docstring"""







									import datasets

									lowercase__						=				'''superb/wav2vec2-base-superb-ks'''

									lowercase__						=				pipeline('''audio-classification'''   ,						model=UpperCamelCase_							)
									lowercase__						=				datasets.load_dataset('''anton-l/superb_dummy'''   ,						'''ks'''   ,						split='''test'''							)

									lowercase__						=				np.array(dataset[3]['''speech''']   ,						dtype=np.floataa							)
									lowercase__						=				audio_classifier(UpperCamelCase_   ,						top_k=4							)
									self.assertEqual(
									    nested_simplify(UpperCamelCase_   ,						decimals=3							)   ,						[
									        {'''score''': 0.981, '''label''': '''go'''},
									        {'''score''': 0.007, '''label''': '''up'''},
									        {'''score''': 0.006, '''label''': '''_unknown_'''},
									        {'''score''': 0.001, '''label''': '''down'''},
									    ]   ,						)


							@require_tf
							@unittest.skip('''Audio classification is not implemented for TF'''							)
							def 				lowerCamelCase_			(							self:     Union[str, Any]							)      ->       Optional[Any]:





									"""simple docstring"""







									pass






def       _a			(				SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE					):


		"""simple docstring"""




		return base * power(SCREAMING_SNAKE_CASE						,    (exponent - 1)					) if exponent else 1


if __name__ == "__main__":
			print('Raise base to the power of exponent using recursion...')
			lowerCAmelCase	=							int(input('Enter the base: ').strip())
			lowerCAmelCase	=							int(input('Enter the exponent: ').strip())
			lowerCAmelCase	=							power(base, abs(exponent))
			if exponent < 0:  # power() does not properly deal w/ negative exponents
						lowerCAmelCase	=							1 / result
			print(f"""{base} to the power of {exponent} is {result}""")


