




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







											@staticmethod
											def   __lowerCAmelCase     (    *lowerCAmelCase_			:    Optional[Any]				,     **lowerCAmelCase_			:    int   )     ->				Tuple:


																		"""simple docstring"""


																		pass

@is_pipeline_test
@require_vision
@require_torch
class      A       (						unittest.TestCase       ):
							lowercase_							     =							MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING







							def   __lowerCAmelCase     (    self			:    Dict				,     lowerCAmelCase_			:    Union[str, Any]				,     lowerCAmelCase_			:    Optional[int]				,     lowerCAmelCase_			:    Optional[int]   )     ->				List[Any]:


														"""simple docstring"""


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

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







							def   __lowerCAmelCase     (    self			:    Optional[int]				,     lowerCAmelCase_			:    str				,     lowerCAmelCase_			:    Union[str, Any]   )     ->				Dict:


														"""simple docstring"""


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

														_a      	=							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   __lowerCAmelCase     (    self			:    int   )     ->				Dict:


														"""simple docstring"""


														pass







							@require_torch
							def   __lowerCAmelCase     (    self			:    Tuple   )     ->				Optional[Any]:


														"""simple docstring"""


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

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

														self.assertEqual(
														    nested_simplify(_lowerCAmelCase				,     decimals=4   )				,     [
														        {'''score''': 0.7_2_3_5, '''label''': '''cat''', '''box''': {'''xmin''': 2_04, '''ymin''': 1_67, '''xmax''': 2_32, '''ymax''': 1_90}},
														        {'''score''': 0.7_2_1_8, '''label''': '''remote''', '''box''': {'''xmin''': 2_04, '''ymin''': 1_67, '''xmax''': 2_32, '''ymax''': 1_90}},
														        {'''score''': 0.7_1_8_4, '''label''': '''couch''', '''box''': {'''xmin''': 2_04, '''ymin''': 1_67, '''xmax''': 2_32, '''ymax''': 1_90}},
														        {'''score''': 0.6_7_4_8, '''label''': '''remote''', '''box''': {'''xmin''': 5_71, '''ymin''': 83, '''xmax''': 5_98, '''ymax''': 1_03}},
														        {'''score''': 0.6_6_5_6, '''label''': '''cat''', '''box''': {'''xmin''': 5_71, '''ymin''': 83, '''xmax''': 5_98, '''ymax''': 1_03}},
														        {'''score''': 0.6_6_1_4, '''label''': '''couch''', '''box''': {'''xmin''': 5_71, '''ymin''': 83, '''xmax''': 5_98, '''ymax''': 1_03}},
														        {'''score''': 0.6_4_5_6, '''label''': '''remote''', '''box''': {'''xmin''': 4_94, '''ymin''': 1_05, '''xmax''': 5_21, '''ymax''': 1_27}},
														        {'''score''': 0.6_4_2, '''label''': '''remote''', '''box''': {'''xmin''': 67, '''ymin''': 2_74, '''xmax''': 93, '''ymax''': 2_97}},
														        {'''score''': 0.6_4_1_9, '''label''': '''cat''', '''box''': {'''xmin''': 4_94, '''ymin''': 1_05, '''xmax''': 5_21, '''ymax''': 1_27}},
														    ]				,     )

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

														self.assertEqual(
														    nested_simplify(_lowerCAmelCase				,     decimals=4   )				,     [
														        [
														            {'''score''': 0.7_2_3_5, '''label''': '''cat''', '''box''': {'''xmin''': 2_04, '''ymin''': 1_67, '''xmax''': 2_32, '''ymax''': 1_90}},
														            {'''score''': 0.7_2_1_8, '''label''': '''remote''', '''box''': {'''xmin''': 2_04, '''ymin''': 1_67, '''xmax''': 2_32, '''ymax''': 1_90}},
														            {'''score''': 0.7_1_8_4, '''label''': '''couch''', '''box''': {'''xmin''': 2_04, '''ymin''': 1_67, '''xmax''': 2_32, '''ymax''': 1_90}},
														            {'''score''': 0.6_7_4_8, '''label''': '''remote''', '''box''': {'''xmin''': 5_71, '''ymin''': 83, '''xmax''': 5_98, '''ymax''': 1_03}},
														            {'''score''': 0.6_6_5_6, '''label''': '''cat''', '''box''': {'''xmin''': 5_71, '''ymin''': 83, '''xmax''': 5_98, '''ymax''': 1_03}},
														            {'''score''': 0.6_6_1_4, '''label''': '''couch''', '''box''': {'''xmin''': 5_71, '''ymin''': 83, '''xmax''': 5_98, '''ymax''': 1_03}},
														            {'''score''': 0.6_4_5_6, '''label''': '''remote''', '''box''': {'''xmin''': 4_94, '''ymin''': 1_05, '''xmax''': 5_21, '''ymax''': 1_27}},
														            {'''score''': 0.6_4_2, '''label''': '''remote''', '''box''': {'''xmin''': 67, '''ymin''': 2_74, '''xmax''': 93, '''ymax''': 2_97}},
														            {'''score''': 0.6_4_1_9, '''label''': '''cat''', '''box''': {'''xmin''': 4_94, '''ymin''': 1_05, '''xmax''': 5_21, '''ymax''': 1_27}},
														        ]
														    ]				,     )







							@require_torch
							@slow
							def   __lowerCAmelCase     (    self			:    Tuple   )     ->				str:


														"""simple docstring"""


														_a      	=							pipeline('''zero-shot-object-detection'''   )

														_a      	=							object_detector(
														    '''http://images.cocodataset.org/val2017/000000039769.jpg'''				,     candidate_labels=['''cat''', '''remote''', '''couch''']				,     )
														self.assertEqual(
														    nested_simplify(_lowerCAmelCase				,     decimals=4   )				,     [
														        {'''score''': 0.2_8_6_8, '''label''': '''cat''', '''box''': {'''xmin''': 3_24, '''ymin''': 20, '''xmax''': 6_40, '''ymax''': 3_73}},
														        {'''score''': 0.2_7_7, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 1_77, '''ymax''': 1_15}},
														        {'''score''': 0.2_5_3_7, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 3_15, '''ymax''': 4_72}},
														        {'''score''': 0.1_4_7_4, '''label''': '''remote''', '''box''': {'''xmin''': 3_35, '''ymin''': 74, '''xmax''': 3_71, '''ymax''': 1_87}},
														        {'''score''': 0.1_2_0_8, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 6_42, '''ymax''': 4_76}},
														    ]				,     )

														_a      	=							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_8_6_8, '''label''': '''cat''', '''box''': {'''xmin''': 3_24, '''ymin''': 20, '''xmax''': 6_40, '''ymax''': 3_73}},
														            {'''score''': 0.2_7_7, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 1_77, '''ymax''': 1_15}},
														            {'''score''': 0.2_5_3_7, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 3_15, '''ymax''': 4_72}},
														            {'''score''': 0.1_4_7_4, '''label''': '''remote''', '''box''': {'''xmin''': 3_35, '''ymin''': 74, '''xmax''': 3_71, '''ymax''': 1_87}},
														            {'''score''': 0.1_2_0_8, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 6_42, '''ymax''': 4_76}},
														        ],
														        [
														            {'''score''': 0.2_8_6_8, '''label''': '''cat''', '''box''': {'''xmin''': 3_24, '''ymin''': 20, '''xmax''': 6_40, '''ymax''': 3_73}},
														            {'''score''': 0.2_7_7, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 1_77, '''ymax''': 1_15}},
														            {'''score''': 0.2_5_3_7, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 3_15, '''ymax''': 4_72}},
														            {'''score''': 0.1_4_7_4, '''label''': '''remote''', '''box''': {'''xmin''': 3_35, '''ymin''': 74, '''xmax''': 3_71, '''ymax''': 1_87}},
														            {'''score''': 0.1_2_0_8, '''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			:    Optional[int]   )     ->				int:


														"""simple docstring"""


														pass







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


														"""simple docstring"""


														_a      	=							0.2
														_a      	=							pipeline('''zero-shot-object-detection'''   )

														_a      	=							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_8_6_8, '''label''': '''cat''', '''box''': {'''xmin''': 3_24, '''ymin''': 20, '''xmax''': 6_40, '''ymax''': 3_73}},
														        {'''score''': 0.2_7_7, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 1_77, '''ymax''': 1_15}},
														        {'''score''': 0.2_5_3_7, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 3_15, '''ymax''': 4_72}},
														    ]				,     )







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


														"""simple docstring"""


														_a      	=							2
														_a      	=							pipeline('''zero-shot-object-detection'''   )

														_a      	=							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_8_6_8, '''label''': '''cat''', '''box''': {'''xmin''': 3_24, '''ymin''': 20, '''xmax''': 6_40, '''ymax''': 3_73}},
														        {'''score''': 0.2_7_7, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 1_77, '''ymax''': 1_15}},
														    ]				,     )








from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase							:       str					 =	{
    """configuration_pegasus_x""": ["""PEGASUS_X_PRETRAINED_CONFIG_ARCHIVE_MAP""", """PegasusXConfig"""],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowerCAmelCase							:       Optional[Any]					 =	[
							    """PEGASUS_X_PRETRAINED_MODEL_ARCHIVE_LIST""",
							    """PegasusXForConditionalGeneration""",
							    """PegasusXModel""",
							    """PegasusXPreTrainedModel""",
							]


if TYPE_CHECKING:
							from .configuration_pegasus_x import PEGASUS_X_PRETRAINED_CONFIG_ARCHIVE_MAP, PegasusXConfig

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_pegasus_x import (
														    PEGASUS_X_PRETRAINED_MODEL_ARCHIVE_LIST,
														    PegasusXForConditionalGeneration,
														    PegasusXModel,
														    PegasusXPreTrainedModel,
														)


else:
							import sys

							lowerCAmelCase							:       str					 =	_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



