




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 	A	:
           """simple docstring"""

           @staticmethod
           def        __snake_case      (			*A__     :      Optional[int]		,     **A__     :      int	) ->				Union[str, Any]:
                 pass






@is_pipeline_test
@require_torch_or_tf
@require_vision
class 	A	(						unittest.TestCase						):
     """simple docstring"""

     _snake_case:		Tuple   =MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
     _snake_case:		Optional[int]   =TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING




     def        __snake_case      (			self     :      Dict		,     A__     :      Optional[int]		,     A__     :      Any		,     A__     :      Union[str, Any]	) ->				str:
           lowerCamelCase__					     = ImageClassificationPipeline(model=A__		,     image_processor=A__		,     top_k=2	)
           lowerCamelCase__					     = [
               Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'	),
               """http://images.cocodataset.org/val2017/000000039769.jpg""",
           ]
           return image_classifier, examples




     def        __snake_case      (			self     :      Union[str, Any]		,     A__     :      Optional[int]		,     A__     :      str	) ->				Optional[int]:
           lowerCamelCase__					     = image_classifier('./tests/fixtures/tests_samples/COCO/000000039769.png'	)

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

           import datasets

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

           # Accepts URL + PIL.Image + lists
           lowerCamelCase__					     = 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(
               A__		,     [
                   [
                       {'score': ANY(A__	), 'label': ANY(A__	)},
                       {'score': ANY(A__	), 'label': ANY(A__	)},
                   ],
                   [
                       {'score': ANY(A__	), 'label': ANY(A__	)},
                       {'score': ANY(A__	), 'label': ANY(A__	)},
                   ],
                   [
                       {'score': ANY(A__	), 'label': ANY(A__	)},
                       {'score': ANY(A__	), 'label': ANY(A__	)},
                   ],
                   [
                       {'score': ANY(A__	), 'label': ANY(A__	)},
                       {'score': ANY(A__	), 'label': ANY(A__	)},
                   ],
                   [
                       {'score': ANY(A__	), 'label': ANY(A__	)},
                       {'score': ANY(A__	), 'label': ANY(A__	)},
                   ],
               ]		,     )




     @require_torch
     def        __snake_case      (			self     :      Union[str, Any]	) ->				Dict:
           lowerCamelCase__					     = """hf-internal-testing/tiny-random-vit"""
           lowerCamelCase__					     = pipeline('image-classification'		,     model=A__	)

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

           lowerCamelCase__					     = image_classifier(
               [
                   'http://images.cocodataset.org/val2017/000000039769.jpg',
                   'http://images.cocodataset.org/val2017/000000039769.jpg',
               ]		,     top_k=2		,     )
           self.assertEqual(
               nested_simplify(A__		,     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        __snake_case      (			self     :      int	) ->				Tuple:
           lowerCamelCase__					     = """hf-internal-testing/tiny-random-vit"""
           lowerCamelCase__					     = pipeline('image-classification'		,     model=A__		,     framework='tf'	)

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

           lowerCamelCase__					     = image_classifier(
               [
                   'http://images.cocodataset.org/val2017/000000039769.jpg',
                   'http://images.cocodataset.org/val2017/000000039769.jpg',
               ]		,     top_k=2		,     )
           self.assertEqual(
               nested_simplify(A__		,     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        __snake_case      (			self     :      Optional[int]	) ->				List[Any]:
           lowerCamelCase__					     = PreTrainedTokenizer()

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

           self.assertIs(image_classifier.tokenizer		,     A__	)




     @slow
     @require_torch
     def        __snake_case      (			self     :      List[Any]	) ->				Union[str, Any]:
           lowerCamelCase__					     = pipeline('image-classification'		,     model='deepmind/vision-perceiver-conv'	)
           lowerCamelCase__					     = image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'	)
           self.assertEqual(
               nested_simplify(A__		,     decimals=4	)		,     [
                   {'score': 0.4385, 'label': 'tabby, tabby cat'},
                   {'score': 0.321, 'label': 'tiger cat'},
                   {'score': 0.0502, 'label': 'Egyptian cat'},
                   {'score': 0.0137, 'label': 'crib, cot'},
                   {'score': 0.007, 'label': 'radiator'},
               ]		,     )

           lowerCamelCase__					     = pipeline('image-classification'		,     model='deepmind/vision-perceiver-fourier'	)
           lowerCamelCase__					     = image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'	)
           self.assertEqual(
               nested_simplify(A__		,     decimals=4	)		,     [
                   {'score': 0.5658, 'label': 'tabby, tabby cat'},
                   {'score': 0.1309, 'label': 'tiger cat'},
                   {'score': 0.0722, 'label': 'Egyptian cat'},
                   {'score': 0.0707, 'label': 'remote control, remote'},
                   {'score': 0.0082, 'label': 'computer keyboard, keypad'},
               ]		,     )

           lowerCamelCase__					     = pipeline('image-classification'		,     model='deepmind/vision-perceiver-learned'	)
           lowerCamelCase__					     = image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'	)
           self.assertEqual(
               nested_simplify(A__		,     decimals=4	)		,     [
                   {'score': 0.3022, 'label': 'tabby, tabby cat'},
                   {'score': 0.2362, 'label': 'Egyptian cat'},
                   {'score': 0.1856, 'label': 'tiger cat'},
                   {'score': 0.0324, 'label': 'remote control, remote'},
                   {'score': 0.0096, 'label': 'quilt, comforter, comfort, puff'},
               ]		,     )


from math import sqrt





def 	snake_case_      (__A     :						int     )			->	list[int]:
   __lowerCAmelCase  :			List[str]					    =						[1]
   for i in range(2					,   int(sqrt(__A     )     ) + 1					,   1     ):
      if number % i == 0:
         values.append(__A     )
         if int(number // i     ) != i:
            values.append(int(number // i     )     )
   return sorted(__A     )





def 	snake_case_      (__A     :						int     )			->	bool:
   return sum(factors(__A     )     ) > n





def 	snake_case_      (__A     :						int     )			->	bool:
   __lowerCAmelCase  :			Any					    =						factors(__A     )
   __lowerCAmelCase  :			Union[str, Any]					    =						len(__A     )
   __lowerCAmelCase  :			str					    =						[[0 for i in range(number + 1     )] for j in range(r + 1     )]
   for i in range(r + 1     ):
      __lowerCAmelCase  :			Tuple					    =						True

   for i in range(1					,   number + 1     ):
      __lowerCAmelCase  :			List[str]					    =						False

   for i in range(1					,   r + 1     ):
      for j in range(1					,   number + 1     ):
         if j < values[i - 1]:
            __lowerCAmelCase  :			Dict					    =						subset[i - 1][j]
         else:
            __lowerCAmelCase  :			Dict					    =						subset[i - 1][j] or subset[i - 1][j - values[i - 1]]

   return subset[r][number] != 0





def 	snake_case_      (__A     :						int     )			->	bool:
   return abundant(__A     ) and not semi_perfect(__A     )


if __name__ == "__main__":
   import doctest

   doctest.testmod(verbose=True)
   for number in (69, 70, 71):
      print(F'{number} is {"" if weird(number) else "not "}weird.')


