


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


if is_vision_available():
		from PIL import Image
else:
		class snake_case   :







				@staticmethod
				def 			a_			(       *a__   :							List[str]     , **a__   :							Union[str, Any]		)							->    List[str]:





								'''simple docstring'''







								pass
@is_pipeline_test
@require_vision
class snake_case   (	unittest.TestCase):
		__UpperCamelCase							     =      MODEL_FOR_VISION_2_SEQ_MAPPING
		__UpperCamelCase							     =      TF_MODEL_FOR_VISION_2_SEQ_MAPPING







		def 			a_			(       self   :							Optional[Any]     , a__   :							Optional[Any]     , a__   :							List[str]     , a__   :							Union[str, Any]		)							->    Optional[Any]:





						'''simple docstring'''







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







		def 			a_			(       self   :							Optional[int]     , a__   :							Optional[Any]     , a__   :							Tuple		)							->    List[str]:





						'''simple docstring'''







						_A       	=      pipe(a__		)
						self.assertEqual(
						    a__     , [
						        [{"generated_text": ANY(a__		)}],
						        [{"generated_text": ANY(a__		)}],
						    ]     , )







		@require_tf
		def 			a_			(       self   :							int		)							->    Any:





						'''simple docstring'''







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

						_A       	=      pipe(a__		)
						self.assertEqual(
						    a__     , [
						        {
						            "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
						        },
						    ]     , )

						_A       	=      pipe([image, image]		)
						self.assertEqual(
						    a__     , [
						        [
						            {
						                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
						            }
						        ],
						        [
						            {
						                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
						            }
						        ],
						    ]     , )

						_A       	=      pipe(a__     , max_new_tokens=1		)
						self.assertEqual(
						    a__     , [{"generated_text": "growth"}]     , )







		@require_torch
		def 			a_			(       self   :							Any		)							->    int:





						'''simple docstring'''







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

						_A       	=      pipe(a__		)
						self.assertEqual(
						    a__     , [
						        {
						            "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
						        },
						    ]     , )

						_A       	=      pipe([image, image]		)
						self.assertEqual(
						    a__     , [
						        [
						            {
						                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
						            }
						        ],
						        [
						            {
						                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
						            }
						        ],
						    ]     , )







		@require_torch
		def 			a_			(       self   :							Any		)							->    Any:





						'''simple docstring'''







						_A       	=      pipeline("image-to-text"     , model="hf-internal-testing/tiny-random-BlipForConditionalGeneration"		)
						_A       	=      "./tests/fixtures/tests_samples/COCO/000000039769.png"
						_A       	=      "a photo of"

						_A       	=      pipe(a__     , prompt=a__		)
						self.assertTrue(outputs[0]["generated_text"].startswith(a__		)		)







		@slow
		@require_torch
		def 			a_			(       self   :							Optional[Any]		)							->    Union[str, Any]:





						'''simple docstring'''







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

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

						_A       	=      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 			a_			(       self   :							Dict		)							->    List[str]:





						'''simple docstring'''







						_A       	=      pipeline("image-to-text"     , model="Salesforce/blip-image-captioning-base"		)
						_A       	=      "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
						_A       	=      Image.open(requests.get(a__     , stream=a__		).raw		)

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







		@slow
		@require_torch
		def 			a_			(       self   :							Tuple		)							->    int:





						'''simple docstring'''







						_A       	=      pipeline("image-to-text"     , model="microsoft/git-base-coco"		)
						_A       	=      "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
						_A       	=      Image.open(requests.get(a__     , stream=a__		).raw		)

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







		@slow
		@require_torch
		def 			a_			(       self   :							Optional[int]		)							->    Union[str, Any]:





						'''simple docstring'''







						_A       	=      pipeline("image-to-text"     , model="Salesforce/blip-image-captioning-base"		)
						_A       	=      "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
						_A       	=      Image.open(requests.get(a__     , stream=a__		).raw		)

						_A       	=      "a photography of"

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

						with self.assertRaises(a__		):
										_A       	=      pipe([image, image]     , prompt=[prompt, prompt]		)







		@slow
		@require_torch
		def 			a_			(       self   :							Union[str, Any]		)							->    Tuple:





						'''simple docstring'''







						_A       	=      pipeline("image-to-text"     , model="microsoft/git-base-coco"		)
						_A       	=      "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
						_A       	=      Image.open(requests.get(a__     , stream=a__		).raw		)

						_A       	=      "a photo of a"

						_A       	=      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__		):
										_A       	=      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   :							Dict		)							->    List[Any]:





						'''simple docstring'''







						_A       	=      pipeline("image-to-text"     , model="google/pix2struct-ai2d-base"		)
						_A       	=      "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
						_A       	=      Image.open(requests.get(a__     , stream=a__		).raw		)

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

						_A       	=      pipe(a__     , prompt=a__		)
						self.assertEqual(a__     , [{"generated_text": "ash cloud"}]		)

						with self.assertRaises(a__		):
										_A       	=      pipe([image, image]     , prompt=[prompt, prompt]		)







		@slow
		@require_tf
		def 			a_			(       self   :							List[Any]		)							->    Any:





						'''simple docstring'''







						_A       	=      pipeline("image-to-text"     , model="ydshieh/vit-gpt2-coco-en"     , framework="tf"		)
						_A       	=      "./tests/fixtures/tests_samples/COCO/000000039769.png"

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

						_A       	=      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 .hash_table import HashTable
class snake_case   (	_UpperCamelCase):







		def __init__(       self   :							Any     , *a__   :							Any     , **a__   :							Tuple		)							->    Tuple:





						'''simple docstring'''







						super().__init__(*a__     , **a__		)







		def 			a_			(       self   :							Tuple     , a__   :							int     , a__   :							str=None		)							->    Optional[int]:





						'''simple docstring'''







						_A       	=      1
						_A       	=      self.hash_function(key + i * i		)

						while self.values[new_key] is not None and self.values[new_key] != key:
										i += 1
										_A       	=      (
										    self.hash_function(key + i * i		)
										    if not self.balanced_factor() >= self.lim_charge
										    else None
										)

										if new_key is None:
														break

						return new_key