code: 
  
  
  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:
     UpperCamelCase__				       =			False
  
  
  if is_vision_available():
     from PIL import Image
  else:
  
     class 						UpperCAmelCase__   :
  
  
  
          '''simple docstring'''
  
  
  
  
          @staticmethod
          def   lowerCAmelCase_   ( *UpperCamelCase       :       Dict	,      **UpperCamelCase       :       str		):
  
  
  
  
  
                 """simple docstring"""
  
  
  
                 pass
  
  @is_pipeline_test
  @require_vision
  class 						UpperCAmelCase__   (      unittest.TestCase		):
  
  
  
       '''simple docstring'''
       UpperCAmelCase_         =  MODEL_FOR_VISION_2_SEQ_MAPPING
       UpperCAmelCase_         =  TF_MODEL_FOR_VISION_2_SEQ_MAPPING
  
  
  
  
       def   lowerCAmelCase_   ( self       :       int	,      UpperCamelCase       :       int	,      UpperCamelCase       :       str	,      UpperCamelCase       :       Optional[Any]		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				int           =			pipeline('''image-to-text'''	,      model=lowerCAmelCase__	,      tokenizer=lowerCAmelCase__	,      image_processor=lowerCAmelCase__		)
              _lowercase					:				List[str]           =			[
                  Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		),
                  "./tests/fixtures/tests_samples/COCO/000000039769.png",
              ]
              return pipe, examples
  
  
  
  
       def   lowerCAmelCase_   ( self       :       Dict	,      UpperCamelCase       :       str	,      UpperCamelCase       :       str		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				List[Any]           =			pipe(lowerCAmelCase__		)
              self.assertEqual(
                  lowerCAmelCase__	,      [
                      [{'''generated_text''': ANY(lowerCAmelCase__		)}],
                      [{'''generated_text''': ANY(lowerCAmelCase__		)}],
                  ]	,      )
  
  
  
  
       @require_tf
       def   lowerCAmelCase_   ( self       :       int		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				Optional[int]           =			pipeline('''image-to-text'''	,      model='''hf-internal-testing/tiny-random-vit-gpt2'''	,      framework='''tf'''		)
              _lowercase					:				Optional[int]           =			"./tests/fixtures/tests_samples/COCO/000000039769.png"
  
              _lowercase					:				Dict           =			pipe(lowerCAmelCase__		)
              self.assertEqual(
                  lowerCAmelCase__	,      [
                      {
                          '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                      },
                  ]	,      )
  
              _lowercase					:				Dict           =			pipe([image, image]		)
              self.assertEqual(
                  lowerCAmelCase__	,      [
                      [
                          {
                              '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                          }
                      ],
                      [
                          {
                              '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                          }
                      ],
                  ]	,      )
  
              _lowercase					:				Optional[int]           =			pipe(lowerCAmelCase__	,      max_new_tokens=1		)
              self.assertEqual(
                  lowerCAmelCase__	,      [{'''generated_text''': '''growth'''}]	,      )
  
  
  
  
       @require_torch
       def   lowerCAmelCase_   ( self       :       Optional[Any]		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				Any           =			pipeline('''image-to-text'''	,      model='''hf-internal-testing/tiny-random-vit-gpt2'''		)
              _lowercase					:				Optional[Any]           =			"./tests/fixtures/tests_samples/COCO/000000039769.png"
  
              _lowercase					:				Any           =			pipe(lowerCAmelCase__		)
              self.assertEqual(
                  lowerCAmelCase__	,      [
                      {
                          '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                      },
                  ]	,      )
  
              _lowercase					:				List[str]           =			pipe([image, image]		)
              self.assertEqual(
                  lowerCAmelCase__	,      [
                      [
                          {
                              '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                          }
                      ],
                      [
                          {
                              '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                          }
                      ],
                  ]	,      )
  
  
  
  
       @require_torch
       def   lowerCAmelCase_   ( self       :       Dict		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				Dict           =			pipeline('''image-to-text'''	,      model='''hf-internal-testing/tiny-random-BlipForConditionalGeneration'''		)
              _lowercase					:				Union[str, Any]           =			"./tests/fixtures/tests_samples/COCO/000000039769.png"
              _lowercase					:				Union[str, Any]           =			"a photo of"
  
              _lowercase					:				Optional[int]           =			pipe(lowerCAmelCase__	,      prompt=lowerCAmelCase__		)
              self.assertTrue(outputs[0]['''generated_text'''].startswith(lowerCAmelCase__		)		)
  
  
  
  
       @slow
       @require_torch
       def   lowerCAmelCase_   ( self       :       Any		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				Tuple           =			pipeline('''image-to-text'''	,      model='''ydshieh/vit-gpt2-coco-en'''		)
              _lowercase					:				Union[str, Any]           =			"./tests/fixtures/tests_samples/COCO/000000039769.png"
  
              _lowercase					:				List[str]           =			pipe(lowerCAmelCase__		)
              self.assertEqual(lowerCAmelCase__	,      [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}]		)
  
              _lowercase					:				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 '''}],
                  ]	,      )
  
  
  
  
       @slow
       @require_torch
       def   lowerCAmelCase_   ( self       :       int		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				List[Any]           =			pipeline('''image-to-text'''	,      model='''Salesforce/blip-image-captioning-base'''		)
              _lowercase					:				List[str]           =			"https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
              _lowercase					:				Union[str, Any]           =			Image.open(requests.get(lowerCAmelCase__	,      stream=lowerCAmelCase__		).raw		)
  
              _lowercase					:				List[str]           =			pipe(lowerCAmelCase__		)
              self.assertEqual(lowerCAmelCase__	,      [{'''generated_text''': '''a pink pokemon pokemon with a blue shirt and a blue shirt'''}]		)
  
  
  
  
       @slow
       @require_torch
       def   lowerCAmelCase_   ( self       :       Tuple		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				Dict           =			pipeline('''image-to-text'''	,      model='''microsoft/git-base-coco'''		)
              _lowercase					:				Dict           =			"https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
              _lowercase					:				Union[str, Any]           =			Image.open(requests.get(lowerCAmelCase__	,      stream=lowerCAmelCase__		).raw		)
  
              _lowercase					:				int           =			pipe(lowerCAmelCase__		)
              self.assertEqual(lowerCAmelCase__	,      [{'''generated_text''': '''a cartoon of a purple character.'''}]		)
  
  
  
  
       @slow
       @require_torch
       def   lowerCAmelCase_   ( self       :       List[str]		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				List[Any]           =			pipeline('''image-to-text'''	,      model='''Salesforce/blip-image-captioning-base'''		)
              _lowercase					:				str           =			"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
              _lowercase					:				Optional[Any]           =			Image.open(requests.get(lowerCAmelCase__	,      stream=lowerCAmelCase__		).raw		)
  
              _lowercase					:				int           =			"a photography of"
  
              _lowercase					:				Any           =			pipe(lowerCAmelCase__	,      prompt=lowerCAmelCase__		)
              self.assertEqual(lowerCAmelCase__	,      [{'''generated_text''': '''a photography of a volcano'''}]		)
  
              with self.assertRaises(lowerCAmelCase__		):
                     _lowercase					:				List[Any]           =			pipe([image, image]	,      prompt=[prompt, prompt]		)
  
  
  
  
       @slow
       @require_torch
       def   lowerCAmelCase_   ( self       :       str		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				int           =			pipeline('''image-to-text'''	,      model='''microsoft/git-base-coco'''		)
              _lowercase					:				str           =			"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
              _lowercase					:				List[str]           =			Image.open(requests.get(lowerCAmelCase__	,      stream=lowerCAmelCase__		).raw		)
  
              _lowercase					:				int           =			"a photo of a"
  
              _lowercase					:				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__		):
                     _lowercase					:				str           =			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   lowerCAmelCase_   ( self       :       Optional[Any]		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				int           =			pipeline('''image-to-text'''	,      model='''google/pix2struct-ai2d-base'''		)
              _lowercase					:				List[str]           =			"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
              _lowercase					:				Dict           =			Image.open(requests.get(lowerCAmelCase__	,      stream=lowerCAmelCase__		).raw		)
  
              _lowercase					:				Union[str, Any]           =			"What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"
  
              _lowercase					:				int           =			pipe(lowerCAmelCase__	,      prompt=lowerCAmelCase__		)
              self.assertEqual(lowerCAmelCase__	,      [{'''generated_text''': '''ash cloud'''}]		)
  
              with self.assertRaises(lowerCAmelCase__		):
                     _lowercase					:				str           =			pipe([image, image]	,      prompt=[prompt, prompt]		)
  
  
  
  
       @slow
       @require_tf
       def   lowerCAmelCase_   ( self       :       Optional[int]		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				Union[str, Any]           =			pipeline('''image-to-text'''	,      model='''ydshieh/vit-gpt2-coco-en'''	,      framework='''tf'''		)
              _lowercase					:				Optional[int]           =			"./tests/fixtures/tests_samples/COCO/000000039769.png"
  
              _lowercase					:				List[Any]           =			pipe(lowerCAmelCase__		)
              self.assertEqual(lowerCAmelCase__	,      [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}]		)
  
              _lowercase					:				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 '''}],
                  ]	,      )
style_context: 
  
  
  from typing import TYPE_CHECKING
  
  from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available
  
  
  UpperCamelCase__				       =			{
      'configuration_realm': ['REALM_PRETRAINED_CONFIG_ARCHIVE_MAP', 'RealmConfig'],
      'tokenization_realm': ['RealmTokenizer'],
  }
  
  try:
     if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
     pass
  else:
     UpperCamelCase__				       =			['RealmTokenizerFast']
  
  try:
     if not is_torch_available():
        raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
     pass
  else:
     UpperCamelCase__				       =			[
         'REALM_PRETRAINED_MODEL_ARCHIVE_LIST',
         'RealmEmbedder',
         'RealmForOpenQA',
         'RealmKnowledgeAugEncoder',
         'RealmPreTrainedModel',
         'RealmReader',
         'RealmScorer',
         'load_tf_weights_in_realm',
     ]
     UpperCamelCase__				       =			['RealmRetriever']
  
  
  if TYPE_CHECKING:
     from .configuration_realm import REALM_PRETRAINED_CONFIG_ARCHIVE_MAP, RealmConfig
     from .tokenization_realm import RealmTokenizer
  
     try:
        if not is_tokenizers_available():
           raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
        pass
     else:
        from .tokenization_realm import RealmTokenizerFast
  
     try:
        if not is_torch_available():
           raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
        pass
     else:
        from .modeling_realm import (
            REALM_PRETRAINED_MODEL_ARCHIVE_LIST,
            RealmEmbedder,
            RealmForOpenQA,
            RealmKnowledgeAugEncoder,
            RealmPreTrainedModel,
            RealmReader,
            RealmScorer,
            load_tf_weights_in_realm,
        )
        from .retrieval_realm import RealmRetriever
  
  
  else:
     import sys
  
     UpperCamelCase__				       =			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)