


'''simple docstring'''
import unittest

from transformers import is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
 from PIL import Image
else:

 class 						_lowerCamelCase					:




  '''simple docstring'''

  @staticmethod
  def  snake_case__   (      *__lowercase      ,      **__lowercase						):

   """simple docstring"""







   pass

@is_pipeline_test
@require_vision
class 						_lowerCamelCase					(    unittest.TestCase				):




 '''simple docstring'''

 @require_torch
 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		Dict       =			pipeline(
      model='hf-internal-testing/tiny-random-clip-zero-shot-image-classification'      ,      )
  __A  :		Optional[Any]       =			Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
  __A  :		Tuple       =			image_classifier(A_      ,      candidate_labels=['a', 'b', 'c']						)

  # The floating scores are so close, we enter floating error approximation and the order is not guaranteed across
  # python and torch versions.
  self.assertIn(
      nested_simplify(A_						)      ,      [
          [{'score': 0.3_3_3, 'label': 'a'}, {'score': 0.3_3_3, 'label': 'b'}, {'score': 0.3_3_3, 'label': 'c'}],
          [{'score': 0.3_3_3, 'label': 'a'}, {'score': 0.3_3_3, 'label': 'c'}, {'score': 0.3_3_3, 'label': 'b'}],
      ]      ,      )

  __A  :		int       =			image_classifier([image] * 5      ,      candidate_labels=['A', 'B', 'C']      ,      batch_size=2						)
  self.assertEqual(
      nested_simplify(A_						)      ,      [
          [
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
          ],
          [
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
          ],
          [
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
          ],
          [
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
          ],
          [
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
          ],
      ]      ,      )

 @require_tf
 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		List[str]       =			pipeline(
      model='hf-internal-testing/tiny-random-clip-zero-shot-image-classification'      ,      framework='tf'						)
  __A  :		Tuple       =			Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
  __A  :		List[Any]       =			image_classifier(A_      ,      candidate_labels=['a', 'b', 'c']						)

  self.assertEqual(
      nested_simplify(A_						)      ,      [{'score': 0.3_3_3, 'label': 'a'}, {'score': 0.3_3_3, 'label': 'b'}, {'score': 0.3_3_3, 'label': 'c'}]      ,      )

  __A  :		Optional[Any]       =			image_classifier([image] * 5      ,      candidate_labels=['A', 'B', 'C']      ,      batch_size=2						)
  self.assertEqual(
      nested_simplify(A_						)      ,      [
          [
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
          ],
          [
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
          ],
          [
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
          ],
          [
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
          ],
          [
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
              {'score': 0.3_3_3, 'label': ANY(A_						)},
          ],
      ]      ,      )

 @slow
 @require_torch
 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		List[Any]       =			pipeline(
      task='zero-shot-image-classification'      ,      model='openai/clip-vit-base-patch32'      ,      )
  # This is an image of 2 cats with remotes and no planes
  __A  :		Any       =			Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
  __A  :		List[str]       =			image_classifier(A_      ,      candidate_labels=['cat', 'plane', 'remote']						)

  self.assertEqual(
      nested_simplify(A_						)      ,      [
          {'score': 0.5_1_1, 'label': 'remote'},
          {'score': 0.4_8_5, 'label': 'cat'},
          {'score': 0.0_0_4, 'label': 'plane'},
      ]      ,      )

  __A  :		Dict       =			image_classifier([image] * 5      ,      candidate_labels=['cat', 'plane', 'remote']      ,      batch_size=2						)
  self.assertEqual(
      nested_simplify(A_						)      ,      [
          [
              {'score': 0.5_1_1, 'label': 'remote'},
              {'score': 0.4_8_5, 'label': 'cat'},
              {'score': 0.0_0_4, 'label': 'plane'},
          ],
      ]
      * 5      ,      )







 @slow
 @require_tf
 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		Optional[int]       =			pipeline(
      task='zero-shot-image-classification'      ,      model='openai/clip-vit-base-patch32'      ,      framework='tf'						)
  # This is an image of 2 cats with remotes and no planes
  __A  :		Optional[Any]       =			Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
  __A  :		int       =			image_classifier(A_      ,      candidate_labels=['cat', 'plane', 'remote']						)
  self.assertEqual(
      nested_simplify(A_						)      ,      [
          {'score': 0.5_1_1, 'label': 'remote'},
          {'score': 0.4_8_5, 'label': 'cat'},
          {'score': 0.0_0_4, 'label': 'plane'},
      ]      ,      )

  __A  :		Dict       =			image_classifier([image] * 5      ,      candidate_labels=['cat', 'plane', 'remote']      ,      batch_size=2						)
  self.assertEqual(
      nested_simplify(A_						)      ,      [
          [
              {'score': 0.5_1_1, 'label': 'remote'},
              {'score': 0.4_8_5, 'label': 'cat'},
              {'score': 0.0_0_4, 'label': 'plane'},
          ],
      ]
      * 5      ,      )










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




 '''simple docstring'''


 @require_torch
 def  snake_case__   (      self						):

  """simple docstring"""







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

  """simple docstring"""







  pass


 @slow
 @require_torch
 def  snake_case__   (      self						):

  """simple docstring"""







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

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

  __A  :		Any       =			audio_classifier([audio] * 5      ,      candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']						)
  self.assertEqual(
      nested_simplify(__lowercase						)      ,      [
          [
              {'score': 0.9_9_9, 'label': 'Sound of a dog'},
              {'score': 0.0_0_1, 'label': 'Sound of vaccum cleaner'},
          ],
      ]
      * 5      ,      )
  __A  :		str       =			audio_classifier(
      [audio] * 5      ,      candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']      ,      batch_size=5						)
  self.assertEqual(
      nested_simplify(__lowercase						)      ,      [
          [
              {'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  snake_case__   (      self						):

  """simple docstring"""







  pass






