





'''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 	lowercase__     (   self					:   int			)					->    List[str]:


					"""simple docstring"""

					__snake_case					:      Any							      =     pipeline(
					    task="""zero-shot-audio-classification"""  ,      model="""hf-internal-testing/tiny-clap-htsat-unfused"""			)
					__snake_case					:      Optional[Any]							      =     load_dataset("""ashraq/esc50"""			)
					__snake_case					:      Dict							      =     dataset["""train"""]["""audio"""][-1]["""array"""]
					__snake_case					:      str							      =     audio_classifier(__magic_name__  ,      candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""]			)
					self.assertEqual(
					    nested_simplify(__magic_name__			)  ,      [{"""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 	lowercase__     (   self					:   Union[str, Any]			)					->    str:


					"""simple docstring"""

					pass

		@slow
		@require_torch
		def 	lowercase__     (   self					:   Dict			)					->    Tuple:


					"""simple docstring"""

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

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

					__snake_case					:      Any							      =     audio_classifier([audio] * 5  ,      candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""]			)
					self.assertEqual(
					    nested_simplify(__magic_name__			)  ,      [
					        [
					            {"""score""": 0.999, """label""": """Sound of a dog"""},
					            {"""score""": 0.001, """label""": """Sound of vaccum cleaner"""},
					        ],
					    ]
					    * 5  ,      )
					__snake_case					:      Optional[int]							      =     audio_classifier(
					    [audio] * 5  ,      candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""]  ,      batch_size=5			)
					self.assertEqual(
					    nested_simplify(__magic_name__			)  ,      [
					        [
					            {"""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 	lowercase__     (   self					:   List[str]			)					->    Optional[Any]:


					"""simple docstring"""

					pass









'''simple docstring'''






from unittest import TestCase

from datasets import Sequence, Value
from datasets.arrow_dataset import Dataset




class  _A (					__lowercase		):

		def 	lowercase__     (   self					:   Any			)					->    str:


					"""simple docstring"""

					return [
					    {"col_1": 3, "col_2": "a"},
					    {"col_1": 2, "col_2": "b"},
					    {"col_1": 1, "col_2": "c"},
					    {"col_1": 0, "col_2": "d"},
					]

		def 	lowercase__     (   self					:   str			)					->    int:


					"""simple docstring"""

					__snake_case					:      Union[str, Any]							      =     {"""col_1""": [3, 2, 1, 0], """col_2""": ["""a""", """b""", """c""", """d"""]}
					return Dataset.from_dict(__magic_name__			)

		def 	lowercase__     (   self					:   str			)					->    List[Any]:


					"""simple docstring"""

					__snake_case					:      Any							      =     self._create_example_records()
					__snake_case					:      str							      =     Dataset.from_list(__magic_name__			)
					self.assertListEqual(dset.column_names  ,      ["""col_1""", """col_2"""]			)
					for i, r in enumerate(__magic_name__			):
								self.assertDictEqual(__magic_name__  ,      example_records[i]			)

		def 	lowercase__     (   self					:   Optional[Any]			)					->    List[Any]:


					"""simple docstring"""

					__snake_case					:      List[Any]							      =     self._create_example_records()
					__snake_case					:      Dict							      =     Dataset.from_list(__magic_name__			)
					__snake_case					:      List[Any]							      =     Dataset.from_dict({k: [r[k] for r in example_records] for k in example_records[0]}			)
					self.assertEqual(dset.info  ,      dset_from_dict.info			)

		def 	lowercase__     (   self					:   str			)					->    List[Any]:  # checks what happens with missing columns


					"""simple docstring"""

					__snake_case					:      Union[str, Any]							      =     [{"""col_1""": 1}, {"""col_2""": """x"""}]
					__snake_case					:      Optional[int]							      =     Dataset.from_list(__magic_name__			)
					self.assertDictEqual(dset[0]  ,      {"""col_1""": 1}			)
					self.assertDictEqual(dset[1]  ,      {"""col_1""": None}			)  # NB: first record is used for columns

		def 	lowercase__     (   self					:   List[str]			)					->    Optional[Any]:  # checks if the type can be inferred from the second record


					"""simple docstring"""

					__snake_case					:      List[Any]							      =     [{"""col_1""": []}, {"""col_1""": [1, 2]}]
					__snake_case					:      int							      =     Dataset.from_list(__magic_name__			)
					self.assertEqual(dset.info.features["""col_1"""]  ,      Sequence(Value("""int64"""			)			)			)

		def 	lowercase__     (   self					:   int			)					->    Union[str, Any]:


					"""simple docstring"""

					__snake_case					:      Tuple							      =     Dataset.from_list([]			)
					self.assertEqual(len(__magic_name__			)  ,      0			)
					self.assertListEqual(dset.column_names  ,      []			)


