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:
 a     :			Optional[int]					    =						False


if is_vision_available():
 from PIL import Image
else:

 class 				_lowercase						:






     '''simple docstring'''




     @staticmethod
     def     _a						(						*lowerCamelCase__					,	**lowerCamelCase__   ):
        pass

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






    '''simple docstring'''
    SCREAMING_SNAKE_CASE:							Union[str, Any]        =						MODEL_FOR_VISION_2_SEQ_MAPPING
    SCREAMING_SNAKE_CASE:							List[Any]        =						TF_MODEL_FOR_VISION_2_SEQ_MAPPING




    def     _a						(						self					,	lowerCamelCase__					,	lowerCamelCase__					,	lowerCamelCase__   ):
       lowerCAmelCase_:       Any         =  pipeline("image-to-text"					,	model=lowerCamelCase__					,	tokenizer=lowerCamelCase__					,	image_processor=lowerCamelCase__   )
       lowerCAmelCase_:       Tuple         =  [
           Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"   ),
           "./tests/fixtures/tests_samples/COCO/000000039769.png",
       ]
       return pipe, examples




    def     _a						(						self					,	lowerCamelCase__					,	lowerCamelCase__   ):
       lowerCAmelCase_:       Optional[int]         =  pipe(lowerCamelCase__   )
       self.assertEqual(
           lowerCamelCase__					,	[
               [{"generated_text": ANY(lowerCamelCase__   )}],
               [{"generated_text": ANY(lowerCamelCase__   )}],
           ]					,	)




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

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

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

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




    @require_torch
    def     _a						(						self   ):
       lowerCAmelCase_:       Dict         =  pipeline("image-to-text"					,	model="hf-internal-testing/tiny-random-vit-gpt2"   )
       lowerCAmelCase_:       List[Any]         =  "./tests/fixtures/tests_samples/COCO/000000039769.png"

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

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




    @require_torch
    def     _a						(						self   ):
       lowerCAmelCase_:       int         =  pipeline("image-to-text"					,	model="hf-internal-testing/tiny-random-BlipForConditionalGeneration"   )
       lowerCAmelCase_:       Optional[Any]         =  "./tests/fixtures/tests_samples/COCO/000000039769.png"
       lowerCAmelCase_:       Dict         =  "a photo of"

       lowerCAmelCase_:       List[Any]         =  pipe(lowerCamelCase__					,	prompt=lowerCamelCase__   )
       self.assertTrue(outputs[0]["generated_text"].startswith(lowerCamelCase__   )   )




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

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

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

       lowerCAmelCase_:       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     _a						(						self   ):
       lowerCAmelCase_:       int         =  pipeline("image-to-text"					,	model="microsoft/git-base-coco"   )
       lowerCAmelCase_:       Union[str, Any]         =  "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
       lowerCAmelCase_:       Tuple         =  Image.open(requests.get(lowerCamelCase__					,	stream=lowerCamelCase__   ).raw   )

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




    @slow
    @require_torch
    def     _a						(						self   ):
       lowerCAmelCase_:       int         =  pipeline("image-to-text"					,	model="Salesforce/blip-image-captioning-base"   )
       lowerCAmelCase_:       Tuple         =  "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
       lowerCAmelCase_:       str         =  Image.open(requests.get(lowerCamelCase__					,	stream=lowerCamelCase__   ).raw   )

       lowerCAmelCase_:       List[str]         =  "a photography of"

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

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




    @slow
    @require_torch
    def     _a						(						self   ):
       lowerCAmelCase_:       int         =  pipeline("image-to-text"					,	model="microsoft/git-base-coco"   )
       lowerCAmelCase_:       str         =  "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
       lowerCAmelCase_:       Dict         =  Image.open(requests.get(lowerCamelCase__					,	stream=lowerCamelCase__   ).raw   )

       lowerCAmelCase_:       Optional[int]         =  "a photo of a"

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

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

       lowerCAmelCase_:       Union[str, Any]         =  pipe(lowerCamelCase__					,	prompt=lowerCamelCase__   )
       self.assertEqual(lowerCamelCase__					,	[{"generated_text": "ash cloud"}]   )

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




    @slow
    @require_tf
    def     _a						(						self   ):
       lowerCAmelCase_:       Optional[Any]         =  pipeline("image-to-text"					,	model="ydshieh/vit-gpt2-coco-en"					,	framework="tf"   )
       lowerCAmelCase_:       Dict         =  "./tests/fixtures/tests_samples/COCO/000000039769.png"

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

       lowerCAmelCase_:       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 "}],
           ]					,	)
import itertools
def 		snake_case__  (		lowercase				):
   return (
       int("".join(combination[0:2]				)				) * int("".join(combination[2:5]				)				)
       == int("".join(combination[5:9]				)				)
   ) or (
       int("".join(combination[0]				)				) * int("".join(combination[1:5]				)				)
       == int("".join(combination[5:9]				)				)
   )
def 		snake_case__  (		):
   return sum(
       {
           int("".join(pandigital[5:9]				)				)
           for pandigital in itertools.permutations("123456789"				)
           if is_combination_valid(lowercase				)
       }				)


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