
'''simple docstring'''

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:
   lowerCAmelCase_			:			Optional[Any]			   =     False


if is_vision_available():
   from PIL import Image
else:







   class 	__lowerCAmelCase    :



        @staticmethod
        def     snake_case_ (*lowerCAmelCase__						,	**lowerCAmelCase__	):
             pass







@is_pipeline_test
@require_vision
class 	__lowerCAmelCase    (  unittest.TestCase				):
     snake_case   :    Union[str, Any]							      =      MODEL_FOR_VISION_2_SEQ_MAPPING
     snake_case   :    List[str]							      =      TF_MODEL_FOR_VISION_2_SEQ_MAPPING



     def     snake_case_ (self						,	lowerCAmelCase__						,	lowerCAmelCase__						,	lowerCAmelCase__	):
          _UpperCAmelCase					:  List[Any]         =    pipeline("""image-to-text"""						,	model=lowerCAmelCase__						,	tokenizer=lowerCAmelCase__						,	image_processor=lowerCAmelCase__	)
          _UpperCAmelCase					:  Dict         =    [
              Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""	),
              """./tests/fixtures/tests_samples/COCO/000000039769.png""",
          ]
          return pipe, examples



     def     snake_case_ (self						,	lowerCAmelCase__						,	lowerCAmelCase__	):
          _UpperCAmelCase					:  Any         =    pipe(lowerCAmelCase__	)
          self.assertEqual(
              lowerCAmelCase__						,	[
                  [{"""generated_text""": ANY(lowerCAmelCase__	)}],
                  [{"""generated_text""": ANY(lowerCAmelCase__	)}],
              ]						,	)



     @require_tf
     def     snake_case_ (self	):
          _UpperCAmelCase					:  List[str]         =    pipeline("""image-to-text"""						,	model="""hf-internal-testing/tiny-random-vit-gpt2"""						,	framework="""tf"""	)
          _UpperCAmelCase					:  Dict         =    """./tests/fixtures/tests_samples/COCO/000000039769.png"""

          _UpperCAmelCase					:  Optional[Any]         =    pipe(lowerCAmelCase__	)
          self.assertEqual(
              lowerCAmelCase__						,	[
                  {
                      """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                  },
              ]						,	)

          _UpperCAmelCase					:  str         =    pipe([image, image]	)
          self.assertEqual(
              lowerCAmelCase__						,	[
                  [
                      {
                          """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                      }
                  ],
                  [
                      {
                          """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                      }
                  ],
              ]						,	)

          _UpperCAmelCase					:  Any         =    pipe(lowerCAmelCase__						,	max_new_tokens=1	)
          self.assertEqual(
              lowerCAmelCase__						,	[{"""generated_text""": """growth"""}]						,	)



     @require_torch
     def     snake_case_ (self	):
          _UpperCAmelCase					:  str         =    pipeline("""image-to-text"""						,	model="""hf-internal-testing/tiny-random-vit-gpt2"""	)
          _UpperCAmelCase					:  int         =    """./tests/fixtures/tests_samples/COCO/000000039769.png"""

          _UpperCAmelCase					:  Optional[int]         =    pipe(lowerCAmelCase__	)
          self.assertEqual(
              lowerCAmelCase__						,	[
                  {
                      """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                  },
              ]						,	)

          _UpperCAmelCase					:  Union[str, Any]         =    pipe([image, image]	)
          self.assertEqual(
              lowerCAmelCase__						,	[
                  [
                      {
                          """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                      }
                  ],
                  [
                      {
                          """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                      }
                  ],
              ]						,	)



     @require_torch
     def     snake_case_ (self	):
          _UpperCAmelCase					:  Union[str, Any]         =    pipeline("""image-to-text"""						,	model="""hf-internal-testing/tiny-random-BlipForConditionalGeneration"""	)
          _UpperCAmelCase					:  Tuple         =    """./tests/fixtures/tests_samples/COCO/000000039769.png"""
          _UpperCAmelCase					:  Tuple         =    """a photo of"""

          _UpperCAmelCase					:  Union[str, Any]         =    pipe(lowerCAmelCase__						,	prompt=lowerCAmelCase__	)
          self.assertTrue(outputs[0]["""generated_text"""].startswith(lowerCAmelCase__	)	)



     @slow
     @require_torch
     def     snake_case_ (self	):
          _UpperCAmelCase					:  int         =    pipeline("""image-to-text"""						,	model="""ydshieh/vit-gpt2-coco-en"""	)
          _UpperCAmelCase					:  Optional[Any]         =    """./tests/fixtures/tests_samples/COCO/000000039769.png"""

          _UpperCAmelCase					:  Optional[int]         =    pipe(lowerCAmelCase__	)
          self.assertEqual(lowerCAmelCase__						,	[{"""generated_text""": """a cat laying on a blanket next to a cat laying on a bed """}]	)

          _UpperCAmelCase					:  Tuple         =    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     snake_case_ (self	):
          _UpperCAmelCase					:  Dict         =    pipeline("""image-to-text"""						,	model="""Salesforce/blip-image-captioning-base"""	)
          _UpperCAmelCase					:  Union[str, Any]         =    """https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"""
          _UpperCAmelCase					:  Dict         =    Image.open(requests.get(lowerCAmelCase__						,	stream=lowerCAmelCase__	).raw	)

          _UpperCAmelCase					:  List[Any]         =    pipe(lowerCAmelCase__	)
          self.assertEqual(lowerCAmelCase__						,	[{"""generated_text""": """a pink pokemon pokemon with a blue shirt and a blue shirt"""}]	)



     @slow
     @require_torch
     def     snake_case_ (self	):
          _UpperCAmelCase					:  int         =    pipeline("""image-to-text"""						,	model="""microsoft/git-base-coco"""	)
          _UpperCAmelCase					:  Optional[int]         =    """https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"""
          _UpperCAmelCase					:  Tuple         =    Image.open(requests.get(lowerCAmelCase__						,	stream=lowerCAmelCase__	).raw	)

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



     @slow
     @require_torch
     def     snake_case_ (self	):
          _UpperCAmelCase					:  Any         =    pipeline("""image-to-text"""						,	model="""Salesforce/blip-image-captioning-base"""	)
          _UpperCAmelCase					:  List[str]         =    """https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"""
          _UpperCAmelCase					:  Dict         =    Image.open(requests.get(lowerCAmelCase__						,	stream=lowerCAmelCase__	).raw	)

          _UpperCAmelCase					:  Tuple         =    """a photography of"""

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

          with self.assertRaises(lowerCAmelCase__	):
               _UpperCAmelCase					:  List[str]         =    pipe([image, image]						,	prompt=[prompt, prompt]	)



     @slow
     @require_torch
     def     snake_case_ (self	):
          _UpperCAmelCase					:  Optional[int]         =    pipeline("""image-to-text"""						,	model="""microsoft/git-base-coco"""	)
          _UpperCAmelCase					:  int         =    """https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"""
          _UpperCAmelCase					:  Union[str, Any]         =    Image.open(requests.get(lowerCAmelCase__						,	stream=lowerCAmelCase__	).raw	)

          _UpperCAmelCase					:  Optional[Any]         =    """a photo of a"""

          _UpperCAmelCase					:  int         =    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__	):
               _UpperCAmelCase					:  int         =    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     snake_case_ (self	):
          _UpperCAmelCase					:  Dict         =    pipeline("""image-to-text"""						,	model="""google/pix2struct-ai2d-base"""	)
          _UpperCAmelCase					:  Union[str, Any]         =    """https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"""
          _UpperCAmelCase					:  Optional[Any]         =    Image.open(requests.get(lowerCAmelCase__						,	stream=lowerCAmelCase__	).raw	)

          _UpperCAmelCase					:  List[str]         =    """What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"""

          _UpperCAmelCase					:  Any         =    pipe(lowerCAmelCase__						,	prompt=lowerCAmelCase__	)
          self.assertEqual(lowerCAmelCase__						,	[{"""generated_text""": """ash cloud"""}]	)

          with self.assertRaises(lowerCAmelCase__	):
               _UpperCAmelCase					:  Dict         =    pipe([image, image]						,	prompt=[prompt, prompt]	)



     @slow
     @require_tf
     def     snake_case_ (self	):
          _UpperCAmelCase					:  str         =    pipeline("""image-to-text"""						,	model="""ydshieh/vit-gpt2-coco-en"""						,	framework="""tf"""	)
          _UpperCAmelCase					:  Any         =    """./tests/fixtures/tests_samples/COCO/000000039769.png"""

          _UpperCAmelCase					:  List[Any]         =    pipe(lowerCAmelCase__	)
          self.assertEqual(lowerCAmelCase__						,	[{"""generated_text""": """a cat laying on a blanket next to a cat laying on a bed """}]	)

          _UpperCAmelCase					:  int         =    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 """}],
              ]						,	)




'''simple docstring'''

from itertools import permutations







def __A  (    ):
     _UpperCAmelCase					:  Union[str, Any]         =    list(map("""""".join ,       permutations("""0123456789"""       )       )       )
     return result[99_9999]


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


