

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       __snake_case  (    unittest.TestCase       ):
  __lowerCAmelCase     :	Optional[int]						 =  MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
  __lowerCAmelCase     :	List[Any]						 =  TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING

  def 						lowerCAmelCase__     (					self						,		_A						,		_A						,		_A):
      SCREAMING_SNAKE_CASE_									=						AudioClassificationPipeline(model=_A						,		feature_extractor=_A)

      # test with a raw waveform
      SCREAMING_SNAKE_CASE_									=						np.zeros((34000,))
      SCREAMING_SNAKE_CASE_									=						np.zeros((14000,))
      return audio_classifier, [audioa, audio]

  def 						lowerCAmelCase__     (					self						,		_A						,		_A):
      SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_									=						examples
      SCREAMING_SNAKE_CASE_									=						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)},
          ]						,		)
      SCREAMING_SNAKE_CASE_									=						audio_classifier(_A						,		top_k=1)
      self.assertEqual(
          _A						,		[
              {'score': ANY(_A), 'label': ANY(_A)},
          ]						,		)

      self.run_torchaudio(_A)

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

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

  @require_torch
  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						'anton-l/wav2vec2-random-tiny-classifier'

      SCREAMING_SNAKE_CASE_									=						pipeline('audio-classification'						,		model=_A)

      SCREAMING_SNAKE_CASE_									=						np.ones((8000,))
      SCREAMING_SNAKE_CASE_									=						audio_classifier(_A						,		top_k=4)

      SCREAMING_SNAKE_CASE_									=						[
          {'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'},
      ]
      SCREAMING_SNAKE_CASE_									=						[
          {'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])

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

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

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

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

      SCREAMING_SNAKE_CASE_									=						np.array(dataset[3]['speech']						,		dtype=np.floataa)
      SCREAMING_SNAKE_CASE_									=						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 						lowerCAmelCase__     (					self):
      pass





def 					_UpperCAmelCase       (  _SCREAMING_SNAKE_CASE					:		int = 200       ):





    """simple docstring"""


    SCREAMING_SNAKE_CASE_									=						[1, 2, 5, 10, 20, 50, 100, 200]
    SCREAMING_SNAKE_CASE_									=						[0] * (pence + 1)
    SCREAMING_SNAKE_CASE_									=						1  # base case: 1 way to make 0 pence

    for coin in coins:
        for i in range(_SCREAMING_SNAKE_CASE ,   pence + 1 ,   1       ):
            number_of_ways[i] += number_of_ways[i - coin]
    return number_of_ways[pence]


if __name__ == "__main__":
       assert solution(200) == 73_682


