
'''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 			lowercase				(*UpperCAmelCase    ,    **UpperCAmelCase    )	->  Dict:
																		pass


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







							'''simple docstring'''

							@require_torch
							def 			lowercase				(self    )	->  Dict:
														_snake_case  =    pipeline(
														    model="""hf-internal-testing/tiny-random-clip-zero-shot-image-classification"""    ,    )
														_snake_case  =    Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""    )
														_snake_case  =    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"""}],
														    ]    ,    )

														_snake_case  =    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 			lowercase				(self    )	->  Any:
														_snake_case  =    pipeline(
														    model="""hf-internal-testing/tiny-random-clip-zero-shot-image-classification"""    ,    framework="""tf"""    )
														_snake_case  =    Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""    )
														_snake_case  =    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"""}]    ,    )

														_snake_case  =    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 			lowercase				(self    )	->  Union[str, Any]:
														_snake_case  =    pipeline(
														    task="""zero-shot-image-classification"""    ,    model="""openai/clip-vit-base-patch32"""    ,    )
														# This is an image of 2 cats with remotes and no planes
														_snake_case  =    Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""    )
														_snake_case  =    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"""},
														    ]    ,    )

														_snake_case  =    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 			lowercase				(self    )	->  Tuple:
														_snake_case  =    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
														_snake_case  =    Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""    )
														_snake_case  =    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"""},
														    ]    ,    )

														_snake_case  =    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    ,    )







import argparse
import importlib
from pathlib import Path


# Test all the extensions added in the setup
lowerCamelCase      :       str    =						[
    '''kernels/rwkv/wkv_cuda.cu''',
    '''kernels/rwkv/wkv_op.cpp''',
    '''kernels/deformable_detr/ms_deform_attn.h''',
    '''kernels/deformable_detr/cuda/ms_deform_im2col_cuda.cuh''',
    '''models/graphormer/algos_graphormer.pyx''',
]





def    __lowerCAmelCase   (    __snake_case							):
     # Test all the extensions added in the setup
     for file in FILES_TO_FIND:
          if not (transformers_path / file).exists():
               return False
     return True


if __name__ == "__main__":
 lowerCamelCase      :       str    =						argparse.ArgumentParser()
 parser.add_argument('''--check_lib''', action='''store_true''', help='''Whether to check the build or the actual package.''')
 lowerCamelCase      :       Dict    =						parser.parse_args()
 if args.check_lib:
  lowerCamelCase      :       Optional[int]    =						importlib.import_module('''transformers''')
  lowerCamelCase      :       str    =						Path(transformers_module.__file__).parent
 else:
  lowerCamelCase      :       List[Any]    =						Path.cwd() / '''build/lib/transformers'''
 if not test_custom_files_are_present(transformers_path):
  raise ValueError('''The built release does not contain the custom files. Fix this before going further!''')






