





'''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 :			str							   =      False


if is_vision_available():
		from PIL import Image
else:







		class       lowerCamelCase       :


							@staticmethod
							def  SCREAMING_SNAKE_CASE_		(       *__snake_case						:	Optional[int]							,  **__snake_case						:	str							):





													'''simple docstring'''





													pass







@is_pipeline_test
@require_vision
class       lowerCamelCase       (    unittest.TestCase	):
					_SCREAMING_SNAKE_CASE				 =     MODEL_FOR_VISION_2_SEQ_MAPPING
					_SCREAMING_SNAKE_CASE				 =     TF_MODEL_FOR_VISION_2_SEQ_MAPPING


					def  SCREAMING_SNAKE_CASE_		(       self						:	Union[str, Any]							,  __snake_case						:	Optional[Any]							,  __snake_case						:	Optional[int]							,  __snake_case						:	Optional[int]							):





											'''simple docstring'''





											_snake_case: Optional[int]	       =		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  SCREAMING_SNAKE_CASE_		(       self						:	List[Any]							,  __snake_case						:	int							,  __snake_case						:	str							):





											'''simple docstring'''





											_snake_case: Union[str, Any]	       =		pipe(__snake_case							)
											self.assertEqual(
											    __snake_case							,  [
											        [{'generated_text': ANY(__snake_case							)}],
											        [{'generated_text': ANY(__snake_case							)}],
											    ]							,  )


					@require_tf
					def  SCREAMING_SNAKE_CASE_		(       self						:	str							):





											'''simple docstring'''





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

											_snake_case: Tuple	       =		pipe(__snake_case							)
											self.assertEqual(
											    __snake_case							,  [
											        {
											            'generated_text': 'growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'
											        },
											    ]							,  )

											_snake_case: Optional[Any]	       =		pipe([image, image]							)
											self.assertEqual(
											    __snake_case							,  [
											        [
											            {
											                'generated_text': 'growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'
											            }
											        ],
											        [
											            {
											                'generated_text': 'growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'
											            }
											        ],
											    ]							,  )

											_snake_case: List[Any]	       =		pipe(__snake_case							,  max_new_tokens=1							)
											self.assertEqual(
											    __snake_case							,  [{'generated_text': 'growth'}]							,  )


					@require_torch
					def  SCREAMING_SNAKE_CASE_		(       self						:	Any							):





											'''simple docstring'''





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

											_snake_case: Optional[Any]	       =		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  SCREAMING_SNAKE_CASE_		(       self						:	int							):





											'''simple docstring'''





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

											_snake_case: int	       =		pipe(__snake_case							,  prompt=__snake_case							)
											self.assertTrue(outputs[0]['generated_text'].startswith(__snake_case							)							)


					@slow
					@require_torch
					def  SCREAMING_SNAKE_CASE_		(       self						:	Union[str, Any]							):





											'''simple docstring'''





											_snake_case: Any	       =		pipeline('image-to-text'							,  model='ydshieh/vit-gpt2-coco-en'							)
											_snake_case: Dict	       =		'./tests/fixtures/tests_samples/COCO/000000039769.png'

											_snake_case: List[str]	       =		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: str	       =		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  SCREAMING_SNAKE_CASE_		(       self						:	Optional[int]							):





											'''simple docstring'''





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

											_snake_case: Union[str, 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  SCREAMING_SNAKE_CASE_		(       self						:	int							):





											'''simple docstring'''





											_snake_case: Optional[Any]	       =		pipeline('image-to-text'							,  model='microsoft/git-base-coco'							)
											_snake_case: List[Any]	       =		'https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png'
											_snake_case: List[str]	       =		Image.open(requests.get(__snake_case							,  stream=__snake_case							).raw							)

											_snake_case: int	       =		pipe(__snake_case							)
											self.assertEqual(__snake_case							,  [{'generated_text': 'a cartoon of a purple character.'}]							)


					@slow
					@require_torch
					def  SCREAMING_SNAKE_CASE_		(       self						:	Any							):





											'''simple docstring'''





											_snake_case: Optional[int]	       =		pipeline('image-to-text'							,  model='Salesforce/blip-image-captioning-base'							)
											_snake_case: Tuple	       =		'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'
											_snake_case: str	       =		Image.open(requests.get(__snake_case							,  stream=__snake_case							).raw							)

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

											_snake_case: List[Any]	       =		pipe(__snake_case							,  prompt=__snake_case							)
											self.assertEqual(__snake_case							,  [{'generated_text': 'a photography of a volcano'}]							)

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


					@slow
					@require_torch
					def  SCREAMING_SNAKE_CASE_		(       self						:	Optional[int]							):





											'''simple docstring'''





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

											_snake_case: int	       =		'a photo of a'

											_snake_case: Optional[Any]	       =		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: List[Any]	       =		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  SCREAMING_SNAKE_CASE_		(       self						:	Optional[int]							):





											'''simple docstring'''





											_snake_case: Optional[Any]	       =		pipeline('image-to-text'							,  model='google/pix2struct-ai2d-base'							)
											_snake_case: List[Any]	       =		'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'
											_snake_case: str	       =		Image.open(requests.get(__snake_case							,  stream=__snake_case							).raw							)

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

											_snake_case: int	       =		pipe(__snake_case							,  prompt=__snake_case							)
											self.assertEqual(__snake_case							,  [{'generated_text': 'ash cloud'}]							)

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




					@slow
					@require_tf
					def  SCREAMING_SNAKE_CASE_		(       self						:	str							):





											'''simple docstring'''





											_snake_case: Dict	       =		pipeline('image-to-text'							,  model='ydshieh/vit-gpt2-coco-en'							,  framework='tf'							)
											_snake_case: str	       =		'./tests/fixtures/tests_samples/COCO/000000039769.png'

											_snake_case: Optional[int]	       =		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: Dict	       =		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    lowercase_   (		lowercase__ = 400_0000    ) ->int:

						if n <= 1:
												return 0
						_snake_case: Union[str, Any]	       =		0
						_snake_case: List[Any]	       =		2
						_snake_case: Any	       =		0
						while 4 * b + a <= n:
												_snake_case       ,    _snake_case: int	       =		b, 4 * b + a
												count += a
						return count + b


if __name__ == "__main__":
		print(F'{solution() = }')





