
'''simple docstring'''







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  lowerCAmelCase__   (  unittest.TestCase     ):
					lowerCAmelCase_        =     MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
					lowerCAmelCase_        =     TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING






					def 	_snake_case    (   self				,							__SCREAMING_SNAKE_CASE				,							__SCREAMING_SNAKE_CASE				,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											lowercase_	:     str													=       AudioClassificationPipeline(model=__SCREAMING_SNAKE_CASE				,							feature_extractor=__SCREAMING_SNAKE_CASE		)

											# test with a raw waveform
											lowercase_	:     Tuple													=       np.zeros((3_40_00,)		)
											lowercase_	:     str													=       np.zeros((1_40_00,)		)
											return audio_classifier, [audioa, audio]






					def 	_snake_case    (   self				,							__SCREAMING_SNAKE_CASE				,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											lowercase_						, lowercase_	:     List[str]													=       examples
											lowercase_	:     Tuple													=       audio_classifier(__SCREAMING_SNAKE_CASE		)
											# by default a model is initialized with num_labels=2
											self.assertEqual(
											    __SCREAMING_SNAKE_CASE				,							[
											        {'''score''': ANY(__SCREAMING_SNAKE_CASE		), '''label''': ANY(__SCREAMING_SNAKE_CASE		)},
											        {'''score''': ANY(__SCREAMING_SNAKE_CASE		), '''label''': ANY(__SCREAMING_SNAKE_CASE		)},
											    ]				,							)
											lowercase_	:     int													=       audio_classifier(__SCREAMING_SNAKE_CASE				,							top_k=1		)
											self.assertEqual(
											    __SCREAMING_SNAKE_CASE				,							[
											        {'''score''': ANY(__SCREAMING_SNAKE_CASE		), '''label''': ANY(__SCREAMING_SNAKE_CASE		)},
											    ]				,							)

											self.run_torchaudio(__SCREAMING_SNAKE_CASE		)






					@require_torchaudio
					def 	_snake_case    (   self				,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											import datasets

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






					@require_torch
					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     str													=       '''anton-l/wav2vec2-random-tiny-classifier'''

											lowercase_	:     str													=       pipeline('''audio-classification'''				,							model=__SCREAMING_SNAKE_CASE		)

											lowercase_	:     Union[str, Any]													=       np.ones((80_00,)		)
											lowercase_	:     List[Any]													=       audio_classifier(__SCREAMING_SNAKE_CASE				,							top_k=4		)

											lowercase_	:     Dict													=       [
											    {'''score''': 0.0_842, '''label''': '''no'''},
											    {'''score''': 0.0_838, '''label''': '''up'''},
											    {'''score''': 0.0_837, '''label''': '''go'''},
											    {'''score''': 0.0_834, '''label''': '''right'''},
											]
											lowercase_	:     Optional[int]													=       [
											    {'''score''': 0.0_845, '''label''': '''stop'''},
											    {'''score''': 0.0_844, '''label''': '''on'''},
											    {'''score''': 0.0_841, '''label''': '''right'''},
											    {'''score''': 0.0_834, '''label''': '''left'''},
											]
											self.assertIn(nested_simplify(__SCREAMING_SNAKE_CASE				,							decimals=4		)				,							[EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]		)

											lowercase_	:     List[str]													=       {'''array''': np.ones((80_00,)		), '''sampling_rate''': audio_classifier.feature_extractor.sampling_rate}
											lowercase_	:     Dict													=       audio_classifier(__SCREAMING_SNAKE_CASE				,							top_k=4		)
											self.assertIn(nested_simplify(__SCREAMING_SNAKE_CASE				,							decimals=4		)				,							[EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]		)






					@require_torch
					@slow
					def 	_snake_case    (   self		):


											"""simple docstring"""





											import datasets

											lowercase_	:     Any													=       '''superb/wav2vec2-base-superb-ks'''

											lowercase_	:     Optional[Any]													=       pipeline('''audio-classification'''				,							model=__SCREAMING_SNAKE_CASE		)
											lowercase_	:     Optional[Any]													=       datasets.load_dataset('''anton-l/superb_dummy'''				,							'''ks'''				,							split='''test'''		)

											lowercase_	:     int													=       np.array(dataset[3]['''speech''']				,							dtype=np.floataa		)
											lowercase_	:     Optional[Any]													=       audio_classifier(__SCREAMING_SNAKE_CASE				,							top_k=4		)
											self.assertEqual(
											    nested_simplify(__SCREAMING_SNAKE_CASE				,							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 	_snake_case    (   self		):


											"""simple docstring"""





											pass





'''simple docstring'''







_lowercase :  int    							=       [sum(int(c, 1_0) ** 2 for c in i.__str__()) for i in range(1_0_0_0_0_0)]
def 					snake_case_		(				__SCREAMING_SNAKE_CASE					: int							):



						"""simple docstring"""





						lowercase_	:     Optional[int]													=       0
						while number:
												# Increased Speed Slightly by checking every 5 digits together.
												sum_of_digits_squared += DIGITS_SQUARED[number % 100000]
												number //= 100000

						return sum_of_digits_squared


# There are 2 Chains made,
# One ends with 89 with the chain member 58 being the one which when declared first,
# there will be the least number of iterations for all the members to be checked.

# The other one ends with 1 and has only one element 1.

# So 58 and 1 are chosen to be declared at the starting.

# Changed dictionary to an array to quicken the solution
_lowercase :  list[bool | None]    							=       [None] * 1_0_0_0_0_0_0_0
_lowercase :  List[str]    							=       True
_lowercase :  Optional[int]    							=       False
def 					snake_case_		(				__SCREAMING_SNAKE_CASE					: int							):



						"""simple docstring"""





						if CHAINS[number - 1] is not None:
												return CHAINS[number - 1]  # type: ignore

						lowercase_	:     Tuple													=       chain(next_number(__SCREAMING_SNAKE_CASE							)							)
						lowercase_	:     Union[str, Any]													=       number_chain

						while number < 10000000:
												lowercase_	:     int													=       number_chain
												number *= 10

						return number_chain
def 					snake_case_		(				__SCREAMING_SNAKE_CASE					: int = 10000000							):



						"""simple docstring"""





						for i in range(1      ,      __SCREAMING_SNAKE_CASE							):
												if CHAINS[i] is None:
																		chain(i + 1							)

						return CHAINS[:number].count(__SCREAMING_SNAKE_CASE							)


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							print(f"""{solution() = }""")



