


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


if is_vision_available():
						from PIL import Image
else:







						class 			snake_case__:







												'''simple docstring'''




												@staticmethod
												def   lowercase_	(			*__lowercase				,  **__lowercase							)   ->      List[str]:
																pass







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







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__ :					List[Any]   =							MODEL_FOR_VISION_2_SEQ_MAPPING
						SCREAMING_SNAKE_CASE__ :					Optional[int]   =							TF_MODEL_FOR_VISION_2_SEQ_MAPPING




						def   lowercase_	(			self				,  __lowercase				,  __lowercase				,  __lowercase							)   ->      Dict:
										lowerCAmelCase_	: str      			=			pipeline('''image-to-text'''				,  model=__lowercase				,  tokenizer=__lowercase				,  image_processor=__lowercase							)
										lowerCAmelCase_	: str      			=			[
										    Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							),
										    '''./tests/fixtures/tests_samples/COCO/000000039769.png''',
										]
										return pipe, examples




						def   lowercase_	(			self				,  __lowercase				,  __lowercase							)   ->      Union[str, Any]:
										lowerCAmelCase_	: Optional[int]      			=			pipe(__lowercase							)
										self.assertEqual(
										    __lowercase				,  [
										        [{'''generated_text''': ANY(__lowercase							)}],
										        [{'''generated_text''': ANY(__lowercase							)}],
										    ]				,  )




						@require_tf
						def   lowercase_	(			self							)   ->      Optional[Any]:
										lowerCAmelCase_	: List[str]      			=			pipeline('''image-to-text'''				,  model='''hf-internal-testing/tiny-random-vit-gpt2'''				,  framework='''tf'''							)
										lowerCAmelCase_	: Optional[Any]      			=			'''./tests/fixtures/tests_samples/COCO/000000039769.png'''

										lowerCAmelCase_	: Optional[Any]      			=			pipe(__lowercase							)
										self.assertEqual(
										    __lowercase				,  [
										        {
										            '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
										        },
										    ]				,  )

										lowerCAmelCase_	: Any      			=			pipe([image, image]							)
										self.assertEqual(
										    __lowercase				,  [
										        [
										            {
										                '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
										            }
										        ],
										        [
										            {
										                '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
										            }
										        ],
										    ]				,  )

										lowerCAmelCase_	: str      			=			pipe(__lowercase				,  max_new_tokens=1							)
										self.assertEqual(
										    __lowercase				,  [{'''generated_text''': '''growth'''}]				,  )




						@require_torch
						def   lowercase_	(			self							)   ->      Dict:
										lowerCAmelCase_	: Tuple      			=			pipeline('''image-to-text'''				,  model='''hf-internal-testing/tiny-random-vit-gpt2'''							)
										lowerCAmelCase_	: List[Any]      			=			'''./tests/fixtures/tests_samples/COCO/000000039769.png'''

										lowerCAmelCase_	: str      			=			pipe(__lowercase							)
										self.assertEqual(
										    __lowercase				,  [
										        {
										            '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
										        },
										    ]				,  )

										lowerCAmelCase_	: Any      			=			pipe([image, image]							)
										self.assertEqual(
										    __lowercase				,  [
										        [
										            {
										                '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
										            }
										        ],
										        [
										            {
										                '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
										            }
										        ],
										    ]				,  )




						@require_torch
						def   lowercase_	(			self							)   ->      Dict:
										lowerCAmelCase_	: Union[str, Any]      			=			pipeline('''image-to-text'''				,  model='''hf-internal-testing/tiny-random-BlipForConditionalGeneration'''							)
										lowerCAmelCase_	: str      			=			'''./tests/fixtures/tests_samples/COCO/000000039769.png'''
										lowerCAmelCase_	: Any      			=			'''a photo of'''

										lowerCAmelCase_	: Tuple      			=			pipe(__lowercase				,  prompt=__lowercase							)
										self.assertTrue(outputs[0]['''generated_text'''].startswith(__lowercase							)							)




						@slow
						@require_torch
						def   lowercase_	(			self							)   ->      Tuple:
										lowerCAmelCase_	: Tuple      			=			pipeline('''image-to-text'''				,  model='''ydshieh/vit-gpt2-coco-en'''							)
										lowerCAmelCase_	: Dict      			=			'''./tests/fixtures/tests_samples/COCO/000000039769.png'''

										lowerCAmelCase_	: str      			=			pipe(__lowercase							)
										self.assertEqual(__lowercase				,  [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}]							)

										lowerCAmelCase_	: Optional[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 '''}],
										    ]				,  )




						@slow
						@require_torch
						def   lowercase_	(			self							)   ->      Union[str, Any]:
										lowerCAmelCase_	: Union[str, Any]      			=			pipeline('''image-to-text'''				,  model='''Salesforce/blip-image-captioning-base'''							)
										lowerCAmelCase_	: Optional[Any]      			=			'''https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png'''
										lowerCAmelCase_	: Any      			=			Image.open(requests.get(__lowercase				,  stream=__lowercase							).raw							)

										lowerCAmelCase_	: int      			=			pipe(__lowercase							)
										self.assertEqual(__lowercase				,  [{'''generated_text''': '''a pink pokemon pokemon with a blue shirt and a blue shirt'''}]							)




						@slow
						@require_torch
						def   lowercase_	(			self							)   ->      Union[str, Any]:
										lowerCAmelCase_	: List[str]      			=			pipeline('''image-to-text'''				,  model='''microsoft/git-base-coco'''							)
										lowerCAmelCase_	: int      			=			'''https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png'''
										lowerCAmelCase_	: Tuple      			=			Image.open(requests.get(__lowercase				,  stream=__lowercase							).raw							)

										lowerCAmelCase_	: Dict      			=			pipe(__lowercase							)
										self.assertEqual(__lowercase				,  [{'''generated_text''': '''a cartoon of a purple character.'''}]							)




						@slow
						@require_torch
						def   lowercase_	(			self							)   ->      Union[str, Any]:
										lowerCAmelCase_	: int      			=			pipeline('''image-to-text'''				,  model='''Salesforce/blip-image-captioning-base'''							)
										lowerCAmelCase_	: List[str]      			=			'''https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'''
										lowerCAmelCase_	: Tuple      			=			Image.open(requests.get(__lowercase				,  stream=__lowercase							).raw							)

										lowerCAmelCase_	: Optional[int]      			=			'''a photography of'''

										lowerCAmelCase_	: Union[str, Any]      			=			pipe(__lowercase				,  prompt=__lowercase							)
										self.assertEqual(__lowercase				,  [{'''generated_text''': '''a photography of a volcano'''}]							)

										with self.assertRaises(__lowercase							):
														lowerCAmelCase_	: str      			=			pipe([image, image]				,  prompt=[prompt, prompt]							)




						@slow
						@require_torch
						def   lowercase_	(			self							)   ->      Any:
										lowerCAmelCase_	: Optional[Any]      			=			pipeline('''image-to-text'''				,  model='''microsoft/git-base-coco'''							)
										lowerCAmelCase_	: Optional[Any]      			=			'''https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'''
										lowerCAmelCase_	: Optional[int]      			=			Image.open(requests.get(__lowercase				,  stream=__lowercase							).raw							)

										lowerCAmelCase_	: Optional[Any]      			=			'''a photo of a'''

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

										lowerCAmelCase_	: List[str]      			=			'''What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud'''

										lowerCAmelCase_	: Any      			=			pipe(__lowercase				,  prompt=__lowercase							)
										self.assertEqual(__lowercase				,  [{'''generated_text''': '''ash cloud'''}]							)

										with self.assertRaises(__lowercase							):
														lowerCAmelCase_	: Dict      			=			pipe([image, image]				,  prompt=[prompt, prompt]							)




						@slow
						@require_tf
						def   lowercase_	(			self							)   ->      List[str]:
										lowerCAmelCase_	: List[Any]      			=			pipeline('''image-to-text'''				,  model='''ydshieh/vit-gpt2-coco-en'''				,  framework='''tf'''							)
										lowerCAmelCase_	: Tuple      			=			'''./tests/fixtures/tests_samples/COCO/000000039769.png'''

										lowerCAmelCase_	: Any      			=			pipe(__lowercase							)
										self.assertEqual(__lowercase				,  [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}]							)

										lowerCAmelCase_	: Optional[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 '''}],
										    ]				,  )



import math







class 			snake_case__:







						'''simple docstring'''




						def __init__(			self				,  __lowercase				,  __lowercase				,  __lowercase							)   ->      Tuple:
										lowerCAmelCase_	: List[str]      			=			x
										lowerCAmelCase_	: Dict      			=			y
										lowerCAmelCase_	: List[Any]      			=			z




						def __repr__(			self							)   ->      str:
										return f"""Point({self.x}, {self.y}, {self.z})"""






def      lowerCAmelCase	(						lowerCAmelCase_	,				lowerCAmelCase_	)->	float:
				return math.sqrt(abs((b.x - a.x) ** 2 + (b.y - a.y) ** 2 + (b.z - a.z) ** 2	)	)


if __name__ == "__main__":
						import doctest

						doctest.testmod()