





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     __magic_name__     (							unittest.TestCase							):





     """simple docstring"""



     __UpperCamelCase    			=   MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
     __UpperCamelCase    			=   TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING



     def   SCREAMING_SNAKE_CASE						(							self				:Tuple	,					snake_case				:Dict	,					snake_case				:Union[str, Any]	,					snake_case				:str     ):





        '''simple docstring'''




        A_    : Union[str, Any]								=	AudioClassificationPipeline(model=_A	,					feature_extractor=_A     )

        # test with a raw waveform
        A_    : Any								=	np.zeros((34_000,)     )
        A_    : Optional[int]								=	np.zeros((14_000,)     )
        return audio_classifier, [audioa, audio]



     def   SCREAMING_SNAKE_CASE						(							self				:List[Any]	,					snake_case				:List[Any]	,					snake_case				:Union[str, Any]     ):





        '''simple docstring'''




        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   SCREAMING_SNAKE_CASE						(							self				:List[Any]	,					snake_case				:Any     ):





        '''simple docstring'''




        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   SCREAMING_SNAKE_CASE						(							self				:Tuple     ):





        '''simple docstring'''




        A_    : Tuple								=	'anton-l/wav2vec2-random-tiny-classifier'

        A_    : List[str]								=	pipeline("audio-classification"	,					model=_A     )

        A_    : Dict								=	np.ones((8_000,)     )
        A_    : int								=	audio_classifier(_A	,					top_k=4     )

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

        A_    : Tuple								=	{'array': np.ones((8_000,)     ), '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   SCREAMING_SNAKE_CASE						(							self				:Optional[Any]     ):





        '''simple docstring'''




        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.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   SCREAMING_SNAKE_CASE						(							self				:Any     ):





        '''simple docstring'''




        pass







def  _SCREAMING_SNAKE_CASE				(   a  )      ->      bool:
					return str(a  ) == str(a  )[::-1]







def  _SCREAMING_SNAKE_CASE				(   a  )      ->      int:
					return int(a  ) + int(str(a  )[::-1]  )







def  _SCREAMING_SNAKE_CASE				(   a = 1_00_00  )      ->      int:
					__A	:						int       =				[]
					for num in range(1					,						a  ):
										__A	:						List[str]       =				0
										__A	:						List[Any]       =				num
										while iterations < 50:
															__A	:						str       =				sum_reverse(a  )
															iterations += 1
															if is_palindrome(a  ):
																				break
										else:
															lychrel_nums.append(a  )
					return len(a  )


if __name__ == "__main__":
				print(F"""{solution() = }""")




