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


  '''simple docstring'''






  @staticmethod
  def a					(      *SCREAMING_SNAKE_CASE__   :	str      ,       **SCREAMING_SNAKE_CASE__   :	List[Any]							)  ->    Optional[Any]:
   pass







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


 '''simple docstring'''






 @require_torch
 def a					(      self   :	Optional[Any]							)  ->    int:
  __lowerCAmelCase											=						pipeline(
      model="""hf-internal-testing/tiny-random-clip-zero-shot-image-classification"""      ,       )
  __lowerCAmelCase											=						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""							)
  __lowerCAmelCase											=						image_classifier(SCREAMING_SNAKE_CASE__      ,       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(SCREAMING_SNAKE_CASE__							)      ,       [
          [{"""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"""}],
      ]      ,       )

  __lowerCAmelCase											=						image_classifier([image] * 5      ,       candidate_labels=["""A""", """B""", """C"""]      ,       batch_size=2							)
  self.assertEqual(
      nested_simplify(SCREAMING_SNAKE_CASE__							)      ,       [
          [
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
          ],
          [
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
          ],
          [
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
          ],
          [
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
          ],
          [
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
          ],
      ]      ,       )
 @require_tf
 def a					(      self   :	int							)  ->    int:
  __lowerCAmelCase											=						pipeline(
      model="""hf-internal-testing/tiny-random-clip-zero-shot-image-classification"""      ,       framework="""tf"""							)
  __lowerCAmelCase											=						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""							)
  __lowerCAmelCase											=						image_classifier(SCREAMING_SNAKE_CASE__      ,       candidate_labels=["""a""", """b""", """c"""]							)

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

  __lowerCAmelCase											=						image_classifier([image] * 5      ,       candidate_labels=["""A""", """B""", """C"""]      ,       batch_size=2							)
  self.assertEqual(
      nested_simplify(SCREAMING_SNAKE_CASE__							)      ,       [
          [
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
          ],
          [
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
          ],
          [
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
          ],
          [
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
          ],
          [
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
              {"""score""": 0.3_3_3, """label""": ANY(SCREAMING_SNAKE_CASE__							)},
          ],
      ]      ,       )
 @slow
 @require_torch
 def a					(      self   :	Any							)  ->    Union[str, Any]:
  __lowerCAmelCase											=						pipeline(
      task="""zero-shot-image-classification"""      ,       model="""openai/clip-vit-base-patch32"""      ,       )
  # This is an image of 2 cats with remotes and no planes
  __lowerCAmelCase											=						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""							)
  __lowerCAmelCase											=						image_classifier(SCREAMING_SNAKE_CASE__      ,       candidate_labels=["""cat""", """plane""", """remote"""]							)

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

  __lowerCAmelCase											=						image_classifier([image] * 5      ,       candidate_labels=["""cat""", """plane""", """remote"""]      ,       batch_size=2							)
  self.assertEqual(
      nested_simplify(SCREAMING_SNAKE_CASE__							)      ,       [
          [
              {"""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 a					(      self   :	Dict							)  ->    List[str]:
  __lowerCAmelCase											=						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
  __lowerCAmelCase											=						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""							)
  __lowerCAmelCase											=						image_classifier(SCREAMING_SNAKE_CASE__      ,       candidate_labels=["""cat""", """plane""", """remote"""]							)
  self.assertEqual(
      nested_simplify(SCREAMING_SNAKE_CASE__							)      ,       [
          {"""score""": 0.5_1_1, """label""": """remote"""},
          {"""score""": 0.4_8_5, """label""": """cat"""},
          {"""score""": 0.0_0_4, """label""": """plane"""},
      ]      ,       )

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







'''simple docstring'''

from abc import ABC, abstractmethod
from argparse import ArgumentParser







class 				_lowercase     (				UpperCAmelCase__			):


 '''simple docstring'''






 @staticmethod
 @abstractmethod
 def a					(      SCREAMING_SNAKE_CASE__   :	ArgumentParser							)  ->    Tuple:
  raise NotImplementedError()





 @abstractmethod
 def a					(      self   :	int							)  ->    Union[str, Any]:
  raise NotImplementedError()






