


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 							_UpperCamelCase :

       '''simple docstring'''







       @staticmethod
       def   _snake_case    (  *_lowerCamelCase  : int       ,  **_lowerCamelCase  : str							):






             '''simple docstring'''



             pass



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

   '''simple docstring'''







   @require_torch
   def   _snake_case    (  self  : List[Any]							):






         '''simple docstring'''



         __lowerCamelCase     :      str       						=						pipeline(
             model="""hf-internal-testing/tiny-random-clip-zero-shot-image-classification"""       ,  )
         __lowerCamelCase     :      int       						=						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""							)
         __lowerCamelCase     :      Optional[Any]       						=						image_classifier(_lowerCamelCase       ,  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(_lowerCamelCase							)       ,  [
                 [{"""score""": 0.333, """label""": """a"""}, {"""score""": 0.333, """label""": """b"""}, {"""score""": 0.333, """label""": """c"""}],
                 [{"""score""": 0.333, """label""": """a"""}, {"""score""": 0.333, """label""": """c"""}, {"""score""": 0.333, """label""": """b"""}],
             ]       ,  )

         __lowerCamelCase     :      str       						=						image_classifier([image] * 5       ,  candidate_labels=["""A""", """B""", """C"""]       ,  batch_size=2							)
         self.assertEqual(
             nested_simplify(_lowerCamelCase							)       ,  [
                 [
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                 ],
                 [
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                 ],
                 [
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                 ],
                 [
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                 ],
                 [
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                 ],
             ]       ,  )

   @require_tf
   def   _snake_case    (  self  : Any							):






         '''simple docstring'''



         __lowerCamelCase     :      Dict       						=						pipeline(
             model="""hf-internal-testing/tiny-random-clip-zero-shot-image-classification"""       ,  framework="""tf"""							)
         __lowerCamelCase     :      str       						=						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""							)
         __lowerCamelCase     :      Dict       						=						image_classifier(_lowerCamelCase       ,  candidate_labels=["""a""", """b""", """c"""]							)

         self.assertEqual(
             nested_simplify(_lowerCamelCase							)       ,  [{"""score""": 0.333, """label""": """a"""}, {"""score""": 0.333, """label""": """b"""}, {"""score""": 0.333, """label""": """c"""}]       ,  )

         __lowerCamelCase     :      Union[str, Any]       						=						image_classifier([image] * 5       ,  candidate_labels=["""A""", """B""", """C"""]       ,  batch_size=2							)
         self.assertEqual(
             nested_simplify(_lowerCamelCase							)       ,  [
                 [
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                 ],
                 [
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                 ],
                 [
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                 ],
                 [
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                 ],
                 [
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                     {"""score""": 0.333, """label""": ANY(_lowerCamelCase							)},
                 ],
             ]       ,  )

   @slow
   @require_torch
   def   _snake_case    (  self  : Union[str, Any]							):






         '''simple docstring'''



         __lowerCamelCase     :      int       						=						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     :      List[str]       						=						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""							)
         __lowerCamelCase     :      List[str]       						=						image_classifier(_lowerCamelCase       ,  candidate_labels=["""cat""", """plane""", """remote"""]							)

         self.assertEqual(
             nested_simplify(_lowerCamelCase							)       ,  [
                 {"""score""": 0.511, """label""": """remote"""},
                 {"""score""": 0.485, """label""": """cat"""},
                 {"""score""": 0.004, """label""": """plane"""},
             ]       ,  )

         __lowerCamelCase     :      Optional[Any]       						=						image_classifier([image] * 5       ,  candidate_labels=["""cat""", """plane""", """remote"""]       ,  batch_size=2							)
         self.assertEqual(
             nested_simplify(_lowerCamelCase							)       ,  [
                 [
                     {"""score""": 0.511, """label""": """remote"""},
                     {"""score""": 0.485, """label""": """cat"""},
                     {"""score""": 0.004, """label""": """plane"""},
                 ],
             ]
             * 5       ,  )


   @slow
   @require_tf
   def   _snake_case    (  self  : str							):






         '''simple docstring'''



         __lowerCamelCase     :      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
         __lowerCamelCase     :      Any       						=						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""							)
         __lowerCamelCase     :      Any       						=						image_classifier(_lowerCamelCase       ,  candidate_labels=["""cat""", """plane""", """remote"""]							)
         self.assertEqual(
             nested_simplify(_lowerCamelCase							)       ,  [
                 {"""score""": 0.511, """label""": """remote"""},
                 {"""score""": 0.485, """label""": """cat"""},
                 {"""score""": 0.004, """label""": """plane"""},
             ]       ,  )

         __lowerCamelCase     :      List[Any]       						=						image_classifier([image] * 5       ,  candidate_labels=["""cat""", """plane""", """remote"""]       ,  batch_size=2							)
         self.assertEqual(
             nested_simplify(_lowerCamelCase							)       ,  [
                 [
                     {"""score""": 0.511, """label""": """remote"""},
                     {"""score""": 0.485, """label""": """cat"""},
                     {"""score""": 0.004, """label""": """plane"""},
                 ],
             ]
             * 5       ,  )







from typing import Any





def   _UpperCAmelCase       (     UpperCAmelCase      :			list      ):
      """simple docstring"""




      if not input_list:
            return []
      __lowerCamelCase     :      int       						=						[input_list.count(UpperCAmelCase      ) for value in input_list]
      __lowerCamelCase     :      Tuple       						=						max(UpperCAmelCase      )  # Gets the maximum count in the input list.
      # Gets values of modes
      return sorted({input_list[i] for i, value in enumerate(UpperCAmelCase      ) if value == y}      )


if __name__ == "__main__":
    import doctest

    doctest.testmod()



