




import random
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
       import torch

if is_vision_available():
       import PIL

       from transformers import FlavaImageProcessor
       from transformers.image_utils import PILImageResampling
       from transformers.models.flava.image_processing_flava import (
           FLAVA_CODEBOOK_MEAN,
           FLAVA_CODEBOOK_STD,
           FLAVA_IMAGE_MEAN,
           FLAVA_IMAGE_STD,
       )
else:
       UpperCAmelCase_   							=      UpperCAmelCase_   							=      UpperCAmelCase_   							=      UpperCAmelCase_   							=      None





class        lowerCamelCase__(   unittest.TestCase):
      def __init__(							self:					Optional[int]       ,			UpperCamelCase_:					List[Any]       ,			UpperCamelCase_:					Union[str, Any]=7       ,			UpperCamelCase_:					Optional[Any]=3       ,			UpperCamelCase_:					Tuple=30       ,			UpperCamelCase_:					Dict=4_00       ,			UpperCamelCase_:					Optional[int]=True       ,			UpperCamelCase_:					Tuple=None       ,			UpperCamelCase_:					Any=True       ,			UpperCamelCase_:					Optional[Any]=None       ,			UpperCamelCase_:					List[Any]=None       ,			UpperCamelCase_:					List[Any]=True       ,			UpperCamelCase_:					Optional[int]=1 / 2_55       ,			UpperCamelCase_:					int=True       ,			UpperCamelCase_:					Dict=FLAVA_IMAGE_MEAN       ,			UpperCamelCase_:					List[str]=FLAVA_IMAGE_STD       ,			UpperCamelCase_:					Tuple=14       ,			UpperCamelCase_:					Optional[Any]=75       ,			UpperCamelCase_:					Tuple=None       ,			UpperCamelCase_:					int=16       ,			UpperCamelCase_:					str=0.3       ,			UpperCamelCase_:					str=None       ,			UpperCamelCase_:					Optional[Any]=True       ,			UpperCamelCase_:					Union[str, Any]=None       ,			UpperCamelCase_:					Optional[Any]=None       ,			UpperCamelCase_:					List[str]=True       ,			UpperCamelCase_:					Union[str, Any]=None       ,			UpperCamelCase_:					Any=True       ,			UpperCamelCase_:					Union[str, Any]=True       ,			UpperCamelCase_:					str=FLAVA_CODEBOOK_MEAN       ,			UpperCamelCase_:					List[Any]=FLAVA_CODEBOOK_STD       ,			):
             __lowerCamelCase  =		size if size is not None else {"height": 2_24, "width": 2_24}
             __lowerCamelCase  =		crop_size if crop_size is not None else {"height": 2_24, "width": 2_24}
             __lowerCamelCase  =		codebook_size if codebook_size is not None else {"height": 1_12, "width": 1_12}
             __lowerCamelCase  =		codebook_crop_size if codebook_crop_size is not None else {"height": 1_12, "width": 1_12}

             __lowerCamelCase  =		parent
             __lowerCamelCase  =		batch_size
             __lowerCamelCase  =		num_channels
             __lowerCamelCase  =		do_resize
             __lowerCamelCase  =		do_rescale
             __lowerCamelCase  =		rescale_factor
             __lowerCamelCase  =		min_resolution
             __lowerCamelCase  =		max_resolution
             __lowerCamelCase  =		size
             __lowerCamelCase  =		resample if resample is not None else PILImageResampling.BICUBIC
             __lowerCamelCase  =		do_normalize
             __lowerCamelCase  =		image_mean
             __lowerCamelCase  =		image_std
             __lowerCamelCase  =		do_center_crop
             __lowerCamelCase  =		crop_size

             __lowerCamelCase  =		input_size_patches
             __lowerCamelCase  =		total_mask_patches
             __lowerCamelCase  =		mask_group_max_patches
             __lowerCamelCase  =		mask_group_min_patches
             __lowerCamelCase  =		mask_group_min_aspect_ratio
             __lowerCamelCase  =		mask_group_max_aspect_ratio

             __lowerCamelCase  =		codebook_do_resize
             __lowerCamelCase  =		codebook_size
             __lowerCamelCase  =		codebook_resample if codebook_resample is not None else PILImageResampling.LANCZOS
             __lowerCamelCase  =		codebook_do_center_crop
             __lowerCamelCase  =		codebook_crop_size
             __lowerCamelCase  =		codebook_do_map_pixels
             __lowerCamelCase  =		codebook_do_normalize
             __lowerCamelCase  =		codebook_image_mean
             __lowerCamelCase  =		codebook_image_std
      def      lowerCAmelCase__		(							self:					Optional[Any]  ):
             return {
                 "image_mean": self.image_mean,
                 "image_std": self.image_std,
                 "do_normalize": self.do_normalize,
                 "do_resize": self.do_resize,
                 "size": self.size,
                 "resample": self.resample,
                 "do_rescale": self.do_rescale,
                 "rescale_factor": self.rescale_factor,
                 "do_center_crop": self.do_center_crop,
                 "crop_size": self.crop_size,
                 "input_size_patches": self.input_size_patches,
                 "total_mask_patches": self.total_mask_patches,
                 "mask_group_max_patches": self.mask_group_max_patches,
                 "mask_group_min_patches": self.mask_group_min_patches,
                 "mask_group_min_aspect_ratio": self.mask_group_min_aspect_ratio,
                 "mask_group_max_aspect_ratio": self.mask_group_min_aspect_ratio,
                 "codebook_do_resize": self.codebook_do_resize,
                 "codebook_size": self.codebook_size,
                 "codebook_resample": self.codebook_resample,
                 "codebook_do_center_crop": self.codebook_do_center_crop,
                 "codebook_crop_size": self.codebook_crop_size,
                 "codebook_do_map_pixels": self.codebook_do_map_pixels,
                 "codebook_do_normalize": self.codebook_do_normalize,
                 "codebook_image_mean": self.codebook_image_mean,
                 "codebook_image_std": self.codebook_image_std,
             }
      def      lowerCAmelCase__		(							self:					Optional[int]  ):
             return (self.size["height"], self.size["width"])
      def      lowerCAmelCase__		(							self:					int  ):
             return (
                 (self.input_size_patches, self.input_size_patches)
                 if not isinstance(self.input_size_patches       ,			UpperCamelCase_  )
                 else self.input_size_patches
             )




      def      lowerCAmelCase__		(							self:					Optional[Any]  ):
             return (self.codebook_size["height"], self.codebook_size["width"])





