





import unittest

import requests

from transformers import MODEL_FOR_VISION_2_SEQ_MAPPING, TF_MODEL_FOR_VISION_2_SEQ_MAPPING, is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    is_torch_available,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_torch_available():
      from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
else:
      SCREAMING_SNAKE_CASE_		  =			False


if is_vision_available():
      from PIL import Image
else:

      class 						UpperCamelCase__					:



           '''simple docstring'''

           @staticmethod
           def 							SCREAMING_SNAKE_CASE__    (				*lowerCamelCase__		:       Dict		,**lowerCamelCase__		:       Dict			)	->						int:




                 '''simple docstring'''


                 pass

@is_pipeline_test
@require_vision
class 						UpperCamelCase__					( unittest.TestCase  ):



     '''simple docstring'''

     __snake_case       :      Any						      =     MODEL_FOR_VISION_2_SEQ_MAPPING
     __snake_case       :      List[Any]						      =     TF_MODEL_FOR_VISION_2_SEQ_MAPPING






     def 							SCREAMING_SNAKE_CASE__    (				self		:       List[Any]		,lowerCamelCase__		:       Union[str, Any]		,lowerCamelCase__		:       Any		,lowerCamelCase__		:       List[Any]			)	->						Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		pipeline("""image-to-text"""		,model=lowerCamelCase__		,tokenizer=lowerCamelCase__		,image_processor=lowerCamelCase__			)
           SCREAMING_SNAKE_CASE						=		[
               Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""			),
               """./tests/fixtures/tests_samples/COCO/000000039769.png""",
           ]
           return pipe, examples






     def 							SCREAMING_SNAKE_CASE__    (				self		:       Dict		,lowerCamelCase__		:       str		,lowerCamelCase__		:       Tuple			)	->						Optional[int]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		pipe(lowerCamelCase__			)
           self.assertEqual(
               lowerCamelCase__		,[
                   [{"""generated_text""": ANY(lowerCamelCase__			)}],
                   [{"""generated_text""": ANY(lowerCamelCase__			)}],
               ]		,)






     @require_tf
     def 							SCREAMING_SNAKE_CASE__    (				self		:       int			)	->						str:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		pipeline("""image-to-text"""		,model="""hf-internal-testing/tiny-random-vit-gpt2"""		,framework="""tf"""			)
           SCREAMING_SNAKE_CASE						=		"""./tests/fixtures/tests_samples/COCO/000000039769.png"""

           SCREAMING_SNAKE_CASE						=		pipe(lowerCamelCase__			)
           self.assertEqual(
               lowerCamelCase__		,[
                   {
                       """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                   },
               ]		,)

           SCREAMING_SNAKE_CASE						=		pipe([image, image]			)
           self.assertEqual(
               lowerCamelCase__		,[
                   [
                       {
                           """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                       }
                   ],
                   [
                       {
                           """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                       }
                   ],
               ]		,)

           SCREAMING_SNAKE_CASE						=		pipe(lowerCamelCase__		,max_new_tokens=1			)
           self.assertEqual(
               lowerCamelCase__		,[{"""generated_text""": """growth"""}]		,)






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		pipeline("""image-to-text"""		,model="""hf-internal-testing/tiny-random-vit-gpt2"""			)
           SCREAMING_SNAKE_CASE						=		"""./tests/fixtures/tests_samples/COCO/000000039769.png"""

           SCREAMING_SNAKE_CASE						=		pipe(lowerCamelCase__			)
           self.assertEqual(
               lowerCamelCase__		,[
                   {
                       """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                   },
               ]		,)

           SCREAMING_SNAKE_CASE						=		pipe([image, image]			)
           self.assertEqual(
               lowerCamelCase__		,[
                   [
                       {
                           """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                       }
                   ],
                   [
                       {
                           """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                       }
                   ],
               ]		,)






     @require_torch
     def 							SCREAMING_SNAKE_CASE__    (				self		:       Optional[Any]			)	->						Union[str, Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		pipeline("""image-to-text"""		,model="""hf-internal-testing/tiny-random-BlipForConditionalGeneration"""			)
           SCREAMING_SNAKE_CASE						=		"""./tests/fixtures/tests_samples/COCO/000000039769.png"""
           SCREAMING_SNAKE_CASE						=		"""a photo of"""

           SCREAMING_SNAKE_CASE						=		pipe(lowerCamelCase__		,prompt=lowerCamelCase__			)
           self.assertTrue(outputs[0]["""generated_text"""].startswith(lowerCamelCase__			)			)






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		pipeline("""image-to-text"""		,model="""ydshieh/vit-gpt2-coco-en"""			)
           SCREAMING_SNAKE_CASE						=		"""./tests/fixtures/tests_samples/COCO/000000039769.png"""

           SCREAMING_SNAKE_CASE						=		pipe(lowerCamelCase__			)
           self.assertEqual(lowerCamelCase__		,[{"""generated_text""": """a cat laying on a blanket next to a cat laying on a bed """}]			)

           SCREAMING_SNAKE_CASE						=		pipe([image, image]			)
           self.assertEqual(
               lowerCamelCase__		,[
                   [{"""generated_text""": """a cat laying on a blanket next to a cat laying on a bed """}],
                   [{"""generated_text""": """a cat laying on a blanket next to a cat laying on a bed """}],
               ]		,)






     @slow
     @require_torch
     def 							SCREAMING_SNAKE_CASE__    (				self		:       Tuple			)	->						List[str]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		pipeline("""image-to-text"""		,model="""Salesforce/blip-image-captioning-base"""			)
           SCREAMING_SNAKE_CASE						=		"""https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"""
           SCREAMING_SNAKE_CASE						=		Image.open(requests.get(lowerCamelCase__		,stream=lowerCamelCase__			).raw			)

           SCREAMING_SNAKE_CASE						=		pipe(lowerCamelCase__			)
           self.assertEqual(lowerCamelCase__		,[{"""generated_text""": """a pink pokemon pokemon with a blue shirt and a blue shirt"""}]			)






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		pipeline("""image-to-text"""		,model="""microsoft/git-base-coco"""			)
           SCREAMING_SNAKE_CASE						=		"""https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"""
           SCREAMING_SNAKE_CASE						=		Image.open(requests.get(lowerCamelCase__		,stream=lowerCamelCase__			).raw			)

           SCREAMING_SNAKE_CASE						=		pipe(lowerCamelCase__			)
           self.assertEqual(lowerCamelCase__		,[{"""generated_text""": """a cartoon of a purple character."""}]			)






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		pipeline("""image-to-text"""		,model="""Salesforce/blip-image-captioning-base"""			)
           SCREAMING_SNAKE_CASE						=		"""https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"""
           SCREAMING_SNAKE_CASE						=		Image.open(requests.get(lowerCamelCase__		,stream=lowerCamelCase__			).raw			)

           SCREAMING_SNAKE_CASE						=		"""a photography of"""

           SCREAMING_SNAKE_CASE						=		pipe(lowerCamelCase__		,prompt=lowerCamelCase__			)
           self.assertEqual(lowerCamelCase__		,[{"""generated_text""": """a photography of a volcano"""}]			)

           with self.assertRaises(lowerCamelCase__			):
                 SCREAMING_SNAKE_CASE						=		pipe([image, image]		,prompt=[prompt, prompt]			)






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		pipeline("""image-to-text"""		,model="""microsoft/git-base-coco"""			)
           SCREAMING_SNAKE_CASE						=		"""https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"""
           SCREAMING_SNAKE_CASE						=		Image.open(requests.get(lowerCamelCase__		,stream=lowerCamelCase__			).raw			)

           SCREAMING_SNAKE_CASE						=		"""a photo of a"""

           SCREAMING_SNAKE_CASE						=		pipe(lowerCamelCase__		,prompt=lowerCamelCase__			)
           self.assertEqual(lowerCamelCase__		,[{"""generated_text""": """a photo of a tent with a tent and a tent in the background."""}]			)

           with self.assertRaises(lowerCamelCase__			):
                 SCREAMING_SNAKE_CASE						=		pipe([image, image]		,prompt=[prompt, prompt]			)






     @unittest.skipIf(
         not is_torch_greater_or_equal_than_1_11		,reason="""`Pix2StructImageProcessor` requires `torch>=1.11.0`."""			)
     @slow
     @require_torch
     def 							SCREAMING_SNAKE_CASE__    (				self		:       int			)	->						Optional[int]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		pipeline("""image-to-text"""		,model="""google/pix2struct-ai2d-base"""			)
           SCREAMING_SNAKE_CASE						=		"""https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"""
           SCREAMING_SNAKE_CASE						=		Image.open(requests.get(lowerCamelCase__		,stream=lowerCamelCase__			).raw			)

           SCREAMING_SNAKE_CASE						=		"""What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"""

           SCREAMING_SNAKE_CASE						=		pipe(lowerCamelCase__		,prompt=lowerCamelCase__			)
           self.assertEqual(lowerCamelCase__		,[{"""generated_text""": """ash cloud"""}]			)

           with self.assertRaises(lowerCamelCase__			):
                 SCREAMING_SNAKE_CASE						=		pipe([image, image]		,prompt=[prompt, prompt]			)






     @slow
     @require_tf
     def 							SCREAMING_SNAKE_CASE__    (				self		:       Dict			)	->						List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		pipeline("""image-to-text"""		,model="""ydshieh/vit-gpt2-coco-en"""		,framework="""tf"""			)
           SCREAMING_SNAKE_CASE						=		"""./tests/fixtures/tests_samples/COCO/000000039769.png"""

           SCREAMING_SNAKE_CASE						=		pipe(lowerCamelCase__			)
           self.assertEqual(lowerCamelCase__		,[{"""generated_text""": """a cat laying on a blanket next to a cat laying on a bed """}]			)

           SCREAMING_SNAKE_CASE						=		pipe([image, image]			)
           self.assertEqual(
               lowerCamelCase__		,[
                   [{"""generated_text""": """a cat laying on a blanket next to a cat laying on a bed """}],
                   [{"""generated_text""": """a cat laying on a blanket next to a cat laying on a bed """}],
               ]		,)









import os



def   __lowercase  ( )					->  int:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		os.path.dirname(os.path.realpath(_SCREAMING_SNAKE_CASE      )      )
      SCREAMING_SNAKE_CASE						=		os.path.join(_SCREAMING_SNAKE_CASE					,		"""triangle.txt"""      )

      with open(_SCREAMING_SNAKE_CASE      ) as in_file:
            SCREAMING_SNAKE_CASE						=		[[int(_SCREAMING_SNAKE_CASE      ) for i in line.split()] for line in in_file]

      while len(_SCREAMING_SNAKE_CASE      ) != 1:
            SCREAMING_SNAKE_CASE						=		triangle.pop()
            SCREAMING_SNAKE_CASE						=		triangle[-1]
            for j in range(len(_SCREAMING_SNAKE_CASE      ) - 1      ):
                  curr_row[j] += max(last_row[j]					,		last_row[j + 1]      )
      return triangle[0][0]


if __name__ == "__main__":
      print(solution())


