






'''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:
       __A      :       List[str]      =	False


if is_vision_available():
       from PIL import Image
else:






       class 					a__    :
            '''simple docstring'''







            @staticmethod
            def     _UpperCamelCase   (*lowercase__    :	Optional[int]				,				**lowercase__    :	Optional[Any]					)  ->       Tuple:
                  pass






@is_pipeline_test
@require_vision
class 					a__    (			unittest.TestCase						):
     '''simple docstring'''







     _snake_case             =  MODEL_FOR_VISION_2_SEQ_MAPPING
     _snake_case             =  TF_MODEL_FOR_VISION_2_SEQ_MAPPING






     def     _UpperCamelCase   (self    :	List[str]				,				lowercase__    :	List[Any]				,				lowercase__    :	Dict				,				lowercase__    :	Union[str, Any]					)  ->       Optional[Any]:
           __A		   =      pipeline("image-to-text"				,				model=lowercase__				,				tokenizer=lowercase__				,				image_processor=lowercase__					)
           __A		   =      [
               Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"					),
               "./tests/fixtures/tests_samples/COCO/000000039769.png",
           ]
           return pipe, examples






     def     _UpperCamelCase   (self    :	List[str]				,				lowercase__    :	int				,				lowercase__    :	List[Any]					)  ->       Union[str, Any]:
           __A		   =      pipe(lowercase__					)
           self.assertEqual(
               lowercase__				,				[
                   [{"generated_text": ANY(lowercase__					)}],
                   [{"generated_text": ANY(lowercase__					)}],
               ]				,				)






     @require_tf
     def     _UpperCamelCase   (self    :	int					)  ->       Tuple:
           __A		   =      pipeline("image-to-text"				,				model="hf-internal-testing/tiny-random-vit-gpt2"				,				framework="tf"					)
           __A		   =      "./tests/fixtures/tests_samples/COCO/000000039769.png"

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

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

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






     @require_torch
     def     _UpperCamelCase   (self    :	int					)  ->       Union[str, Any]:
           __A		   =      pipeline("image-to-text"				,				model="hf-internal-testing/tiny-random-vit-gpt2"					)
           __A		   =      "./tests/fixtures/tests_samples/COCO/000000039769.png"

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

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






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

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






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

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

           __A		   =      pipe([image, image]					)
           self.assertEqual(
               lowercase__				,				[
                   [{"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     _UpperCamelCase   (self    :	int					)  ->       List[Any]:
           __A		   =      pipeline("image-to-text"				,				model="Salesforce/blip-image-captioning-base"					)
           __A		   =      "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
           __A		   =      Image.open(requests.get(lowercase__				,				stream=lowercase__					).raw					)

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






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

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






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

           __A		   =      "a photography of"

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

           with self.assertRaises(lowercase__					):
                 __A		   =      pipe([image, image]				,				prompt=[prompt, prompt]					)






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

           __A		   =      "a photo of a"

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

           with self.assertRaises(lowercase__					):
                 __A		   =      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     _UpperCamelCase   (self    :	Optional[Any]					)  ->       List[Any]:
           __A		   =      pipeline("image-to-text"				,				model="google/pix2struct-ai2d-base"					)
           __A		   =      "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
           __A		   =      Image.open(requests.get(lowercase__				,				stream=lowercase__					).raw					)

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

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

           with self.assertRaises(lowercase__					):
                 __A		   =      pipe([image, image]				,				prompt=[prompt, prompt]					)






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

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

           __A		   =      pipe([image, image]					)
           self.assertEqual(
               lowercase__				,				[
                   [{"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 typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__A      :       str      =	{'configuration_umt5': ['UMT5Config', 'UMT5OnnxConfig']}


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __A      :       str      =	[
           'UMT5EncoderModel',
           'UMT5ForConditionalGeneration',
           'UMT5ForQuestionAnswering',
           'UMT5Model',
           'UMT5PreTrainedModel',
       ]

if TYPE_CHECKING:
       from .configuration_umta import UMTaConfig, UMTaOnnxConfig

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_umta import (
                  UMTaEncoderModel,
                  UMTaForConditionalGeneration,
                  UMTaForQuestionAnswering,
                  UMTaModel,
                  UMTaPreTrainedModel,
              )
else:
       import sys

       __A      :       Optional[int]      =	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)


