


import unittest

from transformers import (
    MODEL_FOR_OBJECT_DETECTION_MAPPING,
    AutoFeatureExtractor,
    AutoModelForObjectDetection,
    ObjectDetectionPipeline,
    is_vision_available,
    pipeline,
)
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_pytesseract,
    require_tf,
    require_timm,
    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 						UpperCamelCase__					(     *_UpperCAmelCase		,				**_UpperCAmelCase ):
          pass







@is_pipeline_test
@require_vision
@require_timm
@require_torch
class lowerCAmelCase_						(			unittest.TestCase	):

 '''simple docstring'''

 __snake_case												=  MODEL_FOR_OBJECT_DETECTION_MAPPING



 def 						UpperCamelCase__					(     self		,				_UpperCAmelCase		,				_UpperCAmelCase		,				_UpperCAmelCase ):
       snake_case_	=				ObjectDetectionPipeline(model=_UpperCAmelCase		,				image_processor=_UpperCAmelCase )
       return object_detector, ["./tests/fixtures/tests_samples/COCO/000000039769.png"]



 def 						UpperCamelCase__					(     self		,				_UpperCAmelCase		,				_UpperCAmelCase ):
       snake_case_	=				object_detector('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		,				threshold=0.0 )

       self.assertGreater(len(_UpperCAmelCase )		,				0 )
       for detected_object in outputs:
             self.assertEqual(
                 _UpperCAmelCase		,				{
                     '''score''': ANY(_UpperCAmelCase ),
                     '''label''': ANY(_UpperCAmelCase ),
                     '''box''': {'''xmin''': ANY(_UpperCAmelCase ), '''ymin''': ANY(_UpperCAmelCase ), '''xmax''': ANY(_UpperCAmelCase ), '''ymax''': ANY(_UpperCAmelCase )},
                 }		,				)

       import datasets

       snake_case_	=				datasets.load_dataset('''hf-internal-testing/fixtures_image_utils'''		,				'''image'''		,				split='''test''' )

       snake_case_	=				[
           Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png''' ),
           '''http://images.cocodataset.org/val2017/000000039769.jpg''',
           # RGBA
           dataset[0]['''file'''],
           # LA
           dataset[1]['''file'''],
           # L
           dataset[2]['''file'''],
       ]
       snake_case_	=				object_detector(_UpperCAmelCase		,				threshold=0.0 )

       self.assertEqual(len(_UpperCAmelCase )		,				len(_UpperCAmelCase ) )
       for outputs in batch_outputs:
             self.assertGreater(len(_UpperCAmelCase )		,				0 )
             for detected_object in outputs:
                   self.assertEqual(
                       _UpperCAmelCase		,				{
                           '''score''': ANY(_UpperCAmelCase ),
                           '''label''': ANY(_UpperCAmelCase ),
                           '''box''': {'''xmin''': ANY(_UpperCAmelCase ), '''ymin''': ANY(_UpperCAmelCase ), '''xmax''': ANY(_UpperCAmelCase ), '''ymax''': ANY(_UpperCAmelCase )},
                       }		,				)



 @require_tf
 @unittest.skip('''Object detection not implemented in TF''' )
 def 						UpperCamelCase__					(     self ):
       pass



 @require_torch
 def 						UpperCamelCase__					(     self ):
       snake_case_	=				'''hf-internal-testing/tiny-detr-mobilenetsv3'''

       snake_case_	=				AutoModelForObjectDetection.from_pretrained(_UpperCAmelCase )
       snake_case_	=				AutoFeatureExtractor.from_pretrained(_UpperCAmelCase )
       snake_case_	=				ObjectDetectionPipeline(model=_UpperCAmelCase		,				feature_extractor=_UpperCAmelCase )

       snake_case_	=				object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''		,				threshold=0.0 )

       self.assertEqual(
           nested_simplify(_UpperCAmelCase		,				decimals=4 )		,				[
               {'''score''': 0.3_376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_59, '''ymin''': 1_20, '''xmax''': 4_80, '''ymax''': 3_59}},
               {'''score''': 0.3_376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_59, '''ymin''': 1_20, '''xmax''': 4_80, '''ymax''': 3_59}},
           ]		,				)

       snake_case_	=				object_detector(
           [
               '''http://images.cocodataset.org/val2017/000000039769.jpg''',
               '''http://images.cocodataset.org/val2017/000000039769.jpg''',
           ]		,				threshold=0.0		,				)

       self.assertEqual(
           nested_simplify(_UpperCAmelCase		,				decimals=4 )		,				[
               [
                   {'''score''': 0.3_376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_59, '''ymin''': 1_20, '''xmax''': 4_80, '''ymax''': 3_59}},
                   {'''score''': 0.3_376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_59, '''ymin''': 1_20, '''xmax''': 4_80, '''ymax''': 3_59}},
               ],
               [
                   {'''score''': 0.3_376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_59, '''ymin''': 1_20, '''xmax''': 4_80, '''ymax''': 3_59}},
                   {'''score''': 0.3_376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_59, '''ymin''': 1_20, '''xmax''': 4_80, '''ymax''': 3_59}},
               ],
           ]		,				)



 @require_torch
 @slow
 def 						UpperCamelCase__					(     self ):
       snake_case_	=				'''facebook/detr-resnet-50'''

       snake_case_	=				AutoModelForObjectDetection.from_pretrained(_UpperCAmelCase )
       snake_case_	=				AutoFeatureExtractor.from_pretrained(_UpperCAmelCase )
       snake_case_	=				ObjectDetectionPipeline(model=_UpperCAmelCase		,				feature_extractor=_UpperCAmelCase )

       snake_case_	=				object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg''' )
       self.assertEqual(
           nested_simplify(_UpperCAmelCase		,				decimals=4 )		,				[
               {'''score''': 0.9_982, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 70, '''xmax''': 1_75, '''ymax''': 1_17}},
               {'''score''': 0.9_960, '''label''': '''remote''', '''box''': {'''xmin''': 3_33, '''ymin''': 72, '''xmax''': 3_68, '''ymax''': 1_87}},
               {'''score''': 0.9_955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_39, '''ymax''': 4_73}},
               {'''score''': 0.9_988, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 3_14, '''ymax''': 4_70}},
               {'''score''': 0.9_987, '''label''': '''cat''', '''box''': {'''xmin''': 3_45, '''ymin''': 23, '''xmax''': 6_40, '''ymax''': 3_68}},
           ]		,				)

       snake_case_	=				object_detector(
           [
               '''http://images.cocodataset.org/val2017/000000039769.jpg''',
               '''http://images.cocodataset.org/val2017/000000039769.jpg''',
           ] )
       self.assertEqual(
           nested_simplify(_UpperCAmelCase		,				decimals=4 )		,				[
               [
                   {'''score''': 0.9_982, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 70, '''xmax''': 1_75, '''ymax''': 1_17}},
                   {'''score''': 0.9_960, '''label''': '''remote''', '''box''': {'''xmin''': 3_33, '''ymin''': 72, '''xmax''': 3_68, '''ymax''': 1_87}},
                   {'''score''': 0.9_955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_39, '''ymax''': 4_73}},
                   {'''score''': 0.9_988, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 3_14, '''ymax''': 4_70}},
                   {'''score''': 0.9_987, '''label''': '''cat''', '''box''': {'''xmin''': 3_45, '''ymin''': 23, '''xmax''': 6_40, '''ymax''': 3_68}},
               ],
               [
                   {'''score''': 0.9_982, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 70, '''xmax''': 1_75, '''ymax''': 1_17}},
                   {'''score''': 0.9_960, '''label''': '''remote''', '''box''': {'''xmin''': 3_33, '''ymin''': 72, '''xmax''': 3_68, '''ymax''': 1_87}},
                   {'''score''': 0.9_955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_39, '''ymax''': 4_73}},
                   {'''score''': 0.9_988, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 3_14, '''ymax''': 4_70}},
                   {'''score''': 0.9_987, '''label''': '''cat''', '''box''': {'''xmin''': 3_45, '''ymin''': 23, '''xmax''': 6_40, '''ymax''': 3_68}},
               ],
           ]		,				)



 @require_torch
 @slow
 def 						UpperCamelCase__					(     self ):
       snake_case_	=				'''facebook/detr-resnet-50'''

       snake_case_	=				pipeline('''object-detection'''		,				model=_UpperCAmelCase )

       snake_case_	=				object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg''' )
       self.assertEqual(
           nested_simplify(_UpperCAmelCase		,				decimals=4 )		,				[
               {'''score''': 0.9_982, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 70, '''xmax''': 1_75, '''ymax''': 1_17}},
               {'''score''': 0.9_960, '''label''': '''remote''', '''box''': {'''xmin''': 3_33, '''ymin''': 72, '''xmax''': 3_68, '''ymax''': 1_87}},
               {'''score''': 0.9_955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_39, '''ymax''': 4_73}},
               {'''score''': 0.9_988, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 3_14, '''ymax''': 4_70}},
               {'''score''': 0.9_987, '''label''': '''cat''', '''box''': {'''xmin''': 3_45, '''ymin''': 23, '''xmax''': 6_40, '''ymax''': 3_68}},
           ]		,				)

       snake_case_	=				object_detector(
           [
               '''http://images.cocodataset.org/val2017/000000039769.jpg''',
               '''http://images.cocodataset.org/val2017/000000039769.jpg''',
           ] )
       self.assertEqual(
           nested_simplify(_UpperCAmelCase		,				decimals=4 )		,				[
               [
                   {'''score''': 0.9_982, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 70, '''xmax''': 1_75, '''ymax''': 1_17}},
                   {'''score''': 0.9_960, '''label''': '''remote''', '''box''': {'''xmin''': 3_33, '''ymin''': 72, '''xmax''': 3_68, '''ymax''': 1_87}},
                   {'''score''': 0.9_955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_39, '''ymax''': 4_73}},
                   {'''score''': 0.9_988, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 3_14, '''ymax''': 4_70}},
                   {'''score''': 0.9_987, '''label''': '''cat''', '''box''': {'''xmin''': 3_45, '''ymin''': 23, '''xmax''': 6_40, '''ymax''': 3_68}},
               ],
               [
                   {'''score''': 0.9_982, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 70, '''xmax''': 1_75, '''ymax''': 1_17}},
                   {'''score''': 0.9_960, '''label''': '''remote''', '''box''': {'''xmin''': 3_33, '''ymin''': 72, '''xmax''': 3_68, '''ymax''': 1_87}},
                   {'''score''': 0.9_955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_39, '''ymax''': 4_73}},
                   {'''score''': 0.9_988, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 3_14, '''ymax''': 4_70}},
                   {'''score''': 0.9_987, '''label''': '''cat''', '''box''': {'''xmin''': 3_45, '''ymin''': 23, '''xmax''': 6_40, '''ymax''': 3_68}},
               ],
           ]		,				)



 @require_torch
 @slow
 def 						UpperCamelCase__					(     self ):
       snake_case_	=				0.9_985
       snake_case_	=				'''facebook/detr-resnet-50'''

       snake_case_	=				pipeline('''object-detection'''		,				model=_UpperCAmelCase )

       snake_case_	=				object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''		,				threshold=_UpperCAmelCase )
       self.assertEqual(
           nested_simplify(_UpperCAmelCase		,				decimals=4 )		,				[
               {'''score''': 0.9_988, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 3_14, '''ymax''': 4_70}},
               {'''score''': 0.9_987, '''label''': '''cat''', '''box''': {'''xmin''': 3_45, '''ymin''': 23, '''xmax''': 6_40, '''ymax''': 3_68}},
           ]		,				)





 @require_torch
 @require_pytesseract
 @slow
 def 						UpperCamelCase__					(     self ):
       snake_case_	=				'''Narsil/layoutlmv3-finetuned-funsd'''
       snake_case_	=				0.9_993

       snake_case_	=				pipeline('''object-detection'''		,				model=_UpperCAmelCase		,				threshold=_UpperCAmelCase )

       snake_case_	=				object_detector(
           '''https://huggingface.co/spaces/impira/docquery/resolve/2359223c1837a7587402bda0f2643382a6eefeab/invoice.png''' )
       self.assertEqual(
           nested_simplify(_UpperCAmelCase		,				decimals=4 )		,				[
               {'''score''': 0.9_993, '''label''': '''I-ANSWER''', '''box''': {'''xmin''': 2_94, '''ymin''': 2_54, '''xmax''': 3_43, '''ymax''': 2_64}},
               {'''score''': 0.9_993, '''label''': '''I-ANSWER''', '''box''': {'''xmin''': 2_94, '''ymin''': 2_54, '''xmax''': 3_43, '''ymax''': 2_64}},
           ]		,				)



def 	__lowerCAmelCase   (SCREAMING_SNAKE_CASE , SCREAMING_SNAKE_CASE )->  int:




      """simple docstring"""

      return x if y == 0 else greatest_common_divisor(SCREAMING_SNAKE_CASE , x % y )






def 	__lowerCAmelCase   (SCREAMING_SNAKE_CASE , SCREAMING_SNAKE_CASE )->  int:




      """simple docstring"""

      return (x * y) // greatest_common_divisor(SCREAMING_SNAKE_CASE , SCREAMING_SNAKE_CASE )






def 	__lowerCAmelCase   (SCREAMING_SNAKE_CASE = 20 )->  int:




      """simple docstring"""

      snake_case_	=				1
      for i in range(1 , n + 1 ):
            snake_case_	=				lcm(SCREAMING_SNAKE_CASE , SCREAMING_SNAKE_CASE )
      return g


if __name__ == "__main__":
   print(f'''{solution() = }''')