

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				):
  _a		     =    MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
  _a		     =    TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING




  def     A__	(							self				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase   )    ->					List[Any]:
        '''simple docstring'''






        _lowercase      			=AudioClassificationPipeline(model=lowerCAmelCase				,  feature_extractor=lowerCAmelCase   )

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




  def     A__	(							self				,  lowerCAmelCase				,  lowerCAmelCase   )    ->					Union[str, Any]:
        '''simple docstring'''






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

        self.run_torchaudio(lowerCAmelCase   )




  @require_torchaudio
  def     A__	(							self				,  lowerCAmelCase   )    ->					List[str]:
        '''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(lowerCAmelCase   )
        self.assertEqual(
            lowerCAmelCase				,  [
                {'score': ANY(lowerCAmelCase   ), 'label': ANY(lowerCAmelCase   )},
                {'score': ANY(lowerCAmelCase   ), 'label': ANY(lowerCAmelCase   )},
            ]				,  )




  @require_torch
  def     A__	(							self   )    ->					Dict:
        '''simple docstring'''






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

        _lowercase      			=pipeline('audio-classification'				,  model=lowerCAmelCase   )

        _lowercase      			=np.ones((8_000,)   )
        _lowercase      			=audio_classifier(lowerCAmelCase				,  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(lowerCAmelCase				,  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(lowerCAmelCase				,  top_k=4   )
        self.assertIn(nested_simplify(lowerCAmelCase				,  decimals=4   )				,  [EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]   )




  @require_torch
  @slow
  def     A__	(							self   )    ->					Dict:
        '''simple docstring'''






        import datasets

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

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

        _lowercase      			=np.array(dataset[3]['speech']				,  dtype=np.floataa   )
        _lowercase      			=audio_classifier(lowerCAmelCase				,  top_k=4   )
        self.assertEqual(
            nested_simplify(lowerCAmelCase				,  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     A__	(							self   )    ->					Dict:
        '''simple docstring'''






        pass





def 	a (     A__      :  int	)       -> bool:





      """simple docstring"""



      return sum(i for i in range(1 ,  number // 2 + 1	) if number % i == 0	) == number


if __name__ == "__main__":
  print('Program to check whether a number is a Perfect number or not...')
  lowercase_   							=  int(input('Enter number: ').strip())
  print(f"{number} is {'' if perfect(number) else 'not '}a Perfect Number.")


