
"""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   _UpperCAmelCase					:
        @staticmethod
        def        lowerCamelCase__						(     *snake_case_    ,     **snake_case_  ):
          pass






@is_pipeline_test
@require_vision
class   _UpperCAmelCase					(       unittest.TestCase):
    __lowercase				:			Tuple	=       MODEL_FOR_VISION_2_SEQ_MAPPING
    __lowercase				:			Dict	=       TF_MODEL_FOR_VISION_2_SEQ_MAPPING
    def        lowerCamelCase__						(     self    ,     snake_case_    ,     snake_case_    ,     snake_case_  ):
      _snake_case  :    Union[str, Any]            = pipeline("image-to-text"    ,     model=snake_case_    ,     tokenizer=snake_case_    ,     image_processor=snake_case_  )
      _snake_case  :    str            = [
          Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"  ),
          "./tests/fixtures/tests_samples/COCO/000000039769.png",
      ]
      return pipe, examples
    def        lowerCamelCase__						(     self    ,     snake_case_    ,     snake_case_  ):
      _snake_case  :    Tuple            = pipe(snake_case_  )
      self.assertEqual(
          snake_case_    ,     [
              [{"generated_text": ANY(snake_case_  )}],
              [{"generated_text": ANY(snake_case_  )}],
          ]    ,     )
    @require_tf
    def        lowerCamelCase__						(     self  ):
      _snake_case  :    List[str]            = pipeline("image-to-text"    ,     model="hf-internal-testing/tiny-random-vit-gpt2"    ,     framework="tf"  )
      _snake_case  :    Tuple            = "./tests/fixtures/tests_samples/COCO/000000039769.png"

      _snake_case  :    Any            = pipe(snake_case_  )
      self.assertEqual(
          snake_case_    ,     [
              {
                  "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
              },
          ]    ,     )

      _snake_case  :    Any            = pipe([image, image]  )
      self.assertEqual(
          snake_case_    ,     [
              [
                  {
                      "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                  }
              ],
              [
                  {
                      "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                  }
              ],
          ]    ,     )

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

      _snake_case  :    Optional[int]            = pipe(snake_case_  )
      self.assertEqual(
          snake_case_    ,     [
              {
                  "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
              },
          ]    ,     )

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

      _snake_case  :    Dict            = pipe(snake_case_    ,     prompt=snake_case_  )
      self.assertTrue(outputs[0]["generated_text"].startswith(snake_case_  )  )
    @slow
    @require_torch
    def        lowerCamelCase__						(     self  ):
      _snake_case  :    Union[str, Any]            = pipeline("image-to-text"    ,     model="ydshieh/vit-gpt2-coco-en"  )
      _snake_case  :    Optional[Any]            = "./tests/fixtures/tests_samples/COCO/000000039769.png"

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

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

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

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

      _snake_case  :    str            = "a photography of"

      _snake_case  :    List[str]            = pipe(snake_case_    ,     prompt=snake_case_  )
      self.assertEqual(snake_case_    ,     [{"generated_text": "a photography of a volcano"}]  )

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

      _snake_case  :    Any            = "a photo of a"

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

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

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

      _snake_case  :    str            = pipe(snake_case_    ,     prompt=snake_case_  )
      self.assertEqual(snake_case_    ,     [{"generated_text": "ash cloud"}]  )

      with self.assertRaises(snake_case_  ):
        _snake_case  :    Any            = pipe([image, image]    ,     prompt=[prompt, prompt]  )


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

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

      _snake_case  :    Optional[Any]            = pipe([image, image]  )
      self.assertEqual(
          snake_case_    ,     [
              [{"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'''

def      __magic_name__							(			A				)      ->		tuple[int, int]:
	# base case
	if len(A				) == 1:
		return a[0], a[0]
	else:
		# split A into half.
		snake_case							=					a[: len(A				) // 2]
		snake_case							=					a[len(A				) // 2 :]

		# 2 sub problems, 1/2 of original size.
		snake_case			,			snake_case							=					max_difference(A				)
		snake_case			,			snake_case							=					max_difference(A				)

		# get min of first and max of second
		# linear time
		snake_case							=					min(A				)
		snake_case							=					max(A				)

		# 3 cases, either (small1, big1),
		# (min_first, max_second), (small2, big2)
		# constant comparisons
		if biga - smalla > max_second - min_first and biga - smalla > biga - smalla:
			return smalla, biga
		elif biga - smalla > max_second - min_first:
			return smalla, biga
		else:
			return min_first, max_second


if __name__ == "__main__":
						import doctest

						doctest.testmod()





