





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


				"""simple docstring"""


				UpperCamelCase    :  Tuple					    =	MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
				UpperCamelCase    :  Optional[int]					    =	TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING



				def 					UpperCAmelCase_		(			self     ,					_A     ,					_A     ,					_A     ):
									__A	:						Union[str, Any]       =				AudioClassificationPipeline(model=_A     ,					feature_extractor=_A     )

									# test with a raw waveform
									__A	:						Any       =				np.zeros((34000,)     )
									__A	:						Optional[int]       =				np.zeros((14000,)     )
									return audio_classifier, [audioa, audio]



				def 					UpperCAmelCase_		(			self     ,					_A     ,					_A     ):
									__A    ,				__A	:						int       =				examples
									__A	:						int       =				audio_classifier(_A     )
									# by default a model is initialized with num_labels=2
									self.assertEqual(
									    _A     ,					[
									        {'score': ANY(_A     ), 'label': ANY(_A     )},
									        {'score': ANY(_A     ), 'label': ANY(_A     )},
									    ]     ,					)
									__A	:						Union[str, Any]       =				audio_classifier(_A     ,					top_k=1     )
									self.assertEqual(
									    _A     ,					[
									        {'score': ANY(_A     ), 'label': ANY(_A     )},
									    ]     ,					)

									self.run_torchaudio(_A     )



				@require_torchaudio
				def 					UpperCAmelCase_		(			self     ,					_A     ):
									import datasets

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



				@require_torch
				def 					UpperCAmelCase_		(			self     ):
									__A	:						Tuple       =				'anton-l/wav2vec2-random-tiny-classifier'

									__A	:						List[str]       =				pipeline('audio-classification'     ,					model=_A     )

									__A	:						Dict       =				np.ones((8000,)     )
									__A	:						int       =				audio_classifier(_A     ,					top_k=4     )

									__A	:						List[str]       =				[
									    {'score': 0.0_8_4_2, 'label': 'no'},
									    {'score': 0.0_8_3_8, 'label': 'up'},
									    {'score': 0.0_8_3_7, 'label': 'go'},
									    {'score': 0.0_8_3_4, 'label': 'right'},
									]
									__A	:						List[str]       =				[
									    {'score': 0.0_8_4_5, 'label': 'stop'},
									    {'score': 0.0_8_4_4, 'label': 'on'},
									    {'score': 0.0_8_4_1, 'label': 'right'},
									    {'score': 0.0_8_3_4, 'label': 'left'},
									]
									self.assertIn(nested_simplify(_A     ,					decimals=4     )     ,					[EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]     )

									__A	:						Tuple       =				{'array': np.ones((8000,)     ), 'sampling_rate': audio_classifier.feature_extractor.sampling_rate}
									__A	:						List[str]       =				audio_classifier(_A     ,					top_k=4     )
									self.assertIn(nested_simplify(_A     ,					decimals=4     )     ,					[EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]     )



				@require_torch
				@slow
				def 					UpperCAmelCase_		(			self     ):
									import datasets

									__A	:						Union[str, Any]       =				'superb/wav2vec2-base-superb-ks'

									__A	:						Any       =				pipeline('audio-classification'     ,					model=_A     )
									__A	:						Tuple       =				datasets.load_dataset('anton-l/superb_dummy'     ,					'ks'     ,					split='test'     )

									__A	:						Any       =				np.array(dataset[3]['speech']     ,					dtype=np.floataa     )
									__A	:						Optional[int]       =				audio_classifier(_A     ,					top_k=4     )
									self.assertEqual(
									    nested_simplify(_A     ,					decimals=3     )     ,					[
									        {'score': 0.9_8_1, 'label': 'go'},
									        {'score': 0.0_0_7, 'label': 'up'},
									        {'score': 0.0_0_6, 'label': '_unknown_'},
									        {'score': 0.0_0_1, 'label': 'down'},
									    ]     ,					)





				@require_tf
				@unittest.skip('Audio classification is not implemented for TF'     )
				def 					UpperCAmelCase_		(			self     ):
									pass











from __future__ import annotations







def  _SCREAMING_SNAKE_CASE				(   a					,						a					,						a  )      ->      float:
					if days_between_payments <= 0:
										raise ValueError('days_between_payments must be > 0'  )
					if daily_interest_rate < 0:
										raise ValueError('daily_interest_rate must be >= 0'  )
					if principal <= 0:
										raise ValueError('principal must be > 0'  )
					return principal * daily_interest_rate * days_between_payments







def  _SCREAMING_SNAKE_CASE				(   a					,						a					,						a					,						)      ->      float:
					if number_of_compounding_periods <= 0:
										raise ValueError('number_of_compounding_periods must be > 0'  )
					if nominal_annual_interest_rate_percentage < 0:
										raise ValueError('nominal_annual_interest_rate_percentage must be >= 0'  )
					if principal <= 0:
										raise ValueError('principal must be > 0'  )

					return principal * (
					    (1 + nominal_annual_interest_rate_percentage) ** number_of_compounding_periods
					    - 1
					)







def  _SCREAMING_SNAKE_CASE				(   a					,						a					,						a					,						)      ->      float:
					if number_of_years <= 0:
										raise ValueError('number_of_years must be > 0'  )
					if nominal_annual_percentage_rate < 0:
										raise ValueError('nominal_annual_percentage_rate must be >= 0'  )
					if principal <= 0:
										raise ValueError('principal must be > 0'  )

					return compound_interest(
					    a					,						nominal_annual_percentage_rate / 3_65					,						number_of_years * 3_65  )


if __name__ == "__main__":
				import doctest

				doctest.testmod()