@require_torch
@require_vision
class        lowerCamelCase__(   lowercase__					,	unittest.TestCase):
      UpperCAmelCase__ :      Optional[Any]       						=  FlavaImageProcessor if is_vision_available() else None
      UpperCAmelCase__ :      List[Any]       						=  None
      def      lowerCAmelCase__		(							self:					Optional[Any]  ):
             __lowerCamelCase  =		FlavaImageProcessingTester(self  )
      @property
      def      lowerCAmelCase__		(							self:					Dict  ):
             return self.image_processor_tester.prepare_image_processor_dict()
      def      lowerCAmelCase__		(							self:					Optional[Any]  ):
             __lowerCamelCase  =		self.image_processing_class(**self.image_processor_dict  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""image_mean"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""image_std"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""do_normalize"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""do_resize"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""resample"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""crop_size"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""do_center_crop"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""do_rescale"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""rescale_factor"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""masking_generator"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""codebook_do_resize"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""codebook_size"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""codebook_resample"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""codebook_do_center_crop"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""codebook_crop_size"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""codebook_do_map_pixels"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""codebook_do_normalize"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""codebook_image_mean"""  )  )
             self.assertTrue(hasattr(UpperCamelCase_       ,			"""codebook_image_std"""  )  )
      def      lowerCAmelCase__		(							self:					Tuple  ):
             __lowerCamelCase  =		self.image_processing_class.from_dict(self.image_processor_dict  )
             self.assertEqual(image_processor.size       ,			{"""height""": 2_24, """width""": 2_24}  )
             self.assertEqual(image_processor.crop_size       ,			{"""height""": 2_24, """width""": 2_24}  )
             self.assertEqual(image_processor.codebook_size       ,			{"""height""": 1_12, """width""": 1_12}  )
             self.assertEqual(image_processor.codebook_crop_size       ,			{"""height""": 1_12, """width""": 1_12}  )

             __lowerCamelCase  =		self.image_processing_class.from_dict(
                 self.image_processor_dict       ,			size=42       ,			crop_size=84       ,			codebook_size=33       ,			codebook_crop_size=66  )
             self.assertEqual(image_processor.size       ,			{"""height""": 42, """width""": 42}  )
             self.assertEqual(image_processor.crop_size       ,			{"""height""": 84, """width""": 84}  )
             self.assertEqual(image_processor.codebook_size       ,			{"""height""": 33, """width""": 33}  )
             self.assertEqual(image_processor.codebook_crop_size       ,			{"""height""": 66, """width""": 66}  )
      def      lowerCAmelCase__		(							self:					Any  ):
             pass
      def      lowerCAmelCase__		(							self:					Optional[int]  ):
             __lowerCamelCase  =		self.image_processing_class(**self.image_processor_dict  )
             # create random PIL images
             __lowerCamelCase  =		prepare_image_inputs(self.image_processor_tester       ,			equal_resolution=UpperCamelCase_  )
             for image in image_inputs:
                    self.assertIsInstance(UpperCamelCase_       ,			PIL.Image.Image  )

             # Test not batched input
             __lowerCamelCase  =		image_processing(image_inputs[0]       ,			return_tensors="""pt"""  )

             # Test no bool masked pos
             self.assertFalse("""bool_masked_pos""" in encoded_images  )

             __lowerCamelCase  =		self.image_processor_tester.get_expected_image_size()

             self.assertEqual(
                 encoded_images.pixel_values.shape       ,			(1, self.image_processor_tester.num_channels, expected_height, expected_width)       ,			)

             # Test batched
             __lowerCamelCase  =		image_processing(UpperCamelCase_       ,			return_tensors="""pt"""  )
             __lowerCamelCase  =		self.image_processor_tester.get_expected_image_size()

             # Test no bool masked pos
             self.assertFalse("""bool_masked_pos""" in encoded_images  )

             self.assertEqual(
                 encoded_images.pixel_values.shape       ,			(
                     self.image_processor_tester.batch_size,
                     self.image_processor_tester.num_channels,
                     expected_height,
                     expected_width,
                 )       ,			)
      def      lowerCAmelCase__		(							self:					Dict       ,			UpperCamelCase_:					str       ,			UpperCamelCase_:					Optional[Any]  ):
             __lowerCamelCase  =		self.image_processing_class(**self.image_processor_dict  )
             # create random tensors
             __lowerCamelCase  =		prepare_image_inputs(self.image_processor_tester       ,			equal_resolution=UpperCamelCase_       ,			**UpperCamelCase_  )
             for image in image_inputs:
                    self.assertIsInstance(UpperCamelCase_       ,			UpperCamelCase_  )

             # Test not batched input
             __lowerCamelCase  =		image_processing(image_inputs[0]       ,			return_tensors="""pt"""  )

             __lowerCamelCase  =		self.image_processor_tester.get_expected_image_size()
             self.assertEqual(
                 encoded_images.pixel_values.shape       ,			(1, self.image_processor_tester.num_channels, expected_height, expected_width)       ,			)

             __lowerCamelCase  =		image_processing(UpperCamelCase_       ,			return_image_mask=UpperCamelCase_       ,			return_tensors="""pt"""  )

             __lowerCamelCase  =		self.image_processor_tester.get_expected_image_size()
             self.assertEqual(
                 encoded_images.pixel_values.shape       ,			(
                     self.image_processor_tester.batch_size,
                     self.image_processor_tester.num_channels,
                     expected_height,
                     expected_width,
                 )       ,			)

             __lowerCamelCase  =		self.image_processor_tester.get_expected_mask_size()
             self.assertEqual(
                 encoded_images.bool_masked_pos.shape       ,			(
                     self.image_processor_tester.batch_size,
                     expected_height,
                     expected_width,
                 )       ,			)

             # Test batched
             __lowerCamelCase  =		image_processing(UpperCamelCase_       ,			return_tensors="""pt"""  ).pixel_values

             __lowerCamelCase  =		self.image_processor_tester.get_expected_image_size()
             self.assertEqual(
                 encoded_images.shape       ,			(
                     self.image_processor_tester.batch_size,
                     self.image_processor_tester.num_channels,
                     expected_height,
                     expected_width,
                 )       ,			)

             # Test masking
             __lowerCamelCase  =		image_processing(UpperCamelCase_       ,			return_image_mask=UpperCamelCase_       ,			return_tensors="""pt"""  )

             __lowerCamelCase  =		self.image_processor_tester.get_expected_image_size()
             self.assertEqual(
                 encoded_images.pixel_values.shape       ,			(
                     self.image_processor_tester.batch_size,
                     self.image_processor_tester.num_channels,
                     expected_height,
                     expected_width,
                 )       ,			)

             __lowerCamelCase  =		self.image_processor_tester.get_expected_mask_size()
             self.assertEqual(
                 encoded_images.bool_masked_pos.shape       ,			(
                     self.image_processor_tester.batch_size,
                     expected_height,
                     expected_width,
                 )       ,			)
      def      lowerCAmelCase__		(							self:					Optional[Any]  ):
             self._test_call_framework(np.ndarray       ,			prepare_kwargs={"""numpify""": True}  )
      def      lowerCAmelCase__		(							self:					str  ):
             self._test_call_framework(torch.Tensor       ,			prepare_kwargs={"""torchify""": True}  )
      def      lowerCAmelCase__		(							self:					Union[str, Any]  ):
             random.seed(12_34  )
             __lowerCamelCase  =		self.image_processing_class(**self.image_processor_dict  )
             __lowerCamelCase  =		prepare_image_inputs(self.image_processor_tester       ,			equal_resolution=UpperCamelCase_       ,			torchify=UpperCamelCase_  )

             # Test not batched input
             __lowerCamelCase  =		image_processing(image_inputs[0]       ,			return_image_mask=UpperCamelCase_       ,			return_tensors="""pt"""  )
             self.assertEqual(encoded_images.bool_masked_pos.sum().item()       ,			75  )




      def      lowerCAmelCase__		(							self:					Any  ):
             __lowerCamelCase  =		self.image_processing_class(**self.image_processor_dict  )
             # create random PIL images
             __lowerCamelCase  =		prepare_image_inputs(self.image_processor_tester       ,			equal_resolution=UpperCamelCase_  )
             for image in image_inputs:
                    self.assertIsInstance(UpperCamelCase_       ,			PIL.Image.Image  )

             # Test not batched input
             __lowerCamelCase  =		image_processing(image_inputs[0]       ,			return_codebook_pixels=UpperCamelCase_       ,			return_tensors="""pt"""  )
             __lowerCamelCase  =		self.image_processor_tester.get_expected_codebook_image_size()
             self.assertEqual(
                 encoded_images.codebook_pixel_values.shape       ,			(1, self.image_processor_tester.num_channels, expected_height, expected_width)       ,			)

             # Test batched
             __lowerCamelCase  =		image_processing(UpperCamelCase_       ,			return_codebook_pixels=UpperCamelCase_       ,			return_tensors="""pt"""  )
             __lowerCamelCase  =		self.image_processor_tester.get_expected_codebook_image_size()
             self.assertEqual(
                 encoded_images.codebook_pixel_values.shape       ,			(
                     self.image_processor_tester.batch_size,
                     self.image_processor_tester.num_channels,
                     expected_height,
                     expected_width,
                 )       ,			)






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								=      False


