'''simple docstring'''




import unittest

from transformers import (
    MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
    TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
    PreTrainedTokenizer,
    is_vision_available,
)
from transformers.pipelines import ImageClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_torch_or_tf,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
  from PIL import Image
else:




  class 	__UpperCAmelCase				:





         '''simple docstring'''



         @staticmethod
         def 					__A       (      *_SCREAMING_SNAKE_CASE    ,     **_SCREAMING_SNAKE_CASE )		->     Optional[Any]:
             pass




@is_pipeline_test
@require_torch_or_tf
@require_vision
class 	__UpperCAmelCase				(				unittest.TestCase     ):





       '''simple docstring'''



       __lowercase					:					List[Any]    =				MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
       __lowercase					:					Any    =				TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING

       def 					__A       (      self    ,     _SCREAMING_SNAKE_CASE    ,     _SCREAMING_SNAKE_CASE    ,     _SCREAMING_SNAKE_CASE )		->     str:
           A_     =   ImageClassificationPipeline(model=_SCREAMING_SNAKE_CASE    ,     image_processor=_SCREAMING_SNAKE_CASE    ,     top_k=2 )
           A_     =   [
               Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png''' ),
               '''http://images.cocodataset.org/val2017/000000039769.jpg''',
           ]
           return image_classifier, examples

       def 					__A       (      self    ,     _SCREAMING_SNAKE_CASE    ,     _SCREAMING_SNAKE_CASE )		->     Union[str, Any]:
           A_     =   image_classifier('''./tests/fixtures/tests_samples/COCO/000000039769.png''' )

           self.assertEqual(
               _SCREAMING_SNAKE_CASE    ,     [
                   {'''score''': ANY(_SCREAMING_SNAKE_CASE ), '''label''': ANY(_SCREAMING_SNAKE_CASE )},
                   {'''score''': ANY(_SCREAMING_SNAKE_CASE ), '''label''': ANY(_SCREAMING_SNAKE_CASE )},
               ]    ,     )

           import datasets

           A_     =   datasets.load_dataset('''hf-internal-testing/fixtures_image_utils'''    ,     '''image'''    ,     split='''test''' )

           # Accepts URL + PIL.Image + lists
           A_     =   image_classifier(
               [
                   Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png''' ),
                   '''http://images.cocodataset.org/val2017/000000039769.jpg''',
                   # RGBA
                   dataset[0]['''file'''],
                   # LA
                   dataset[1]['''file'''],
                   # L
                   dataset[2]['''file'''],
               ] )
           self.assertEqual(
               _SCREAMING_SNAKE_CASE    ,     [
                   [
                       {'''score''': ANY(_SCREAMING_SNAKE_CASE ), '''label''': ANY(_SCREAMING_SNAKE_CASE )},
                       {'''score''': ANY(_SCREAMING_SNAKE_CASE ), '''label''': ANY(_SCREAMING_SNAKE_CASE )},
                   ],
                   [
                       {'''score''': ANY(_SCREAMING_SNAKE_CASE ), '''label''': ANY(_SCREAMING_SNAKE_CASE )},
                       {'''score''': ANY(_SCREAMING_SNAKE_CASE ), '''label''': ANY(_SCREAMING_SNAKE_CASE )},
                   ],
                   [
                       {'''score''': ANY(_SCREAMING_SNAKE_CASE ), '''label''': ANY(_SCREAMING_SNAKE_CASE )},
                       {'''score''': ANY(_SCREAMING_SNAKE_CASE ), '''label''': ANY(_SCREAMING_SNAKE_CASE )},
                   ],
                   [
                       {'''score''': ANY(_SCREAMING_SNAKE_CASE ), '''label''': ANY(_SCREAMING_SNAKE_CASE )},
                       {'''score''': ANY(_SCREAMING_SNAKE_CASE ), '''label''': ANY(_SCREAMING_SNAKE_CASE )},
                   ],
                   [
                       {'''score''': ANY(_SCREAMING_SNAKE_CASE ), '''label''': ANY(_SCREAMING_SNAKE_CASE )},
                       {'''score''': ANY(_SCREAMING_SNAKE_CASE ), '''label''': ANY(_SCREAMING_SNAKE_CASE )},
                   ],
               ]    ,     )

       @require_torch
       def 					__A       (      self )		->     Union[str, Any]:
           A_     =   '''hf-internal-testing/tiny-random-vit'''
           A_     =   pipeline('''image-classification'''    ,     model=_SCREAMING_SNAKE_CASE )

           A_     =   image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg''' )
           self.assertEqual(
               nested_simplify(_SCREAMING_SNAKE_CASE    ,     decimals=4 )    ,     [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}]    ,     )

           A_     =   image_classifier(
               [
                   '''http://images.cocodataset.org/val2017/000000039769.jpg''',
                   '''http://images.cocodataset.org/val2017/000000039769.jpg''',
               ]    ,     top_k=2    ,     )
           self.assertEqual(
               nested_simplify(_SCREAMING_SNAKE_CASE    ,     decimals=4 )    ,     [
                   [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],
                   [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],
               ]    ,     )

       @require_tf
       def 					__A       (      self )		->     Optional[Any]:
           A_     =   '''hf-internal-testing/tiny-random-vit'''
           A_     =   pipeline('''image-classification'''    ,     model=_SCREAMING_SNAKE_CASE    ,     framework='''tf''' )

           A_     =   image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg''' )
           self.assertEqual(
               nested_simplify(_SCREAMING_SNAKE_CASE    ,     decimals=4 )    ,     [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}]    ,     )

           A_     =   image_classifier(
               [
                   '''http://images.cocodataset.org/val2017/000000039769.jpg''',
                   '''http://images.cocodataset.org/val2017/000000039769.jpg''',
               ]    ,     top_k=2    ,     )
           self.assertEqual(
               nested_simplify(_SCREAMING_SNAKE_CASE    ,     decimals=4 )    ,     [
                   [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],
                   [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],
               ]    ,     )

       def 					__A       (      self )		->     Optional[int]:
           A_     =   PreTrainedTokenizer()

           # Assert that the pipeline can be initialized with a feature extractor that is not in any mapping
           A_     =   pipeline(
               '''image-classification'''    ,     model='''hf-internal-testing/tiny-random-vit'''    ,     tokenizer=_SCREAMING_SNAKE_CASE )

           self.assertIs(image_classifier.tokenizer    ,     _SCREAMING_SNAKE_CASE )

       @slow
       @require_torch
       def 					__A       (      self )		->     Dict:
           # Perceiver is not tested by `run_pipeline_test` properly.
           # That is because the type of feature_extractor and model preprocessor need to be kept
           # in sync, which is not the case in the current design
           A_     =   pipeline('''image-classification'''    ,     model='''deepmind/vision-perceiver-conv''' )
           A_     =   image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg''' )
           self.assertEqual(
               nested_simplify(_SCREAMING_SNAKE_CASE    ,     decimals=4 )    ,     [
                   {'''score''': 0.4_385, '''label''': '''tabby, tabby cat'''},
                   {'''score''': 0.321, '''label''': '''tiger cat'''},
                   {'''score''': 0.0_502, '''label''': '''Egyptian cat'''},
                   {'''score''': 0.0_137, '''label''': '''crib, cot'''},
                   {'''score''': 0.007, '''label''': '''radiator'''},
               ]    ,     )

           A_     =   pipeline('''image-classification'''    ,     model='''deepmind/vision-perceiver-fourier''' )
           A_     =   image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg''' )
           self.assertEqual(
               nested_simplify(_SCREAMING_SNAKE_CASE    ,     decimals=4 )    ,     [
                   {'''score''': 0.5_658, '''label''': '''tabby, tabby cat'''},
                   {'''score''': 0.1_309, '''label''': '''tiger cat'''},
                   {'''score''': 0.0_722, '''label''': '''Egyptian cat'''},
                   {'''score''': 0.0_707, '''label''': '''remote control, remote'''},
                   {'''score''': 0.0_082, '''label''': '''computer keyboard, keypad'''},
               ]    ,     )

           A_     =   pipeline('''image-classification'''    ,     model='''deepmind/vision-perceiver-learned''' )
           A_     =   image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg''' )
           self.assertEqual(
               nested_simplify(_SCREAMING_SNAKE_CASE    ,     decimals=4 )    ,     [
                   {'''score''': 0.3_022, '''label''': '''tabby, tabby cat'''},
                   {'''score''': 0.2_362, '''label''': '''Egyptian cat'''},
                   {'''score''': 0.1_856, '''label''': '''tiger cat'''},
                   {'''score''': 0.0_324, '''label''': '''remote control, remote'''},
                   {'''score''': 0.0_096, '''label''': '''quilt, comforter, comfort, puff'''},
               ]    ,     )







'''simple docstring'''




from scipy.constants import g





def      _UpperCAmelCase    (							_UpperCamelCase    :	float,   _UpperCamelCase    :	float   )	->      float:
    if mass < 0:
        # handling of negative values of mass
        raise ValueError('''The mass of a body cannot be negative'''   )
    if height < 0:
        # handling of negative values of height
        raise ValueError('''The height above the ground cannot be negative'''   )
    return mass * g * height


if __name__ == "__main__":
  from doctest import testmod

  testmod(name='potential_energy')






