






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




      """simple docstring"""




      @require_torch
      def 				A__      ( self			:		str		)  ->  Optional[int]:


       '''simple docstring'''

       lowercase					:   Optional[int]				  =pipeline(
           task='''zero-shot-audio-classification'''     ,      model='''hf-internal-testing/tiny-clap-htsat-unfused'''		)
       lowercase					:   Optional[int]				  =load_dataset('''ashraq/esc50'''		)
       lowercase					:   int				  =dataset['''train''']['''audio'''][-1]['''array''']
       lowercase					:   Union[str, Any]				  =audio_classifier(UpperCAmelCase     ,      candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']		)
       self.assertEqual(
           nested_simplify(UpperCAmelCase		)     ,      [{'''score''': 0.5_0_1, '''label''': '''Sound of a dog'''}, {'''score''': 0.4_9_9, '''label''': '''Sound of vaccum cleaner'''}]     ,      )






      @unittest.skip('''No models are available in TF'''		)
      def 				A__      ( self			:		Tuple		)  ->  Any:


       '''simple docstring'''

       pass






      @slow
      @require_torch
      def 				A__      ( self			:		int		)  ->  Any:


       '''simple docstring'''

       lowercase					:   str				  =pipeline(
           task='''zero-shot-audio-classification'''     ,      model='''laion/clap-htsat-unfused'''     ,      )
       # This is an audio of a dog
       lowercase					:   Tuple				  =load_dataset('''ashraq/esc50'''		)
       lowercase					:   int				  =dataset['''train''']['''audio'''][-1]['''array''']
       lowercase					:   Optional[Any]				  =audio_classifier(UpperCAmelCase     ,      candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']		)

       self.assertEqual(
           nested_simplify(UpperCAmelCase		)     ,      [
               {'''score''': 0.9_9_9, '''label''': '''Sound of a dog'''},
               {'''score''': 0.0_0_1, '''label''': '''Sound of vaccum cleaner'''},
           ]     ,      )

       lowercase					:   Union[str, Any]				  =audio_classifier([audio] * 5     ,      candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']		)
       self.assertEqual(
           nested_simplify(UpperCAmelCase		)     ,      [
               [
                   {'''score''': 0.9_9_9, '''label''': '''Sound of a dog'''},
                   {'''score''': 0.0_0_1, '''label''': '''Sound of vaccum cleaner'''},
               ],
           ]
           * 5     ,      )
       lowercase					:   Union[str, Any]				  =audio_classifier(
           [audio] * 5     ,      candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']     ,      batch_size=5		)
       self.assertEqual(
           nested_simplify(UpperCAmelCase		)     ,      [
               [
                   {'''score''': 0.9_9_9, '''label''': '''Sound of a dog'''},
                   {'''score''': 0.0_0_1, '''label''': '''Sound of vaccum cleaner'''},
               ],
           ]
           * 5     ,      )






      @unittest.skip('''No models are available in TF'''		)
      def 				A__      ( self			:		Dict		)  ->  Any:


       '''simple docstring'''

       pass











'''simple docstring'''



import importlib.metadata
from typing import Union

from packaging.version import Version, parse

from .constants import STR_OPERATION_TO_FUNC


SCREAMING_SNAKE_CASE						=	parse(importlib.metadata.version('torch'))


def 							lowercase_				(    __A :       Union[str, Version]					,      __A :       str					,      __A :       str			)       ->      Union[str, Any]:



 """simple docstring"""




 if operation not in STR_OPERATION_TO_FUNC.keys():
  raise ValueError(F'`operation` must be one of {list(STR_OPERATION_TO_FUNC.keys()			)}, received {operation}'			)
 lowercase					:   Any				  =STR_OPERATION_TO_FUNC[operation]
 if isinstance(__A					,      __A			):
  lowercase					:   List[Any]				  =parse(importlib.metadata.version(__A			)			)
 return operation(__A					,      parse(__A			)			)





def 							lowercase_				(    __A :       str					,      __A :       str			)       ->      Tuple:



 """simple docstring"""




 return compare_versions(__A					,      __A					,      __A			)