if is_vision_available():
   from PIL import Image
else:


   class 	snake_case_			:




          """simple docstring"""






          @staticmethod
          def 			A_ (  *lowercase  ,**lowercase):

                """simple docstring"""





                pass


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




       """simple docstring"""






       _lowerCamelCase           =					MODEL_FOR_VISION_2_SEQ_MAPPING
       _lowerCamelCase           =					TF_MODEL_FOR_VISION_2_SEQ_MAPPING



       def 			A_ (  self  ,lowercase  ,lowercase  ,lowercase):

             """simple docstring"""





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



       def 			A_ (  self  ,lowercase  ,lowercase):

             """simple docstring"""





             UpperCAmelCase_	:						str					   =		pipe(lowercase)
             self.assertEqual(
                 lowercase  ,[
                     [{"generated_text": ANY(lowercase)}],
                     [{"generated_text": ANY(lowercase)}],
                 ]  ,)



       @require_tf
       def 			A_ (  self):

             """simple docstring"""





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

             UpperCAmelCase_	:						Tuple					   =		pipe(lowercase)
             self.assertEqual(
                 lowercase  ,[
                     {
                         "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                     },
                 ]  ,)

             UpperCAmelCase_	:						Optional[int]					   =		pipe([image, image])
             self.assertEqual(
                 lowercase  ,[
                     [
                         {
                             "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                         }
                     ],
                     [
                         {
                             "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                         }
                     ],
                 ]  ,)

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



       @require_torch
       def 			A_ (  self):

             """simple docstring"""





             UpperCAmelCase_	:						List[Any]					   =		pipeline("image-to-text"  ,model="hf-internal-testing/tiny-random-vit-gpt2")
             UpperCAmelCase_	:						str					   =		"./tests/fixtures/tests_samples/COCO/000000039769.png"

             UpperCAmelCase_	:						str					   =		pipe(lowercase)
             self.assertEqual(
                 lowercase  ,[
                     {
                         "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                     },
                 ]  ,)

             UpperCAmelCase_	:						Optional[int]					   =		pipe([image, image])
             self.assertEqual(
                 lowercase  ,[
                     [
                         {
                             "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                         }
                     ],
                     [
                         {
                             "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                         }
                     ],
                 ]  ,)



       @require_torch
       def 			A_ (  self):

             """simple docstring"""





             UpperCAmelCase_	:						List[Any]					   =		pipeline("image-to-text"  ,model="hf-internal-testing/tiny-random-BlipForConditionalGeneration")
             UpperCAmelCase_	:						Union[str, Any]					   =		"./tests/fixtures/tests_samples/COCO/000000039769.png"
             UpperCAmelCase_	:						Optional[Any]					   =		"a photo of"

             UpperCAmelCase_	:						Any					   =		pipe(lowercase  ,prompt=lowercase)
             self.assertTrue(outputs[0]["generated_text"].startswith(lowercase))



       @slow
       @require_torch
       def 			A_ (  self):

             """simple docstring"""





             UpperCAmelCase_	:						List[Any]					   =		pipeline("image-to-text"  ,model="ydshieh/vit-gpt2-coco-en")
             UpperCAmelCase_	:						List[str]					   =		"./tests/fixtures/tests_samples/COCO/000000039769.png"

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

             UpperCAmelCase_	:						Optional[Any]					   =		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 			A_ (  self):

             """simple docstring"""





             UpperCAmelCase_	:						Any					   =		pipeline("image-to-text"  ,model="Salesforce/blip-image-captioning-base")
             UpperCAmelCase_	:						str					   =		"https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
             UpperCAmelCase_	:						Optional[Any]					   =		Image.open(requests.get(lowercase  ,stream=lowercase).raw)

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



       @slow
       @require_torch
       def 			A_ (  self):

             """simple docstring"""





             UpperCAmelCase_	:						str					   =		pipeline("image-to-text"  ,model="microsoft/git-base-coco")
             UpperCAmelCase_	:						Union[str, Any]					   =		"https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
             UpperCAmelCase_	:						int					   =		Image.open(requests.get(lowercase  ,stream=lowercase).raw)

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



       @slow
       @require_torch
       def 			A_ (  self):

             """simple docstring"""





             UpperCAmelCase_	:						Any					   =		pipeline("image-to-text"  ,model="Salesforce/blip-image-captioning-base")
             UpperCAmelCase_	:						Union[str, Any]					   =		"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
             UpperCAmelCase_	:						int					   =		Image.open(requests.get(lowercase  ,stream=lowercase).raw)

             UpperCAmelCase_	:						Any					   =		"a photography of"

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

             with self.assertRaises(lowercase):
                   UpperCAmelCase_	:						Tuple					   =		pipe([image, image]  ,prompt=[prompt, prompt])



       @slow
       @require_torch
       def 			A_ (  self):

             """simple docstring"""





             UpperCAmelCase_	:						Optional[int]					   =		pipeline("image-to-text"  ,model="microsoft/git-base-coco")
             UpperCAmelCase_	:						List[str]					   =		"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
             UpperCAmelCase_	:						List[str]					   =		Image.open(requests.get(lowercase  ,stream=lowercase).raw)

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

             UpperCAmelCase_	:						Tuple					   =		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):
                   UpperCAmelCase_	:						Tuple					   =		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):

             """simple docstring"""





             UpperCAmelCase_	:						Optional[int]					   =		pipeline("image-to-text"  ,model="google/pix2struct-ai2d-base")
             UpperCAmelCase_	:						Any					   =		"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
             UpperCAmelCase_	:						Union[str, Any]					   =		Image.open(requests.get(lowercase  ,stream=lowercase).raw)

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

             UpperCAmelCase_	:						Dict					   =		pipe(lowercase  ,prompt=lowercase)
             self.assertEqual(lowercase  ,[{"generated_text": "ash cloud"}])

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



       @slow
       @require_tf
       def 			A_ (  self):

             """simple docstring"""





             UpperCAmelCase_	:						Union[str, Any]					   =		pipeline("image-to-text"  ,model="ydshieh/vit-gpt2-coco-en"  ,framework="tf")
             UpperCAmelCase_	:						str					   =		"./tests/fixtures/tests_samples/COCO/000000039769.png"

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

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