





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






										@staticmethod
										def     snake_case     (			*lowerCAmelCase__		:   Union[str, Any],			**lowerCAmelCase__		:   Optional[Any]							)     ->				Dict:




																'''simple docstring'''



																pass




@is_pipeline_test
@require_vision
@require_torch
class 			_a						(				unittest.TestCase    ):
				UpperCamelCase								=   MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING






				def     snake_case     (			self		:   Any,			lowerCAmelCase__		:   int,			lowerCAmelCase__		:   int,			lowerCAmelCase__		:   Dict							)     ->				Tuple:




										'''simple docstring'''



										_UpperCamelCase      : List[str]         =   pipeline(
										    '''zero-shot-object-detection''',			model='''hf-internal-testing/tiny-random-owlvit-object-detection'''							)

										_UpperCamelCase      : List[Any]         =   [
										    {
										        '''image''': '''./tests/fixtures/tests_samples/COCO/000000039769.png''',
										        '''candidate_labels''': ['''cat''', '''remote''', '''couch'''],
										    }
										]
										return object_detector, examples






				def     snake_case     (			self		:   Dict,			lowerCAmelCase__		:   List[str],			lowerCAmelCase__		:   Optional[Any]							)     ->				Optional[int]:




										'''simple docstring'''



										_UpperCamelCase      : List[str]         =   object_detector(examples[0],			threshold=0.0							)

										_UpperCamelCase      : Union[str, Any]         =   len(lowerCAmelCase__							)
										self.assertGreater(lowerCAmelCase__,			0							)
										self.assertEqual(
										    lowerCAmelCase__,			[
										        {
										            '''score''': ANY(lowerCAmelCase__							),
										            '''label''': ANY(lowerCAmelCase__							),
										            '''box''': {'''xmin''': ANY(lowerCAmelCase__							), '''ymin''': ANY(lowerCAmelCase__							), '''xmax''': ANY(lowerCAmelCase__							), '''ymax''': ANY(lowerCAmelCase__							)},
										        }
										        for i in range(lowerCAmelCase__							)
										    ],			)






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




										'''simple docstring'''



										pass






				@require_torch
				def     snake_case     (			self		:   Optional[int]							)     ->				List[str]:




										'''simple docstring'''



										_UpperCamelCase      : int         =   pipeline(
										    '''zero-shot-object-detection''',			model='''hf-internal-testing/tiny-random-owlvit-object-detection'''							)

										_UpperCamelCase      : str         =   object_detector(
										    '''./tests/fixtures/tests_samples/COCO/000000039769.png''',			candidate_labels=['''cat''', '''remote''', '''couch'''],			threshold=0.64,			)

										self.assertEqual(
										    nested_simplify(lowerCAmelCase__,			decimals=4							),			[
										        {'''score''': 0.7_235, '''label''': '''cat''', '''box''': {'''xmin''': 2_0_4, '''ymin''': 1_6_7, '''xmax''': 2_3_2, '''ymax''': 1_9_0}},
										        {'''score''': 0.7_218, '''label''': '''remote''', '''box''': {'''xmin''': 2_0_4, '''ymin''': 1_6_7, '''xmax''': 2_3_2, '''ymax''': 1_9_0}},
										        {'''score''': 0.7_184, '''label''': '''couch''', '''box''': {'''xmin''': 2_0_4, '''ymin''': 1_6_7, '''xmax''': 2_3_2, '''ymax''': 1_9_0}},
										        {'''score''': 0.6_748, '''label''': '''remote''', '''box''': {'''xmin''': 5_7_1, '''ymin''': 8_3, '''xmax''': 5_9_8, '''ymax''': 1_0_3}},
										        {'''score''': 0.6_656, '''label''': '''cat''', '''box''': {'''xmin''': 5_7_1, '''ymin''': 8_3, '''xmax''': 5_9_8, '''ymax''': 1_0_3}},
										        {'''score''': 0.6_614, '''label''': '''couch''', '''box''': {'''xmin''': 5_7_1, '''ymin''': 8_3, '''xmax''': 5_9_8, '''ymax''': 1_0_3}},
										        {'''score''': 0.6_456, '''label''': '''remote''', '''box''': {'''xmin''': 4_9_4, '''ymin''': 1_0_5, '''xmax''': 5_2_1, '''ymax''': 1_2_7}},
										        {'''score''': 0.642, '''label''': '''remote''', '''box''': {'''xmin''': 6_7, '''ymin''': 2_7_4, '''xmax''': 9_3, '''ymax''': 2_9_7}},
										        {'''score''': 0.6_419, '''label''': '''cat''', '''box''': {'''xmin''': 4_9_4, '''ymin''': 1_0_5, '''xmax''': 5_2_1, '''ymax''': 1_2_7}},
										    ],			)

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

										self.assertEqual(
										    nested_simplify(lowerCAmelCase__,			decimals=4							),			[
										        [
										            {'''score''': 0.7_235, '''label''': '''cat''', '''box''': {'''xmin''': 2_0_4, '''ymin''': 1_6_7, '''xmax''': 2_3_2, '''ymax''': 1_9_0}},
										            {'''score''': 0.7_218, '''label''': '''remote''', '''box''': {'''xmin''': 2_0_4, '''ymin''': 1_6_7, '''xmax''': 2_3_2, '''ymax''': 1_9_0}},
										            {'''score''': 0.7_184, '''label''': '''couch''', '''box''': {'''xmin''': 2_0_4, '''ymin''': 1_6_7, '''xmax''': 2_3_2, '''ymax''': 1_9_0}},
										            {'''score''': 0.6_748, '''label''': '''remote''', '''box''': {'''xmin''': 5_7_1, '''ymin''': 8_3, '''xmax''': 5_9_8, '''ymax''': 1_0_3}},
										            {'''score''': 0.6_656, '''label''': '''cat''', '''box''': {'''xmin''': 5_7_1, '''ymin''': 8_3, '''xmax''': 5_9_8, '''ymax''': 1_0_3}},
										            {'''score''': 0.6_614, '''label''': '''couch''', '''box''': {'''xmin''': 5_7_1, '''ymin''': 8_3, '''xmax''': 5_9_8, '''ymax''': 1_0_3}},
										            {'''score''': 0.6_456, '''label''': '''remote''', '''box''': {'''xmin''': 4_9_4, '''ymin''': 1_0_5, '''xmax''': 5_2_1, '''ymax''': 1_2_7}},
										            {'''score''': 0.642, '''label''': '''remote''', '''box''': {'''xmin''': 6_7, '''ymin''': 2_7_4, '''xmax''': 9_3, '''ymax''': 2_9_7}},
										            {'''score''': 0.6_419, '''label''': '''cat''', '''box''': {'''xmin''': 4_9_4, '''ymin''': 1_0_5, '''xmax''': 5_2_1, '''ymax''': 1_2_7}},
										        ]
										    ],			)






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




										'''simple docstring'''



										_UpperCamelCase      : Any         =   pipeline('''zero-shot-object-detection'''							)

										_UpperCamelCase      : Dict         =   object_detector(
										    '''http://images.cocodataset.org/val2017/000000039769.jpg''',			candidate_labels=['''cat''', '''remote''', '''couch'''],			)
										self.assertEqual(
										    nested_simplify(lowerCAmelCase__,			decimals=4							),			[
										        {'''score''': 0.2_868, '''label''': '''cat''', '''box''': {'''xmin''': 3_2_4, '''ymin''': 2_0, '''xmax''': 6_4_0, '''ymax''': 3_7_3}},
										        {'''score''': 0.277, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_2, '''xmax''': 1_7_7, '''ymax''': 1_1_5}},
										        {'''score''': 0.2_537, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 5_5, '''xmax''': 3_1_5, '''ymax''': 4_7_2}},
										        {'''score''': 0.1_474, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_5, '''ymin''': 7_4, '''xmax''': 3_7_1, '''ymax''': 1_8_7}},
										        {'''score''': 0.1_208, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 6_4_2, '''ymax''': 4_7_6}},
										    ],			)

										_UpperCamelCase      : List[Any]         =   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(lowerCAmelCase__,			decimals=4							),			[
										        [
										            {'''score''': 0.2_868, '''label''': '''cat''', '''box''': {'''xmin''': 3_2_4, '''ymin''': 2_0, '''xmax''': 6_4_0, '''ymax''': 3_7_3}},
										            {'''score''': 0.277, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_2, '''xmax''': 1_7_7, '''ymax''': 1_1_5}},
										            {'''score''': 0.2_537, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 5_5, '''xmax''': 3_1_5, '''ymax''': 4_7_2}},
										            {'''score''': 0.1_474, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_5, '''ymin''': 7_4, '''xmax''': 3_7_1, '''ymax''': 1_8_7}},
										            {'''score''': 0.1_208, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 6_4_2, '''ymax''': 4_7_6}},
										        ],
										        [
										            {'''score''': 0.2_868, '''label''': '''cat''', '''box''': {'''xmin''': 3_2_4, '''ymin''': 2_0, '''xmax''': 6_4_0, '''ymax''': 3_7_3}},
										            {'''score''': 0.277, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_2, '''xmax''': 1_7_7, '''ymax''': 1_1_5}},
										            {'''score''': 0.2_537, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 5_5, '''xmax''': 3_1_5, '''ymax''': 4_7_2}},
										            {'''score''': 0.1_474, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_5, '''ymin''': 7_4, '''xmax''': 3_7_1, '''ymax''': 1_8_7}},
										            {'''score''': 0.1_208, '''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     snake_case     (			self		:   Any							)     ->				Dict:




										'''simple docstring'''



										pass






				@require_torch
				@slow
				def     snake_case     (			self		:   Any							)     ->				Dict:




										'''simple docstring'''



										_UpperCamelCase      : Union[str, Any]         =   0.2
										_UpperCamelCase      : Optional[Any]         =   pipeline('''zero-shot-object-detection'''							)

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






				@require_torch
				@slow
				def     snake_case     (			self		:   int							)     ->				Tuple:




										'''simple docstring'''



										_UpperCamelCase      : Tuple         =   2
										_UpperCamelCase      : str         =   pipeline('''zero-shot-object-detection'''							)

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










"""simple docstring"""




def 	a_    (							_lowercase	,						_lowercase       ):
						if discount_rate < 0:
												raise ValueError('''Discount rate cannot be negative'''       )
						if not cash_flows:
												raise ValueError('''Cash flows list cannot be empty'''       )
						_UpperCamelCase      : Optional[int]         =   sum(
						    cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(_lowercase       )       )
						return round(_lowercase	,						ndigits=2       )


if __name__ == "__main__":
						import doctest

						doctest.testmod()



