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


if is_vision_available():
   from PIL import Image
else:

   class 		a__						:
      @staticmethod
      def       __magic_name__      (      *_a     ,   **_a    ):
             pass

@is_pipeline_test
@require_vision
class 		a__						(				unittest.TestCase						):
   __lowerCAmelCase						=    MODEL_FOR_VISION_2_SEQ_MAPPING
   __lowerCAmelCase						=    TF_MODEL_FOR_VISION_2_SEQ_MAPPING
   def       __magic_name__      (      self     ,   _a     ,   _a     ,   _a    ):
          lowercase   :    Any			=							pipeline("image-to-text"     ,   model=_a     ,   tokenizer=_a     ,   image_processor=_a    )
          lowercase   :    int			=							[
              Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"    ),
              "./tests/fixtures/tests_samples/COCO/000000039769.png",
          ]
          return pipe, examples
   def       __magic_name__      (      self     ,   _a     ,   _a    ):
          lowercase   :    Optional[int]			=							pipe(_a    )
          self.assertEqual(
              _a     ,   [
                  [{"generated_text": ANY(_a    )}],
                  [{"generated_text": ANY(_a    )}],
              ]     ,   )
   @require_tf
   def       __magic_name__      (      self    ):
          lowercase   :    List[str]			=							pipeline("image-to-text"     ,   model="hf-internal-testing/tiny-random-vit-gpt2"     ,   framework="tf"    )
          lowercase   :    str			=							"./tests/fixtures/tests_samples/COCO/000000039769.png"

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

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

          lowercase   :    str			=							pipe(_a     ,   max_new_tokens=1    )
          self.assertEqual(
              _a     ,   [{"generated_text": "growth"}]     ,   )
   @require_torch
   def       __magic_name__      (      self    ):
          lowercase   :    Tuple			=							pipeline("image-to-text"     ,   model="hf-internal-testing/tiny-random-vit-gpt2"    )
          lowercase   :    List[str]			=							"./tests/fixtures/tests_samples/COCO/000000039769.png"

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

          lowercase   :    int			=							pipe([image, image]    )
          self.assertEqual(
              _a     ,   [
                  [
                      {
                          "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                      }
                  ],
                  [
                      {
                          "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                      }
                  ],
              ]     ,   )
   @require_torch
   def       __magic_name__      (      self    ):
          lowercase   :    Optional[Any]			=							pipeline("image-to-text"     ,   model="hf-internal-testing/tiny-random-BlipForConditionalGeneration"    )
          lowercase   :    Optional[Any]			=							"./tests/fixtures/tests_samples/COCO/000000039769.png"
          lowercase   :    List[Any]			=							"a photo of"

          lowercase   :    Tuple			=							pipe(_a     ,   prompt=_a    )
          self.assertTrue(outputs[0]["generated_text"].startswith(_a    )    )
   @slow
   @require_torch
   def       __magic_name__      (      self    ):
          lowercase   :    Any			=							pipeline("image-to-text"     ,   model="ydshieh/vit-gpt2-coco-en"    )
          lowercase   :    Tuple			=							"./tests/fixtures/tests_samples/COCO/000000039769.png"

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

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

          lowercase   :    Optional[Any]			=							pipe(_a    )
          self.assertEqual(_a     ,   [{"generated_text": "a pink pokemon pokemon with a blue shirt and a blue shirt"}]    )
   @slow
   @require_torch
   def       __magic_name__      (      self    ):
          lowercase   :    Optional[int]			=							pipeline("image-to-text"     ,   model="microsoft/git-base-coco"    )
          lowercase   :    Optional[int]			=							"https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
          lowercase   :    Tuple			=							Image.open(requests.get(_a     ,   stream=_a    ).raw    )

          lowercase   :    str			=							pipe(_a    )
          self.assertEqual(_a     ,   [{"generated_text": "a cartoon of a purple character."}]    )
   @slow
   @require_torch
   def       __magic_name__      (      self    ):
          lowercase   :    int			=							pipeline("image-to-text"     ,   model="Salesforce/blip-image-captioning-base"    )
          lowercase   :    List[Any]			=							"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
          lowercase   :    str			=							Image.open(requests.get(_a     ,   stream=_a    ).raw    )

          lowercase   :    Dict			=							"a photography of"

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

          with self.assertRaises(_a    ):
                 lowercase   :    Dict			=							pipe([image, image]     ,   prompt=[prompt, prompt]    )
   @slow
   @require_torch
   def       __magic_name__      (      self    ):
          lowercase   :    Dict			=							pipeline("image-to-text"     ,   model="microsoft/git-base-coco"    )
          lowercase   :    Any			=							"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
          lowercase   :    Dict			=							Image.open(requests.get(_a     ,   stream=_a    ).raw    )

          lowercase   :    Dict			=							"a photo of a"

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

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

          lowercase   :    Optional[int]			=							"What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"

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

          with self.assertRaises(_a    ):
                 lowercase   :    Optional[int]			=							pipe([image, image]     ,   prompt=[prompt, prompt]    )

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

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

          lowercase   :    List[Any]			=							pipe([image, image]    )
          self.assertEqual(
              _a     ,   [
                  [{"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 ...configuration_utils import PretrainedConfig
from ...utils import logging


_A      :	str       		=	logging.get_logger(__name__)

_A      :	Optional[int]       		=	{
    """ZinengTang/tvlt-base""": """https://huggingface.co/ZinengTang/tvlt-base/blob/main/config.json""",
}

class 		a__						(				a_						):
   __lowerCAmelCase						=    """tvlt"""
   def __init__(      self     ,   _a=224     ,   _a=2_048     ,   _a=128     ,   _a=[16, 16]     ,   _a=[16, 16]     ,   _a=3     ,   _a=1     ,   _a=8     ,   _a=768     ,   _a=12     ,   _a=12     ,   _a=3_072     ,   _a="gelu"     ,   _a=0.0     ,   _a=0.0     ,   _a=0.0_2     ,   _a=1E-6     ,   _a=True     ,   _a=False     ,   _a=16     ,   _a=512     ,   _a=8     ,   _a=2_048     ,   _a=0.7_5     ,   _a=0.1_5     ,   _a="frame-level"     ,   _a=True     ,   _a=True     ,   _a="classification"     ,   **_a     ,   ):
          super().__init__(**_a    )

          if audio_mask_type not in ("frame-level", "patch_level"):
                 raise ValueError(
                     "audio_mask_type must be one of two acceptable strategies - {'frame_level', 'patch-level') "
                     f"""got {audio_mask_type}"""    )

          lowercase   :    Union[str, Any]			=							image_size
          lowercase   :    Dict			=							spectrogram_length
          lowercase   :    Union[str, Any]			=							frequency_length
          lowercase   :    Union[str, Any]			=							image_patch_size
          lowercase   :    Any			=							audio_patch_size
          lowercase   :    int			=							num_image_channels
          lowercase   :    Union[str, Any]			=							num_audio_channels
          lowercase   :    Any			=							num_frames

          lowercase   :    List[str]			=							hidden_size
          lowercase   :    List[str]			=							num_hidden_layers
          lowercase   :    List[Any]			=							num_attention_heads
          lowercase   :    int			=							intermediate_size
          lowercase   :    Tuple			=							hidden_act
          lowercase   :    int			=							hidden_dropout_prob
          lowercase   :    Dict			=							attention_probs_dropout_prob
          lowercase   :    List[Any]			=							initializer_range
          lowercase   :    Union[str, Any]			=							layer_norm_eps
          lowercase   :    Dict			=							qkv_bias
          lowercase   :    List[Any]			=							use_mean_pooling

          lowercase   :    List[Any]			=							decoder_num_attention_heads
          lowercase   :    Union[str, Any]			=							decoder_hidden_size
          lowercase   :    Dict			=							decoder_num_hidden_layers
          lowercase   :    Union[str, Any]			=							decoder_intermediate_size
          lowercase   :    List[str]			=							pixel_mask_ratio
          lowercase   :    str			=							audio_mask_ratio
          lowercase   :    Any			=							audio_mask_type

          lowercase   :    Union[str, Any]			=							task_matching
          lowercase   :    Optional[Any]			=							task_mae
          lowercase   :    List[str]			=							loss_type


