





'''simple docstring'''




import unittest

from transformers import MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING, is_vision_available, 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      lowerCAmelCase			(   *__snake_case							:			Optional[int]   ,       **__snake_case							:			int						)->	Optional[int]:
         pass
@is_pipeline_test
@require_vision
@require_torch
class 			_lowerCAmelCase		(			unittest.TestCase	):






     """simple docstring"""






     snake_case_						      =   MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING



     def      lowerCAmelCase			(   self							:			Optional[Any]   ,       __snake_case							:			List[str]   ,       __snake_case							:			List[Any]   ,       __snake_case							:			Any						)->	Tuple:
        snake_case 						=   pipeline(
            """zero-shot-object-detection"""   ,       model="""hf-internal-testing/tiny-random-owlvit-object-detection"""						)

        snake_case 						=   [
            {
                """image""": """./tests/fixtures/tests_samples/COCO/000000039769.png""",
                """candidate_labels""": ["""cat""", """remote""", """couch"""],
            }
        ]
        return object_detector, examples



     def      lowerCAmelCase			(   self							:			str   ,       __snake_case							:			Tuple   ,       __snake_case							:			Optional[int]						)->	Dict:
        snake_case 						=   object_detector(examples[0]   ,       threshold=0.0						)

        snake_case 						=   len(__snake_case						)
        self.assertGreater(__snake_case   ,       0						)
        self.assertEqual(
            __snake_case   ,       [
                {
                    """score""": ANY(__snake_case						),
                    """label""": ANY(__snake_case						),
                    """box""": {"""xmin""": ANY(__snake_case						), """ymin""": ANY(__snake_case						), """xmax""": ANY(__snake_case						), """ymax""": ANY(__snake_case						)},
                }
                for i in range(__snake_case						)
            ]   ,       )



     @require_tf
     @unittest.skip("""Zero Shot Object Detection not implemented in TF"""						)
     def      lowerCAmelCase			(   self							:			Optional[int]						)->	Dict:
        pass



     @require_torch
     def      lowerCAmelCase			(   self							:			List[Any]						)->	int:
        snake_case 						=   pipeline(
            """zero-shot-object-detection"""   ,       model="""hf-internal-testing/tiny-random-owlvit-object-detection"""						)

        snake_case 						=   object_detector(
            """./tests/fixtures/tests_samples/COCO/000000039769.png"""   ,       candidate_labels=["""cat""", """remote""", """couch"""]   ,       threshold=0.64   ,       )

        self.assertEqual(
            nested_simplify(__snake_case   ,       decimals=4						)   ,       [
                {"""score""": 0.72_35, """label""": """cat""", """box""": {"""xmin""": 2_04, """ymin""": 1_67, """xmax""": 2_32, """ymax""": 1_90}},
                {"""score""": 0.72_18, """label""": """remote""", """box""": {"""xmin""": 2_04, """ymin""": 1_67, """xmax""": 2_32, """ymax""": 1_90}},
                {"""score""": 0.71_84, """label""": """couch""", """box""": {"""xmin""": 2_04, """ymin""": 1_67, """xmax""": 2_32, """ymax""": 1_90}},
                {"""score""": 0.67_48, """label""": """remote""", """box""": {"""xmin""": 5_71, """ymin""": 83, """xmax""": 5_98, """ymax""": 1_03}},
                {"""score""": 0.66_56, """label""": """cat""", """box""": {"""xmin""": 5_71, """ymin""": 83, """xmax""": 5_98, """ymax""": 1_03}},
                {"""score""": 0.66_14, """label""": """couch""", """box""": {"""xmin""": 5_71, """ymin""": 83, """xmax""": 5_98, """ymax""": 1_03}},
                {"""score""": 0.64_56, """label""": """remote""", """box""": {"""xmin""": 4_94, """ymin""": 1_05, """xmax""": 5_21, """ymax""": 1_27}},
                {"""score""": 0.6_42, """label""": """remote""", """box""": {"""xmin""": 67, """ymin""": 2_74, """xmax""": 93, """ymax""": 2_97}},
                {"""score""": 0.64_19, """label""": """cat""", """box""": {"""xmin""": 4_94, """ymin""": 1_05, """xmax""": 5_21, """ymax""": 1_27}},
            ]   ,       )

        snake_case 						=   object_detector(
            [
                {
                    """image""": """./tests/fixtures/tests_samples/COCO/000000039769.png""",
                    """candidate_labels""": ["""cat""", """remote""", """couch"""],
                }
            ]   ,       threshold=0.64   ,       )

        self.assertEqual(
            nested_simplify(__snake_case   ,       decimals=4						)   ,       [
                [
                    {"""score""": 0.72_35, """label""": """cat""", """box""": {"""xmin""": 2_04, """ymin""": 1_67, """xmax""": 2_32, """ymax""": 1_90}},
                    {"""score""": 0.72_18, """label""": """remote""", """box""": {"""xmin""": 2_04, """ymin""": 1_67, """xmax""": 2_32, """ymax""": 1_90}},
                    {"""score""": 0.71_84, """label""": """couch""", """box""": {"""xmin""": 2_04, """ymin""": 1_67, """xmax""": 2_32, """ymax""": 1_90}},
                    {"""score""": 0.67_48, """label""": """remote""", """box""": {"""xmin""": 5_71, """ymin""": 83, """xmax""": 5_98, """ymax""": 1_03}},
                    {"""score""": 0.66_56, """label""": """cat""", """box""": {"""xmin""": 5_71, """ymin""": 83, """xmax""": 5_98, """ymax""": 1_03}},
                    {"""score""": 0.66_14, """label""": """couch""", """box""": {"""xmin""": 5_71, """ymin""": 83, """xmax""": 5_98, """ymax""": 1_03}},
                    {"""score""": 0.64_56, """label""": """remote""", """box""": {"""xmin""": 4_94, """ymin""": 1_05, """xmax""": 5_21, """ymax""": 1_27}},
                    {"""score""": 0.6_42, """label""": """remote""", """box""": {"""xmin""": 67, """ymin""": 2_74, """xmax""": 93, """ymax""": 2_97}},
                    {"""score""": 0.64_19, """label""": """cat""", """box""": {"""xmin""": 4_94, """ymin""": 1_05, """xmax""": 5_21, """ymax""": 1_27}},
                ]
            ]   ,       )



     @require_torch
     @slow
     def      lowerCAmelCase			(   self							:			str						)->	Optional[Any]:
        snake_case 						=   pipeline("""zero-shot-object-detection"""						)

        snake_case 						=   object_detector(
            """http://images.cocodataset.org/val2017/000000039769.jpg"""   ,       candidate_labels=["""cat""", """remote""", """couch"""]   ,       )
        self.assertEqual(
            nested_simplify(__snake_case   ,       decimals=4						)   ,       [
                {"""score""": 0.28_68, """label""": """cat""", """box""": {"""xmin""": 3_24, """ymin""": 20, """xmax""": 6_40, """ymax""": 3_73}},
                {"""score""": 0.2_77, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 72, """xmax""": 1_77, """ymax""": 1_15}},
                {"""score""": 0.25_37, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 55, """xmax""": 3_15, """ymax""": 4_72}},
                {"""score""": 0.14_74, """label""": """remote""", """box""": {"""xmin""": 3_35, """ymin""": 74, """xmax""": 3_71, """ymax""": 1_87}},
                {"""score""": 0.12_08, """label""": """couch""", """box""": {"""xmin""": 4, """ymin""": 0, """xmax""": 6_42, """ymax""": 4_76}},
            ]   ,       )

        snake_case 						=   object_detector(
            [
                {
                    """image""": """http://images.cocodataset.org/val2017/000000039769.jpg""",
                    """candidate_labels""": ["""cat""", """remote""", """couch"""],
                },
                {
                    """image""": """http://images.cocodataset.org/val2017/000000039769.jpg""",
                    """candidate_labels""": ["""cat""", """remote""", """couch"""],
                },
            ]   ,       )
        self.assertEqual(
            nested_simplify(__snake_case   ,       decimals=4						)   ,       [
                [
                    {"""score""": 0.28_68, """label""": """cat""", """box""": {"""xmin""": 3_24, """ymin""": 20, """xmax""": 6_40, """ymax""": 3_73}},
                    {"""score""": 0.2_77, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 72, """xmax""": 1_77, """ymax""": 1_15}},
                    {"""score""": 0.25_37, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 55, """xmax""": 3_15, """ymax""": 4_72}},
                    {"""score""": 0.14_74, """label""": """remote""", """box""": {"""xmin""": 3_35, """ymin""": 74, """xmax""": 3_71, """ymax""": 1_87}},
                    {"""score""": 0.12_08, """label""": """couch""", """box""": {"""xmin""": 4, """ymin""": 0, """xmax""": 6_42, """ymax""": 4_76}},
                ],
                [
                    {"""score""": 0.28_68, """label""": """cat""", """box""": {"""xmin""": 3_24, """ymin""": 20, """xmax""": 6_40, """ymax""": 3_73}},
                    {"""score""": 0.2_77, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 72, """xmax""": 1_77, """ymax""": 1_15}},
                    {"""score""": 0.25_37, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 55, """xmax""": 3_15, """ymax""": 4_72}},
                    {"""score""": 0.14_74, """label""": """remote""", """box""": {"""xmin""": 3_35, """ymin""": 74, """xmax""": 3_71, """ymax""": 1_87}},
                    {"""score""": 0.12_08, """label""": """couch""", """box""": {"""xmin""": 4, """ymin""": 0, """xmax""": 6_42, """ymax""": 4_76}},
                ],
            ]   ,       )



     @require_tf
     @unittest.skip("""Zero Shot Object Detection not implemented in TF"""						)
     def      lowerCAmelCase			(   self							:			Any						)->	int:
        pass



     @require_torch
     @slow
     def      lowerCAmelCase			(   self							:			Tuple						)->	Dict:
        snake_case 						=   0.2
        snake_case 						=   pipeline("""zero-shot-object-detection"""						)

        snake_case 						=   object_detector(
            """http://images.cocodataset.org/val2017/000000039769.jpg"""   ,       candidate_labels=["""cat""", """remote""", """couch"""]   ,       threshold=__snake_case   ,       )
        self.assertEqual(
            nested_simplify(__snake_case   ,       decimals=4						)   ,       [
                {"""score""": 0.28_68, """label""": """cat""", """box""": {"""xmin""": 3_24, """ymin""": 20, """xmax""": 6_40, """ymax""": 3_73}},
                {"""score""": 0.2_77, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 72, """xmax""": 1_77, """ymax""": 1_15}},
                {"""score""": 0.25_37, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 55, """xmax""": 3_15, """ymax""": 4_72}},
            ]   ,       )



     @require_torch
     @slow
     def      lowerCAmelCase			(   self							:			Optional[int]						)->	List[str]:
        snake_case 						=   2
        snake_case 						=   pipeline("""zero-shot-object-detection"""						)

        snake_case 						=   object_detector(
            """http://images.cocodataset.org/val2017/000000039769.jpg"""   ,       candidate_labels=["""cat""", """remote""", """couch"""]   ,       top_k=__snake_case   ,       )
        self.assertEqual(
            nested_simplify(__snake_case   ,       decimals=4						)   ,       [
                {"""score""": 0.28_68, """label""": """cat""", """box""": {"""xmin""": 3_24, """ymin""": 20, """xmax""": 6_40, """ymax""": 3_73}},
                {"""score""": 0.2_77, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 72, """xmax""": 1_77, """ymax""": 1_15}},
            ]   ,       )








'''simple docstring'''




def 	__lowerCamelCase			(      __lowerCAmelCase       :							int		)		->  int:
   assert isinstance(__lowerCAmelCase      ,    __lowerCAmelCase		), F'''The input value of [n={number}] is not an integer'''

   if number == 1:
      return 2
   elif number < 1:
      snake_case 						=   F'''The input value of [n={number}] has to be > 0'''
      raise ValueError(__lowerCAmelCase		)
   else:
      snake_case 						=   sylvester(number - 1		)
      snake_case 						=   num - 1
      snake_case 						=   num
      return lower * upper + 1


if __name__ == "__main__":
 print(F"""The 8th number in Sylvester's sequence: {sylvester(8)}""")

