





'''simple docstring'''

import unittest

from datasets import load_dataset

from transformers.pipelines import pipeline
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_torch, slow







@is_pipeline_test
@require_torch
class __a			( unittest.TestCase      ):





   @require_torch
   def   UpperCAmelCase__  (       self					:      List[str]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							pipeline(
          task="""zero-shot-audio-classification"""					,model="""hf-internal-testing/tiny-clap-htsat-unfused"""     )
      __SCREAMING_SNAKE_CASE   				=							load_dataset("""ashraq/esc50"""     )
      __SCREAMING_SNAKE_CASE   				=							dataset["""train"""]["""audio"""][-1]["""array"""]
      __SCREAMING_SNAKE_CASE   				=							audio_classifier(lowerCamelCase					,candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""]     )
      self.assertEqual(
          nested_simplify(lowerCamelCase     )					,[{"""score""": 0.501, """label""": """Sound of a dog"""}, {"""score""": 0.499, """label""": """Sound of vaccum cleaner"""}]					,)





   @unittest.skip("""No models are available in TF"""     )
   def   UpperCAmelCase__  (       self					:      List[Any]     ):

      '''simple docstring'''

      pass





   @slow
   @require_torch
   def   UpperCAmelCase__  (       self					:      Tuple     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							pipeline(
          task="""zero-shot-audio-classification"""					,model="""laion/clap-htsat-unfused"""					,)
      # This is an audio of a dog
      __SCREAMING_SNAKE_CASE   				=							load_dataset("""ashraq/esc50"""     )
      __SCREAMING_SNAKE_CASE   				=							dataset["""train"""]["""audio"""][-1]["""array"""]
      __SCREAMING_SNAKE_CASE   				=							audio_classifier(lowerCamelCase					,candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""]     )

      self.assertEqual(
          nested_simplify(lowerCamelCase     )					,[
              {"""score""": 0.999, """label""": """Sound of a dog"""},
              {"""score""": 0.001, """label""": """Sound of vaccum cleaner"""},
          ]					,)

      __SCREAMING_SNAKE_CASE   				=							audio_classifier([audio] * 5					,candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""]     )
      self.assertEqual(
          nested_simplify(lowerCamelCase     )					,[
              [
                  {"""score""": 0.999, """label""": """Sound of a dog"""},
                  {"""score""": 0.001, """label""": """Sound of vaccum cleaner"""},
              ],
          ]
          * 5					,)
      __SCREAMING_SNAKE_CASE   				=							audio_classifier(
          [audio] * 5					,candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""]					,batch_size=5     )
      self.assertEqual(
          nested_simplify(lowerCamelCase     )					,[
              [
                  {"""score""": 0.999, """label""": """Sound of a dog"""},
                  {"""score""": 0.001, """label""": """Sound of vaccum cleaner"""},
              ],
          ]
          * 5					,)





   @unittest.skip("""No models are available in TF"""     )
   def   UpperCAmelCase__  (       self					:      Dict     ):

      '''simple docstring'''

      pass








'''simple docstring'''







import pytest

import datasets.config
from datasets.utils.info_utils import is_small_dataset
@pytest.mark.parametrize("""dataset_size""",							[None, 4_00 * 2**20, 6_00 * 2**20]					)
@pytest.mark.parametrize("""input_in_memory_max_size""",							["""default""", 0, 1_00 * 2**20, 9_00 * 2**20]					)
def    UpperCAmelCase__     (   UpperCAmelCase__,							UpperCAmelCase__,							UpperCAmelCase__					)      ->      Dict:
       if input_in_memory_max_size != "default":
              monkeypatch.setattr(datasets.config,							"""IN_MEMORY_MAX_SIZE""",							UpperCAmelCase__					)
       A_						       =   datasets.config.IN_MEMORY_MAX_SIZE
       if input_in_memory_max_size == "default":
              assert in_memory_max_size == 0
       else:
              assert in_memory_max_size == input_in_memory_max_size
       if dataset_size and in_memory_max_size:
              A_						       =   dataset_size < in_memory_max_size
       else:
              A_						       =   False
       A_						       =   is_small_dataset(UpperCAmelCase__					)
       assert result == expected
