





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


       @staticmethod
       def 							SCREAMING_SNAKE_CASE  (						*_UpperCAmelCase						,     **_UpperCAmelCase):

            '''simple docstring'''






            pass


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


     @require_torch
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						:			str								=	pipeline(
              model='hf-internal-testing/tiny-random-clip-zero-shot-image-classification'						,     )
          __A						:			str								=	Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
          __A						:			Optional[int]								=	image_classifier(_UpperCAmelCase						,     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(_UpperCAmelCase)						,     [
                  [{'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'}],
              ]						,     )

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


     @require_tf
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






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

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

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


     @slow
     @require_torch
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						:			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						:			int								=	Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
          __A						:			Dict								=	image_classifier(_UpperCAmelCase						,     candidate_labels=['cat', 'plane', 'remote'])

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

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


     @slow
     @require_tf
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






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

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






'''simple docstring'''




import argparse


lowercase__   :				Any      =   '''docs/source/_static/js/custom.js'''






def 	_lowerCAmelCase      (  __snake_case  :			Union[str, Any]      )					->					str:
     with open(__snake_case			,							encoding='utf-8'			,							newline='\n'      ) as f:
          __A						:			Optional[Any]								=	f.readlines()
     __A						:			List[str]								=	0

     # First let's put the right version
     while not lines[index].startswith('const stableVersion ='      ):
          index += 1
     __A						:			Tuple								=	f'const stableVersion = "v{version}"\n'

     # Then update the dictionary
     while not lines[index].startswith('const versionMapping = {'      ):
          index += 1

     # We go until the end
     while not lines[index].startswith('}'      ):
          index += 1
     # We add the new version at the end
     lines[index - 1] += f'    "v{version}": "v{version}",\n'

     with open(__snake_case			,							'w'			,							encoding='utf-8'			,							newline='\n'      ) as f:
          f.writelines(__snake_case      )


if __name__ == "__main__":
  lowercase__   :				Optional[Any]      =   argparse.ArgumentParser()
  parser.add_argument('''--version''', help='''Release version.''')
  lowercase__   :				List[str]      =   parser.parse_args()
  update_custom_js(args.version)