






'''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    _SCREAMING_SNAKE_CASE							:


								'''simple docstring'''





								@staticmethod
								def 				A      (   *lowercase							:						str ,      **lowercase							:						List[Any]			)							->    str:

														'''simple docstring'''







														pass
@is_pipeline_test
@require_vision
@require_torch
class    _SCREAMING_SNAKE_CASE							(		unittest.TestCase	):


			'''simple docstring'''





			__a							:							Optional[int]					     =					MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING






			def 				A      (   self							:						str ,      lowercase							:						Any ,      lowercase							:						List[Any] ,      lowercase							:						str			)							->    Tuple:

									'''simple docstring'''







									UpperCamelCase__         = pipeline(
									    """zero-shot-object-detection""" ,      model="""hf-internal-testing/tiny-random-owlvit-object-detection"""			)

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






			def 				A      (   self							:						int ,      lowercase							:						int ,      lowercase							:						str			)							->    str:

									'''simple docstring'''







									UpperCamelCase__         = object_detector(examples[0] ,      threshold=0.0			)

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






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

									'''simple docstring'''







									pass






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

									'''simple docstring'''







									UpperCamelCase__         = pipeline(
									    """zero-shot-object-detection""" ,      model="""hf-internal-testing/tiny-random-owlvit-object-detection"""			)

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

									self.assertEqual(
									    nested_simplify(lowercase ,      decimals=4			) ,      [
									        {"""score""": 0.7_2_3_5, """label""": """cat""", """box""": {"""xmin""": 2_0_4, """ymin""": 1_6_7, """xmax""": 2_3_2, """ymax""": 1_9_0}},
									        {"""score""": 0.7_2_1_8, """label""": """remote""", """box""": {"""xmin""": 2_0_4, """ymin""": 1_6_7, """xmax""": 2_3_2, """ymax""": 1_9_0}},
									        {"""score""": 0.7_1_8_4, """label""": """couch""", """box""": {"""xmin""": 2_0_4, """ymin""": 1_6_7, """xmax""": 2_3_2, """ymax""": 1_9_0}},
									        {"""score""": 0.6_7_4_8, """label""": """remote""", """box""": {"""xmin""": 5_7_1, """ymin""": 8_3, """xmax""": 5_9_8, """ymax""": 1_0_3}},
									        {"""score""": 0.6_6_5_6, """label""": """cat""", """box""": {"""xmin""": 5_7_1, """ymin""": 8_3, """xmax""": 5_9_8, """ymax""": 1_0_3}},
									        {"""score""": 0.6_6_1_4, """label""": """couch""", """box""": {"""xmin""": 5_7_1, """ymin""": 8_3, """xmax""": 5_9_8, """ymax""": 1_0_3}},
									        {"""score""": 0.6_4_5_6, """label""": """remote""", """box""": {"""xmin""": 4_9_4, """ymin""": 1_0_5, """xmax""": 5_2_1, """ymax""": 1_2_7}},
									        {"""score""": 0.6_4_2, """label""": """remote""", """box""": {"""xmin""": 6_7, """ymin""": 2_7_4, """xmax""": 9_3, """ymax""": 2_9_7}},
									        {"""score""": 0.6_4_1_9, """label""": """cat""", """box""": {"""xmin""": 4_9_4, """ymin""": 1_0_5, """xmax""": 5_2_1, """ymax""": 1_2_7}},
									    ] ,      )

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

									self.assertEqual(
									    nested_simplify(lowercase ,      decimals=4			) ,      [
									        [
									            {"""score""": 0.7_2_3_5, """label""": """cat""", """box""": {"""xmin""": 2_0_4, """ymin""": 1_6_7, """xmax""": 2_3_2, """ymax""": 1_9_0}},
									            {"""score""": 0.7_2_1_8, """label""": """remote""", """box""": {"""xmin""": 2_0_4, """ymin""": 1_6_7, """xmax""": 2_3_2, """ymax""": 1_9_0}},
									            {"""score""": 0.7_1_8_4, """label""": """couch""", """box""": {"""xmin""": 2_0_4, """ymin""": 1_6_7, """xmax""": 2_3_2, """ymax""": 1_9_0}},
									            {"""score""": 0.6_7_4_8, """label""": """remote""", """box""": {"""xmin""": 5_7_1, """ymin""": 8_3, """xmax""": 5_9_8, """ymax""": 1_0_3}},
									            {"""score""": 0.6_6_5_6, """label""": """cat""", """box""": {"""xmin""": 5_7_1, """ymin""": 8_3, """xmax""": 5_9_8, """ymax""": 1_0_3}},
									            {"""score""": 0.6_6_1_4, """label""": """couch""", """box""": {"""xmin""": 5_7_1, """ymin""": 8_3, """xmax""": 5_9_8, """ymax""": 1_0_3}},
									            {"""score""": 0.6_4_5_6, """label""": """remote""", """box""": {"""xmin""": 4_9_4, """ymin""": 1_0_5, """xmax""": 5_2_1, """ymax""": 1_2_7}},
									            {"""score""": 0.6_4_2, """label""": """remote""", """box""": {"""xmin""": 6_7, """ymin""": 2_7_4, """xmax""": 9_3, """ymax""": 2_9_7}},
									            {"""score""": 0.6_4_1_9, """label""": """cat""", """box""": {"""xmin""": 4_9_4, """ymin""": 1_0_5, """xmax""": 5_2_1, """ymax""": 1_2_7}},
									        ]
									    ] ,      )






			@require_torch
			@slow
			def 				A      (   self							:						Optional[Any]			)							->    List[Any]:

									'''simple docstring'''







									UpperCamelCase__         = pipeline("""zero-shot-object-detection"""			)

									UpperCamelCase__         = object_detector(
									    """http://images.cocodataset.org/val2017/000000039769.jpg""" ,      candidate_labels=["""cat""", """remote""", """couch"""] ,      )
									self.assertEqual(
									    nested_simplify(lowercase ,      decimals=4			) ,      [
									        {"""score""": 0.2_8_6_8, """label""": """cat""", """box""": {"""xmin""": 3_2_4, """ymin""": 2_0, """xmax""": 6_4_0, """ymax""": 3_7_3}},
									        {"""score""": 0.2_7_7, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_2, """xmax""": 1_7_7, """ymax""": 1_1_5}},
									        {"""score""": 0.2_5_3_7, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 5_5, """xmax""": 3_1_5, """ymax""": 4_7_2}},
									        {"""score""": 0.1_4_7_4, """label""": """remote""", """box""": {"""xmin""": 3_3_5, """ymin""": 7_4, """xmax""": 3_7_1, """ymax""": 1_8_7}},
									        {"""score""": 0.1_2_0_8, """label""": """couch""", """box""": {"""xmin""": 4, """ymin""": 0, """xmax""": 6_4_2, """ymax""": 4_7_6}},
									    ] ,      )

									UpperCamelCase__         = 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(lowercase ,      decimals=4			) ,      [
									        [
									            {"""score""": 0.2_8_6_8, """label""": """cat""", """box""": {"""xmin""": 3_2_4, """ymin""": 2_0, """xmax""": 6_4_0, """ymax""": 3_7_3}},
									            {"""score""": 0.2_7_7, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_2, """xmax""": 1_7_7, """ymax""": 1_1_5}},
									            {"""score""": 0.2_5_3_7, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 5_5, """xmax""": 3_1_5, """ymax""": 4_7_2}},
									            {"""score""": 0.1_4_7_4, """label""": """remote""", """box""": {"""xmin""": 3_3_5, """ymin""": 7_4, """xmax""": 3_7_1, """ymax""": 1_8_7}},
									            {"""score""": 0.1_2_0_8, """label""": """couch""", """box""": {"""xmin""": 4, """ymin""": 0, """xmax""": 6_4_2, """ymax""": 4_7_6}},
									        ],
									        [
									            {"""score""": 0.2_8_6_8, """label""": """cat""", """box""": {"""xmin""": 3_2_4, """ymin""": 2_0, """xmax""": 6_4_0, """ymax""": 3_7_3}},
									            {"""score""": 0.2_7_7, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_2, """xmax""": 1_7_7, """ymax""": 1_1_5}},
									            {"""score""": 0.2_5_3_7, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 5_5, """xmax""": 3_1_5, """ymax""": 4_7_2}},
									            {"""score""": 0.1_4_7_4, """label""": """remote""", """box""": {"""xmin""": 3_3_5, """ymin""": 7_4, """xmax""": 3_7_1, """ymax""": 1_8_7}},
									            {"""score""": 0.1_2_0_8, """label""": """couch""", """box""": {"""xmin""": 4, """ymin""": 0, """xmax""": 6_4_2, """ymax""": 4_7_6}},
									        ],
									    ] ,      )






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

									'''simple docstring'''







									pass






			@require_torch
			@slow
			def 				A      (   self							:						Union[str, Any]			)							->    Union[str, Any]:

									'''simple docstring'''







									UpperCamelCase__         = 0.2
									UpperCamelCase__         = pipeline("""zero-shot-object-detection"""			)

									UpperCamelCase__         = object_detector(
									    """http://images.cocodataset.org/val2017/000000039769.jpg""" ,      candidate_labels=["""cat""", """remote""", """couch"""] ,      threshold=lowercase ,      )
									self.assertEqual(
									    nested_simplify(lowercase ,      decimals=4			) ,      [
									        {"""score""": 0.2_8_6_8, """label""": """cat""", """box""": {"""xmin""": 3_2_4, """ymin""": 2_0, """xmax""": 6_4_0, """ymax""": 3_7_3}},
									        {"""score""": 0.2_7_7, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_2, """xmax""": 1_7_7, """ymax""": 1_1_5}},
									        {"""score""": 0.2_5_3_7, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 5_5, """xmax""": 3_1_5, """ymax""": 4_7_2}},
									    ] ,      )







			@require_torch
			@slow
			def 				A      (   self							:						Optional[Any]			)							->    List[Any]:

									'''simple docstring'''







									UpperCamelCase__         = 2
									UpperCamelCase__         = pipeline("""zero-shot-object-detection"""			)

									UpperCamelCase__         = object_detector(
									    """http://images.cocodataset.org/val2017/000000039769.jpg""" ,      candidate_labels=["""cat""", """remote""", """couch"""] ,      top_k=lowercase ,      )
									self.assertEqual(
									    nested_simplify(lowercase ,      decimals=4			) ,      [
									        {"""score""": 0.2_8_6_8, """label""": """cat""", """box""": {"""xmin""": 3_2_4, """ymin""": 2_0, """xmax""": 6_4_0, """ymax""": 3_7_3}},
									        {"""score""": 0.2_7_7, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_2, """xmax""": 1_7_7, """ymax""": 1_1_5}},
									    ] ,      )








'''simple docstring'''


import math







def 	__magic_name__( _A					):
						'''simple docstring'''





						assert isinstance(_A						,      _A					) and (
						    number >= 0
						), "'number' must been an int and positive"

						if 1 < number < 4:
												# 2 and 3 are primes
												return True
						elif number < 2 or not number % 2:
												# Negatives, 0, 1 and all even numbers are not primes
												return False

						UpperCamelCase__         = range(3						,      int(math.sqrt(_A					) + 1					)						,      2					)
						return not any(not number % i for i in odd_numbers					)







def 	__magic_name__( _A						,      _A=1						,      **_A					):
						'''simple docstring'''





						UpperCamelCase__         = factor * value
						UpperCamelCase__         = value

						while not is_prime(_A					):
												value += 1 if not ("desc" in kwargs and kwargs["desc"] is True) else -1

						if value == first_value_val:
												return next_prime(value + 1						,      **_A					)
						return value
