

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



 """simple docstring"""



 lowerCAmelCase__       = MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
 lowerCAmelCase__       = TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
 def  UpperCAmelCase__						(						self   :			List[Any]   ,				__SCREAMING_SNAKE_CASE   :			Optional[int]   ,				__SCREAMING_SNAKE_CASE   :			Optional[int]   ,				__SCREAMING_SNAKE_CASE   :			Tuple     )    ->					List[Any]:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = AudioClassificationPipeline(model=__SCREAMING_SNAKE_CASE   ,				feature_extractor=__SCREAMING_SNAKE_CASE     )

      # test with a raw waveform
      __SCREAMING_SNAKE_CASE      = np.zeros((34_000,)     )
      __SCREAMING_SNAKE_CASE      = np.zeros((14_000,)     )
      return audio_classifier, [audioa, audio]
 def  UpperCAmelCase__						(						self   :			str   ,				__SCREAMING_SNAKE_CASE   :			List[str]   ,				__SCREAMING_SNAKE_CASE   :			Tuple     )    ->					Any:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE  ,     __SCREAMING_SNAKE_CASE      = examples
      __SCREAMING_SNAKE_CASE      = 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     )},
          ]   ,				)
      __SCREAMING_SNAKE_CASE      = 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  UpperCAmelCase__						(						self   :			Any   ,				__SCREAMING_SNAKE_CASE   :			Tuple     )    ->					Optional[Any]:


      """simple docstring"""




      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(__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  UpperCAmelCase__						(						self   :			str     )    ->					str:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = """anton-l/wav2vec2-random-tiny-classifier"""

      __SCREAMING_SNAKE_CASE      = pipeline("""audio-classification"""   ,				model=__SCREAMING_SNAKE_CASE     )

      __SCREAMING_SNAKE_CASE      = np.ones((8_000,)     )
      __SCREAMING_SNAKE_CASE      = audio_classifier(__SCREAMING_SNAKE_CASE   ,				top_k=4     )

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

      __SCREAMING_SNAKE_CASE      = {"""array""": np.ones((8_000,)     ), """sampling_rate""": audio_classifier.feature_extractor.sampling_rate}
      __SCREAMING_SNAKE_CASE      = 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  UpperCAmelCase__						(						self   :			List[str]     )    ->					Optional[Any]:


      """simple docstring"""




      import datasets

      __SCREAMING_SNAKE_CASE      = """superb/wav2vec2-base-superb-ks"""

      __SCREAMING_SNAKE_CASE      = pipeline("""audio-classification"""   ,				model=__SCREAMING_SNAKE_CASE     )
      __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(__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  UpperCAmelCase__						(						self   :			Optional[int]     )    ->					str:


      """simple docstring"""




      pass









'''simple docstring'''



from math import isqrt







def   a__			(    a__		):




     """simple docstring"""


     return all(number % divisor != 0 for divisor in range(2 ,       isqrt(a__		) + 1		)		)







def   a__			(    a__ = 10**6		):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE      = 0
     __SCREAMING_SNAKE_CASE      = 1
     __SCREAMING_SNAKE_CASE      = 7
     while prime_candidate < max_prime:
          primes_count += is_prime(a__		)

          cube_index += 1
          prime_candidate += 6 * cube_index

     return primes_count


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






