





'''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__						(							*lowerCAmelCase__   :		Any       , **lowerCAmelCase__   :		Tuple     )    ->     Any:

               '''simple docstring'''




               pass
@is_pipeline_test
@require_vision
class 				__lowerCAmelCase     (    unittest.TestCase ):






       """simple docstring"""





       @require_torch
       def snake_case__						(							self   :		int     )    ->     Tuple:

            '''simple docstring'''




            _UpperCamelCase				    =       pipeline(
                model='''hf-internal-testing/tiny-random-clip-zero-shot-image-classification'''       , )
            _UpperCamelCase				    =       Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''     )
            _UpperCamelCase				    =       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.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'''}],
                ]       , )

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





       @require_tf
       def snake_case__						(							self   :		Tuple     )    ->     Optional[int]:

            '''simple docstring'''




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

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

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





       @slow
       @require_torch
       def snake_case__						(							self   :		Tuple     )    ->     Optional[int]:

            '''simple docstring'''




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

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

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







       @slow
       @require_tf
       def snake_case__						(							self   :		List[Any]     )    ->     Any:

            '''simple docstring'''




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

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










def 						__SCREAMING_SNAKE_CASE  (				UpperCamelCase__			,			UpperCamelCase__			,			UpperCamelCase__ )  ->				int:







			'''simple docstring'''

			if exponent == 1:
						return base
			if exponent % 2 == 0:
						UpperCAmelCase   		=				_modexpt(UpperCamelCase__			,			exponent // 2			,			UpperCamelCase__ ) % modulo_value
						return (x * x) % modulo_value
			else:
						return (base * _modexpt(UpperCamelCase__			,			exponent - 1			,			UpperCamelCase__ )) % modulo_value





def 						__SCREAMING_SNAKE_CASE  (				UpperCamelCase__ = 1777			,			UpperCamelCase__ = 1855			,			UpperCamelCase__ = 8 )  ->				int:







			'''simple docstring'''

			UpperCAmelCase   		=				base
			for _ in range(1			,			UpperCamelCase__ ):
						UpperCAmelCase   		=				_modexpt(UpperCamelCase__			,			UpperCamelCase__			,			10**digits )

			return result


if __name__ == "__main__":
				print(F'{solution() = }')



