




"""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:
    _SCREAMING_SNAKE_CASE						 =     False


if is_vision_available():
    from PIL import Image
else:







    class  _SCREAMING_SNAKE_CASE       :



     '''simple docstring'''





     @staticmethod
     def lowercase_      (*lowerCAmelCase__					,     **lowerCAmelCase__   ):

      '''simple docstring'''







      pass







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



 '''simple docstring'''





 __UpperCAmelCase		   =							MODEL_FOR_VISION_2_SEQ_MAPPING
 __UpperCAmelCase		   =							TF_MODEL_FOR_VISION_2_SEQ_MAPPING






 def lowercase_      (self					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__   ):

  '''simple docstring'''







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






 def lowercase_      (self					,     lowerCAmelCase__					,     lowerCAmelCase__   ):

  '''simple docstring'''







  _UpperCamelCase      :	int					      =  pipe(lowerCAmelCase__   )
  self.assertEqual(
      lowerCAmelCase__					,     [
          [{"generated_text": ANY(lowerCAmelCase__   )}],
          [{"generated_text": ANY(lowerCAmelCase__   )}],
      ]					,     )






 @require_tf
 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Optional[Any]					      =  pipeline("image-to-text"					,     model="hf-internal-testing/tiny-random-vit-gpt2"					,     framework="tf"   )
  _UpperCamelCase      :	Dict					      =  "./tests/fixtures/tests_samples/COCO/000000039769.png"

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

  _UpperCamelCase      :	List[Any]					      =  pipe([image, image]   )
  self.assertEqual(
      lowerCAmelCase__					,     [
          [
              {
                  "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
              }
          ],
          [
              {
                  "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
              }
          ],
      ]					,     )

  _UpperCamelCase      :	Dict					      =  pipe(lowerCAmelCase__					,     max_new_tokens=1   )
  self.assertEqual(
      lowerCAmelCase__					,     [{"generated_text": "growth"}]					,     )






 @require_torch
 def lowercase_      (self   ):

  '''simple docstring'''







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

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

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






 @require_torch
 def lowercase_      (self   ):

  '''simple docstring'''







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

  _UpperCamelCase      :	Dict					      =  pipe(lowerCAmelCase__					,     prompt=lowerCAmelCase__   )
  self.assertTrue(outputs[0]["generated_text"].startswith(lowerCAmelCase__   )   )






 @slow
 @require_torch
 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	str					      =  pipeline("image-to-text"					,     model="ydshieh/vit-gpt2-coco-en"   )
  _UpperCamelCase      :	int					      =  "./tests/fixtures/tests_samples/COCO/000000039769.png"

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

  _UpperCamelCase      :	List[str]					      =  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 lowercase_      (self   ):

  '''simple docstring'''







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

  _UpperCamelCase      :	Union[str, Any]					      =  pipe(lowerCAmelCase__   )
  self.assertEqual(lowerCAmelCase__					,     [{"generated_text": "a pink pokemon pokemon with a blue shirt and a blue shirt"}]   )






 @slow
 @require_torch
 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Dict					      =  pipeline("image-to-text"					,     model="microsoft/git-base-coco"   )
  _UpperCamelCase      :	Tuple					      =  "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
  _UpperCamelCase      :	List[Any]					      =  Image.open(requests.get(lowerCAmelCase__					,     stream=lowerCAmelCase__   ).raw   )

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






 @slow
 @require_torch
 def lowercase_      (self   ):

  '''simple docstring'''







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

  _UpperCamelCase      :	str					      =  "a photography of"

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

  with self.assertRaises(lowerCAmelCase__   ):
   _UpperCamelCase      :	Tuple					      =  pipe([image, image]					,     prompt=[prompt, prompt]   )






 @slow
 @require_torch
 def lowercase_      (self   ):

  '''simple docstring'''







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

  _UpperCamelCase      :	int					      =  "a photo of a"

  _UpperCamelCase      :	int					      =  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__   ):
   _UpperCamelCase      :	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 lowercase_      (self   ):

  '''simple docstring'''







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

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

  _UpperCamelCase      :	List[Any]					      =  pipe(lowerCAmelCase__					,     prompt=lowerCAmelCase__   )
  self.assertEqual(lowerCAmelCase__					,     [{"generated_text": "ash cloud"}]   )

  with self.assertRaises(lowerCAmelCase__   ):
   _UpperCamelCase      :	List[Any]					      =  pipe([image, image]					,     prompt=[prompt, prompt]   )






 @slow
 @require_tf
 def lowercase_      (self   ):

  '''simple docstring'''







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

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

  _UpperCamelCase      :	Optional[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 "}],
      ]					,     )









"""simple docstring"""
import platform
from argparse import ArgumentParser

import huggingface_hub
import pandas
import pyarrow

from datasets import __version__ as version
from datasets.commands import BaseDatasetsCLICommand






def 				__lowerCAmelCase					(					__lowerCAmelCase			:		Union[str, Any]						)    ->       int:
 return EnvironmentCommand()







class  _SCREAMING_SNAKE_CASE       (     SCREAMING_SNAKE_CASE__				):



 '''simple docstring'''





 @staticmethod
 def lowercase_      (lowerCAmelCase__   ):

  '''simple docstring'''







  _UpperCamelCase      :	Optional[Any]					      =  parser.add_parser("env"					,     help="Print relevant system environment info."   )
  download_parser.set_defaults(func=lowerCAmelCase__   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Any					      =  {
      "`datasets` version": version,
      "Platform": platform.platform(),
      "Python version": platform.python_version(),
      "Huggingface_hub version": huggingface_hub.__version__,
      "PyArrow version": pyarrow.__version__,
      "Pandas version": pandas.__version__,
  }

  print("\nCopy-and-paste the text below in your GitHub issue.\n"   )
  print(self.format_dict(lowerCAmelCase__   )   )

  return info






 @staticmethod
 def lowercase_      (lowerCAmelCase__   ):

  '''simple docstring'''







  return "\n".join([F"- {prop}: {val}" for prop, val in d.items()]   ) + "\n"



