
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      _lowerCAmelCase :




							@staticmethod
							def 					__a						( *_UpperCamelCase    ,    **_UpperCamelCase					)    ->				Optional[int]:
										pass





@is_pipeline_test
@require_vision
class      _lowerCAmelCase (     unittest.TestCase	):
				_lowercase      		=MODEL_FOR_VISION_2_SEQ_MAPPING
				_lowercase      		=TF_MODEL_FOR_VISION_2_SEQ_MAPPING




				def 					__a						( self    ,    _UpperCamelCase    ,    _UpperCamelCase    ,    _UpperCamelCase					)    ->				Optional[Any]:
							lowerCAmelCase_      =     pipeline("image-to-text"    ,    model=_UpperCamelCase    ,    tokenizer=_UpperCamelCase    ,    image_processor=_UpperCamelCase					)
							lowerCAmelCase_      =     [
							    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"					),
							    "./tests/fixtures/tests_samples/COCO/000000039769.png",
							]
							return pipe, examples




				def 					__a						( self    ,    _UpperCamelCase    ,    _UpperCamelCase					)    ->				List[str]:
							lowerCAmelCase_      =     pipe(_UpperCamelCase					)
							self.assertEqual(
							    _UpperCamelCase    ,    [
							        [{"generated_text": ANY(_UpperCamelCase					)}],
							        [{"generated_text": ANY(_UpperCamelCase					)}],
							    ]    ,    )




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

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

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

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




				@require_torch
				def 					__a						( self					)    ->				Optional[int]:
							lowerCAmelCase_      =     pipeline("image-to-text"    ,    model="hf-internal-testing/tiny-random-vit-gpt2"					)
							lowerCAmelCase_      =     "./tests/fixtures/tests_samples/COCO/000000039769.png"

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

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




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

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




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

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

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

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




				@slow
				@require_torch
				def 					__a						( self					)    ->				int:
							lowerCAmelCase_      =     pipeline("image-to-text"    ,    model="microsoft/git-base-coco"					)
							lowerCAmelCase_      =     "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
							lowerCAmelCase_      =     Image.open(requests.get(_UpperCamelCase    ,    stream=_UpperCamelCase					).raw					)

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




				@slow
				@require_torch
				def 					__a						( self					)    ->				str:
							lowerCAmelCase_      =     pipeline("image-to-text"    ,    model="Salesforce/blip-image-captioning-base"					)
							lowerCAmelCase_      =     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
							lowerCAmelCase_      =     Image.open(requests.get(_UpperCamelCase    ,    stream=_UpperCamelCase					).raw					)

							lowerCAmelCase_      =     "a photography of"

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

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




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

							lowerCAmelCase_      =     "a photo of a"

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

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

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

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

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




				@slow
				@require_tf
				def 					__a						( self					)    ->				Dict:
							lowerCAmelCase_      =     pipeline("image-to-text"    ,    model="ydshieh/vit-gpt2-coco-en"    ,    framework="tf"					)
							lowerCAmelCase_      =     "./tests/fixtures/tests_samples/COCO/000000039769.png"

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

							lowerCAmelCase_      =     pipe([image, image]					)
							self.assertEqual(
							    _UpperCamelCase    ,    [
							        [{"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






def        lowerCamelCase__    (    __lowerCAmelCase  :  int    ):




			"""simple docstring"""


			if 1 < number < 4:
						# 2 and 3 are primes
						return True
			elif number < 2 or number % 2 == 0 or number % 3 == 0:
						# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
						return False

			# All primes number are in format of 6k +/- 1
			for i in range(5   ,							int(math.sqrt(__lowerCAmelCase    ) + 1    )   ,							6    ):
						if number % i == 0 or number % (i + 2) == 0:
									return False
			return True






def        lowerCamelCase__    (    __lowerCAmelCase  :  int = 600851475143    ):




			"""simple docstring"""


			try:
						lowerCAmelCase_      =     int(__lowerCAmelCase    )
			except (TypeError, ValueError):
						raise TypeError("Parameter n must be int or castable to int."    )
			if n <= 0:
						raise ValueError("Parameter n must be greater than or equal to one."    )
			lowerCAmelCase_      =     0
			if is_prime(__lowerCAmelCase    ):
						return n
			while n % 2 == 0:
						n //= 2
			if is_prime(__lowerCAmelCase    ):
						return n
			for i in range(3   ,							int(math.sqrt(__lowerCAmelCase    )    ) + 1   ,							2    ):
						if n % i == 0:
									if is_prime(n // i    ):
												lowerCAmelCase_      =     n // i
												break
									elif is_prime(__lowerCAmelCase    ):
												lowerCAmelCase_      =     i
			return max_number


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



