

from abc import ABC, abstractmethod
from typing import List, Optional






class 						__magic_name__					(							snake_case				):






     def __init__(				self	)->     Optional[int]:
         # test for the above condition
         self.test()






     def 	UpperCAmelCase_				(				self	)->     Union[str, Any]:
         UpperCamelCase_			  =						0
         UpperCamelCase_			  =						False
         while not completed:
             if counter == 1:
                 self.reset()
             UpperCamelCase_			  =						self.advance()
             if not self.does_advance(_lowercase	):
                 raise Exception(
                     "Custom Constraint is not defined correctly. self.does_advance(self.advance()) must be true."	)

             UpperCamelCase_  ,       UpperCamelCase_  ,       UpperCamelCase_			  =						self.update(_lowercase	)
             counter += 1

             if counter > 10_000:
                 raise Exception("update() does not fulfill the constraint."	)

         if self.remaining() != 0:
             raise Exception("Custom Constraint is not defined correctly."	)






     @abstractmethod
     def 	UpperCAmelCase_				(				self	)->     Optional[Any]:
         raise NotImplementedError(
             F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."	)






     @abstractmethod
     def 	UpperCAmelCase_				(				self		,						_lowercase	)->     Any:
         raise NotImplementedError(
             F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."	)






     @abstractmethod
     def 	UpperCAmelCase_				(				self		,						_lowercase	)->     Union[str, Any]:
         raise NotImplementedError(
             F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."	)






     @abstractmethod
     def 	UpperCAmelCase_				(				self	)->     List[Any]:
         raise NotImplementedError(
             F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."	)






     @abstractmethod
     def 	UpperCAmelCase_				(				self	)->     Optional[Any]:
         raise NotImplementedError(
             F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."	)






     @abstractmethod
     def 	UpperCAmelCase_				(				self		,						_lowercase=False	)->     Dict:
         raise NotImplementedError(
             F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."	)






class 						__magic_name__					(							snake_case				):






     def __init__(				self		,						_lowercase	)->     Optional[int]:
         super(_lowercase		,						self	).__init__()

         if not isinstance(_lowercase		,						_lowercase	) or len(_lowercase	) == 0:
             raise ValueError(F"`token_ids` has to be a non-empty list, but is {token_ids}."	)
         if any((not isinstance(_lowercase		,						_lowercase	) or token_id < 0) for token_id in token_ids	):
             raise ValueError(F"Each list in `token_ids` has to be a list of positive integers, but is {token_ids}."	)

         UpperCamelCase_			  =						token_ids

         UpperCamelCase_			  =						len(self.token_ids	)
         UpperCamelCase_			  =						-1  # the index of the currently fulfilled step
         UpperCamelCase_			  =						False






     def 	UpperCAmelCase_				(				self	)->     List[str]:
         if self.completed:
             return None
         return self.token_ids[self.fulfilled_idx + 1]






     def 	UpperCAmelCase_				(				self		,						_lowercase	)->     Dict:
         if not isinstance(_lowercase		,						_lowercase	):
             raise ValueError(F"`token_id` has to be an `int`, but is {token_id} of type {type(_lowercase	)}"	)

         if self.completed:
             return False

         return token_id == self.token_ids[self.fulfilled_idx + 1]






     def 	UpperCAmelCase_				(				self		,						_lowercase	)->     Optional[int]:
         if not isinstance(_lowercase		,						_lowercase	):
             raise ValueError(F"`token_id` has to be an `int`, but is {token_id} of type {type(_lowercase	)}"	)

         UpperCamelCase_			  =						False
         UpperCamelCase_			  =						False
         UpperCamelCase_			  =						False

         if self.does_advance(_lowercase	):
             self.fulfilled_idx += 1
             UpperCamelCase_			  =						True
             if self.fulfilled_idx == (self.seqlen - 1):
                 UpperCamelCase_			  =						True
             UpperCamelCase_			  =						completed
         else:
             # failed to make progress.
             UpperCamelCase_			  =						True
             self.reset()
         return stepped, completed, reset






     def 	UpperCAmelCase_				(				self	)->     List[str]:
         UpperCamelCase_			  =						False
         UpperCamelCase_			  =						0






     def 	UpperCAmelCase_				(				self	)->     Union[str, Any]:
         return self.seqlen - (self.fulfilled_idx + 1)






     def 	UpperCAmelCase_				(				self		,						_lowercase=False	)->     Optional[Any]:
         UpperCamelCase_			  =						PhrasalConstraint(self.token_ids	)

         if stateful:
             UpperCamelCase_			  =						self.seqlen
             UpperCamelCase_			  =						self.fulfilled_idx
             UpperCamelCase_			  =						self.completed

         return new_constraint






class 						__magic_name__					:






     def __init__(				self		,						_lowercase		,						_lowercase=True	)->     str:
         UpperCamelCase_			  =						max([len(_lowercase	) for one in nested_token_ids]	)

         UpperCamelCase_			  =						{}
         for token_ids in nested_token_ids:
             UpperCamelCase_			  =						root
             for tidx, token_id in enumerate(_lowercase	):
                 if token_id not in level:
                     UpperCamelCase_			  =						{}

                 UpperCamelCase_			  =						level[token_id]

         if no_subsets and self.has_subsets(_lowercase		,						_lowercase	):
             raise ValueError(
                 "Each list in `nested_token_ids` can't be a complete subset of another list, but is"
                 F" {nested_token_ids}."	)

         UpperCamelCase_			  =						root






     def 	UpperCAmelCase_				(				self		,						_lowercase	)->     Dict:
         UpperCamelCase_			  =						self.trie

         for current_token in current_seq:
             UpperCamelCase_			  =						start[current_token]

         UpperCamelCase_			  =						list(start.keys()	)

         return next_tokens






     def 	UpperCAmelCase_				(				self		,						_lowercase	)->     Tuple:
         UpperCamelCase_			  =						self.next_tokens(_lowercase	)

         return len(_lowercase	) == 0






     def 	UpperCAmelCase_				(				self		,						_lowercase	)->     Dict:
         UpperCamelCase_			  =						list(root.values()	)
         if len(_lowercase	) == 0:
             return 1
         else:
             return sum([self.count_leaves(_lowercase	) for nn in next_nodes]	)






     def 	UpperCAmelCase_				(				self		,						_lowercase		,						_lowercase	)->     Any:
         UpperCamelCase_			  =						self.count_leaves(_lowercase	)
         return len(_lowercase	) != leaf_count






class 						__magic_name__					(							snake_case				):






     def __init__(				self		,						_lowercase	)->     Optional[int]:
         super(_lowercase		,						self	).__init__()

         if not isinstance(_lowercase		,						_lowercase	) or len(_lowercase	) == 0:
             raise ValueError(F"`nested_token_ids` has to be a non-empty list, but is {nested_token_ids}."	)
         if any(not isinstance(_lowercase		,						_lowercase	) for token_ids in nested_token_ids	):
             raise ValueError(F"`nested_token_ids` has to be a list of lists, but is {nested_token_ids}."	)
         if any(
             any((not isinstance(_lowercase		,						_lowercase	) or token_id < 0) for token_id in token_ids	)
             for token_ids in nested_token_ids	):
             raise ValueError(
                 F"Each list in `nested_token_ids` has to be a list of positive integers, but is {nested_token_ids}."	)

         UpperCamelCase_			  =						DisjunctiveTrie(_lowercase	)
         UpperCamelCase_			  =						nested_token_ids

         UpperCamelCase_			  =						self.trie.max_height
         UpperCamelCase_			  =						[]
         UpperCamelCase_			  =						False






     def 	UpperCAmelCase_				(				self	)->     int:
         UpperCamelCase_			  =						self.trie.next_tokens(self.current_seq	)

         if len(_lowercase	) == 0:
             return None
         else:
             return token_list






     def 	UpperCAmelCase_				(				self		,						_lowercase	)->     List[Any]:
         if not isinstance(_lowercase		,						_lowercase	):
             raise ValueError(F"`token_id` is supposed to be type `int`, but is {token_id} of type {type(_lowercase	)}"	)

         UpperCamelCase_			  =						self.trie.next_tokens(self.current_seq	)

         return token_id in next_tokens






     def 	UpperCAmelCase_				(				self		,						_lowercase	)->     Any:
         if not isinstance(_lowercase		,						_lowercase	):
             raise ValueError(F"`token_id` is supposed to be type `int`, but is {token_id} of type {type(_lowercase	)}"	)

         UpperCamelCase_			  =						False
         UpperCamelCase_			  =						False
         UpperCamelCase_			  =						False

         if self.does_advance(_lowercase	):
             self.current_seq.append(_lowercase	)
             UpperCamelCase_			  =						True
         else:
             UpperCamelCase_			  =						True
             self.reset()

         UpperCamelCase_			  =						self.trie.reached_leaf(self.current_seq	)
         UpperCamelCase_			  =						completed

         return stepped, completed, reset






     def 	UpperCAmelCase_				(				self	)->     str:
         UpperCamelCase_			  =						False
         UpperCamelCase_			  =						[]






     def 	UpperCAmelCase_				(				self	)->     Union[str, Any]:
         if self.completed:
             # since this can be completed without reaching max height
             return 0
         else:
             return self.seqlen - len(self.current_seq	)






     def 	UpperCAmelCase_				(				self		,						_lowercase=False	)->     Optional[Any]:
         UpperCamelCase_			  =						DisjunctiveConstraint(self.token_ids	)

         if stateful:
             UpperCamelCase_			  =						self.seqlen
             UpperCamelCase_			  =						self.current_seq
             UpperCamelCase_			  =						self.completed

         return new_constraint






class 						__magic_name__					:






     def __init__(				self		,						_lowercase	)->     Dict:
         UpperCamelCase_			  =						constraints

         # max # of steps required to fulfill a given constraint
         UpperCamelCase_			  =						max([c.seqlen for c in constraints]	)
         UpperCamelCase_			  =						len(_lowercase	)
         UpperCamelCase_			  =						False

         self.init_state()






     def 	UpperCAmelCase_				(				self	)->     str:
         UpperCamelCase_			  =						[]
         UpperCamelCase_			  =						None
         UpperCamelCase_			  =						[constraint.copy(stateful=_lowercase	) for constraint in self.constraints]






     def 	UpperCAmelCase_				(				self	)->     List[Any]:
         UpperCamelCase_			  =						0
         if self.inprogress_constraint:
             # extra points for having a constraint mid-fulfilled
             add += self.max_seqlen - self.inprogress_constraint.remaining()

         return (len(self.complete_constraints	) * self.max_seqlen) + add






     def 	UpperCAmelCase_				(				self	)->     List[Any]:
         UpperCamelCase_			  =						[]
         if self.inprogress_constraint is None:
             for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
                 UpperCamelCase_			  =						constraint.advance()
                 if isinstance(_lowercase		,						_lowercase	):
                     token_list.append(_lowercase	)
                 elif isinstance(_lowercase		,						_lowercase	):
                     token_list.extend(_lowercase	)
         else:
             UpperCamelCase_			  =						self.inprogress_constraint.advance()
             if isinstance(_lowercase		,						_lowercase	):
                 token_list.append(_lowercase	)
             elif isinstance(_lowercase		,						_lowercase	):
                 token_list.extend(_lowercase	)

         if len(_lowercase	) == 0:
             return None
         else:
             return token_list






     def 	UpperCAmelCase_				(				self		,						_lowercase	)->     str:
         self.init_state()

         if token_ids is not None:
             for token in token_ids:
                 # completes or steps **one** constraint
                 UpperCamelCase_  ,       UpperCamelCase_			  =						self.add(_lowercase	)

                 # the entire list of constraints are fulfilled
                 if self.completed:
                     break






     def 	UpperCAmelCase_				(				self		,						_lowercase	)->     Union[str, Any]:
         if not isinstance(_lowercase		,						_lowercase	):
             raise ValueError(F"`token_id` should be an `int`, but is `{token_id}`."	)

         UpperCamelCase_  ,       UpperCamelCase_			  =						False, False

         if self.completed:
             UpperCamelCase_			  =						True
             UpperCamelCase_			  =						False
             return complete, stepped

         if self.inprogress_constraint is not None:
             # In the middle of fulfilling a constraint. If the `token_id` *does* makes an incremental progress to current
             # job, simply update the state

             UpperCamelCase_  ,       UpperCamelCase_  ,       UpperCamelCase_			  =						self.inprogress_constraint.update(_lowercase	)
             if reset:
                 # 1. If the next token breaks the progress, then we must restart.
                 #     e.g. constraint = "I love pies" and sequence so far is "I love" but `token_id` == "books".

                 #     But that doesn't mean we self.init_state(), since we only reset the state for this particular
                 #     constraint, not the full list of constraints.

                 self.pending_constraints.append(self.inprogress_constraint.copy(stateful=_lowercase	)	)
                 UpperCamelCase_			  =						None

             if complete:
                 # 2. If the next token completes the constraint, move it to completed list, set
                 #     inprogress to None. If there are no pending constraints either, then this full list of constraints
                 #     is complete.

                 self.complete_constraints.append(self.inprogress_constraint	)
                 UpperCamelCase_			  =						None

                 if len(self.pending_constraints	) == 0:
                     # we're done!
                     UpperCamelCase_			  =						True

         else:
             # Not in the middle of fulfilling a constraint. So does this `token_id` helps us step towards any of our list
             # of constraints?

             for cidx, pending_constraint in enumerate(self.pending_constraints	):
                 if pending_constraint.does_advance(_lowercase	):
                     UpperCamelCase_  ,       UpperCamelCase_  ,       UpperCamelCase_			  =						pending_constraint.update(_lowercase	)

                     if not stepped:
                         raise Exception(
                             "`constraint.update(token_id)` is not yielding incremental progress, "
                             "even though `constraint.does_advance(token_id)` is true."	)

                     if complete:
                         self.complete_constraints.append(_lowercase	)
                         UpperCamelCase_			  =						None

                     if not complete and stepped:
                         UpperCamelCase_			  =						pending_constraint

                     if complete or stepped:
                         # If we made any progress at all, then it's at least not a "pending constraint".

                         UpperCamelCase_			  =						(
                             self.pending_constraints[:cidx] + self.pending_constraints[cidx + 1 :]
                         )

                         if len(self.pending_constraints	) == 0 and self.inprogress_constraint is None:
                             # If there's no longer any pending after this and no inprogress either, then we must be
                             # complete.

                             UpperCamelCase_			  =						True

                         break  # prevent accidentally stepping through multiple constraints with just one token.

         return complete, stepped






     def 	UpperCAmelCase_				(				self		,						_lowercase=True	)->     List[str]:
         UpperCamelCase_			  =						ConstraintListState(self.constraints	)  # we actually never though self.constraints objects
         # throughout this process. So it's at initialization state.

         if stateful:
             UpperCamelCase_			  =						[
                 constraint.copy(stateful=_lowercase	) for constraint in self.complete_constraints
             ]
             if self.inprogress_constraint is not None:
                 UpperCamelCase_			  =						self.inprogress_constraint.copy(stateful=_lowercase	)
             UpperCamelCase_			  =						[constraint.copy() for constraint in self.pending_constraints]

         return new_state



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 						__magic_name__					:






      @staticmethod
      def 	UpperCAmelCase_				(				*_lowercase		,						**_lowercase	)->     Optional[int]:
          pass






@is_pipeline_test
@require_vision
@require_torch
class 						__magic_name__					(							unittest.TestCase				):
     UpperCamelCase_	:Optional[Any]										=      MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING






     def 	UpperCAmelCase_				(				self		,						_lowercase		,						_lowercase		,						_lowercase	)->     Union[str, Any]:
         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 	UpperCAmelCase_				(				self		,						_lowercase		,						_lowercase	)->     Union[str, Any]:
         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 	UpperCAmelCase_				(				self	)->     str:
         pass






     @require_torch
     def 	UpperCAmelCase_				(				self	)->     List[Any]:
         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.64		,						)

         self.assertEqual(
             nested_simplify(_lowercase		,						decimals=4	)		,						[
                 {"score": 0.7_235, "label": "cat", "box": {"xmin": 204, "ymin": 167, "xmax": 232, "ymax": 190}},
                 {"score": 0.7_218, "label": "remote", "box": {"xmin": 204, "ymin": 167, "xmax": 232, "ymax": 190}},
                 {"score": 0.7_184, "label": "couch", "box": {"xmin": 204, "ymin": 167, "xmax": 232, "ymax": 190}},
                 {"score": 0.6_748, "label": "remote", "box": {"xmin": 571, "ymin": 83, "xmax": 598, "ymax": 103}},
                 {"score": 0.6_656, "label": "cat", "box": {"xmin": 571, "ymin": 83, "xmax": 598, "ymax": 103}},
                 {"score": 0.6_614, "label": "couch", "box": {"xmin": 571, "ymin": 83, "xmax": 598, "ymax": 103}},
                 {"score": 0.6_456, "label": "remote", "box": {"xmin": 494, "ymin": 105, "xmax": 521, "ymax": 127}},
                 {"score": 0.642, "label": "remote", "box": {"xmin": 67, "ymin": 274, "xmax": 93, "ymax": 297}},
                 {"score": 0.6_419, "label": "cat", "box": {"xmin": 494, "ymin": 105, "xmax": 521, "ymax": 127}},
             ]		,						)

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

         self.assertEqual(
             nested_simplify(_lowercase		,						decimals=4	)		,						[
                 [
                     {"score": 0.7_235, "label": "cat", "box": {"xmin": 204, "ymin": 167, "xmax": 232, "ymax": 190}},
                     {"score": 0.7_218, "label": "remote", "box": {"xmin": 204, "ymin": 167, "xmax": 232, "ymax": 190}},
                     {"score": 0.7_184, "label": "couch", "box": {"xmin": 204, "ymin": 167, "xmax": 232, "ymax": 190}},
                     {"score": 0.6_748, "label": "remote", "box": {"xmin": 571, "ymin": 83, "xmax": 598, "ymax": 103}},
                     {"score": 0.6_656, "label": "cat", "box": {"xmin": 571, "ymin": 83, "xmax": 598, "ymax": 103}},
                     {"score": 0.6_614, "label": "couch", "box": {"xmin": 571, "ymin": 83, "xmax": 598, "ymax": 103}},
                     {"score": 0.6_456, "label": "remote", "box": {"xmin": 494, "ymin": 105, "xmax": 521, "ymax": 127}},
                     {"score": 0.642, "label": "remote", "box": {"xmin": 67, "ymin": 274, "xmax": 93, "ymax": 297}},
                     {"score": 0.6_419, "label": "cat", "box": {"xmin": 494, "ymin": 105, "xmax": 521, "ymax": 127}},
                 ]
             ]		,						)






     @require_torch
     @slow
     def 	UpperCAmelCase_				(				self	)->     Any:
         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_868, "label": "cat", "box": {"xmin": 324, "ymin": 20, "xmax": 640, "ymax": 373}},
                 {"score": 0.277, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 177, "ymax": 115}},
                 {"score": 0.2_537, "label": "cat", "box": {"xmin": 1, "ymin": 55, "xmax": 315, "ymax": 472}},
                 {"score": 0.1_474, "label": "remote", "box": {"xmin": 335, "ymin": 74, "xmax": 371, "ymax": 187}},
                 {"score": 0.1_208, "label": "couch", "box": {"xmin": 4, "ymin": 0, "xmax": 642, "ymax": 476}},
             ]		,						)

         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_868, "label": "cat", "box": {"xmin": 324, "ymin": 20, "xmax": 640, "ymax": 373}},
                     {"score": 0.277, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 177, "ymax": 115}},
                     {"score": 0.2_537, "label": "cat", "box": {"xmin": 1, "ymin": 55, "xmax": 315, "ymax": 472}},
                     {"score": 0.1_474, "label": "remote", "box": {"xmin": 335, "ymin": 74, "xmax": 371, "ymax": 187}},
                     {"score": 0.1_208, "label": "couch", "box": {"xmin": 4, "ymin": 0, "xmax": 642, "ymax": 476}},
                 ],
                 [
                     {"score": 0.2_868, "label": "cat", "box": {"xmin": 324, "ymin": 20, "xmax": 640, "ymax": 373}},
                     {"score": 0.277, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 177, "ymax": 115}},
                     {"score": 0.2_537, "label": "cat", "box": {"xmin": 1, "ymin": 55, "xmax": 315, "ymax": 472}},
                     {"score": 0.1_474, "label": "remote", "box": {"xmin": 335, "ymin": 74, "xmax": 371, "ymax": 187}},
                     {"score": 0.1_208, "label": "couch", "box": {"xmin": 4, "ymin": 0, "xmax": 642, "ymax": 476}},
                 ],
             ]		,						)






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






     @require_torch
     @slow
     def 	UpperCAmelCase_				(				self	)->     Optional[Any]:
         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_868, "label": "cat", "box": {"xmin": 324, "ymin": 20, "xmax": 640, "ymax": 373}},
                 {"score": 0.277, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 177, "ymax": 115}},
                 {"score": 0.2_537, "label": "cat", "box": {"xmin": 1, "ymin": 55, "xmax": 315, "ymax": 472}},
             ]		,						)






     @require_torch
     @slow
     def 	UpperCAmelCase_				(				self	)->     Optional[int]:
         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_868, "label": "cat", "box": {"xmin": 324, "ymin": 20, "xmax": 640, "ymax": 373}},
                 {"score": 0.277, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 177, "ymax": 115}},
             ]		,						)
