

"""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 							lowercase_  (			*UpperCamelCase__							:       Any  ,						**UpperCamelCase__							:       List[Any])->     Union[str, Any]:



														'''simple docstring'''


														pass





@is_pipeline_test
@require_vision
class 					snake_case			(       unittest.TestCase						):
				SCREAMING_SNAKE_CASE_     :   int        =						MODEL_FOR_VISION_2_SEQ_MAPPING
				SCREAMING_SNAKE_CASE_     :   int        =						TF_MODEL_FOR_VISION_2_SEQ_MAPPING

				def 							lowercase_  (			self							:       int  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       Union[str, Any])->     Any:



											'''simple docstring'''


											__lowerCAmelCase: List[str]					   =    pipeline("image-to-text"  ,						model=UpperCamelCase__  ,						tokenizer=UpperCamelCase__  ,						image_processor=UpperCamelCase__)
											__lowerCAmelCase: str					   =    [
											    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"),
											    './tests/fixtures/tests_samples/COCO/000000039769.png',
											]
											return pipe, examples

				def 							lowercase_  (			self							:       List[Any]  ,						UpperCamelCase__							:       Any  ,						UpperCamelCase__							:       List[str])->     List[str]:



											'''simple docstring'''


											__lowerCAmelCase: str					   =    pipe(UpperCamelCase__)
											self.assertEqual(
											    UpperCamelCase__  ,						[
											        [{"generated_text": ANY(UpperCamelCase__)}],
											        [{"generated_text": ANY(UpperCamelCase__)}],
											    ]  ,						)

				@require_tf
				def 							lowercase_  (			self							:       Union[str, Any])->     Dict:



											'''simple docstring'''


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

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

											__lowerCAmelCase: List[Any]					   =    pipe([image, image])
											self.assertEqual(
											    UpperCamelCase__  ,						[
											        [
											            {
											                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
											            }
											        ],
											        [
											            {
											                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
											            }
											        ],
											    ]  ,						)

											__lowerCAmelCase: str					   =    pipe(UpperCamelCase__  ,						max_new_tokens=1)
											self.assertEqual(
											    UpperCamelCase__  ,						[{"generated_text": "growth"}]  ,						)

				@require_torch
				def 							lowercase_  (			self							:       Tuple)->     Optional[int]:



											'''simple docstring'''


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

											__lowerCAmelCase: int					   =    pipe(UpperCamelCase__)
											self.assertEqual(
											    UpperCamelCase__  ,						[
											        {
											            "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
											        },
											    ]  ,						)

											__lowerCAmelCase: Tuple					   =    pipe([image, image])
											self.assertEqual(
											    UpperCamelCase__  ,						[
											        [
											            {
											                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
											            }
											        ],
											        [
											            {
											                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
											            }
											        ],
											    ]  ,						)

				@require_torch
				def 							lowercase_  (			self							:       Dict)->     int:



											'''simple docstring'''


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

											__lowerCAmelCase: Dict					   =    pipe(UpperCamelCase__  ,						prompt=UpperCamelCase__)
											self.assertTrue(outputs[0]["generated_text"].startswith(UpperCamelCase__))

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



											'''simple docstring'''


											__lowerCAmelCase: List[str]					   =    pipeline("image-to-text"  ,						model="ydshieh/vit-gpt2-coco-en")
											__lowerCAmelCase: Any					   =    './tests/fixtures/tests_samples/COCO/000000039769.png'

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

											__lowerCAmelCase: Union[str, Any]					   =    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 							lowercase_  (			self							:       List[Any])->     Dict:



											'''simple docstring'''


											__lowerCAmelCase: int					   =    pipeline("image-to-text"  ,						model="Salesforce/blip-image-captioning-base")
											__lowerCAmelCase: Tuple					   =    'https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png'
											__lowerCAmelCase: List[Any]					   =    Image.open(requests.get(UpperCamelCase__  ,						stream=UpperCamelCase__).raw)

											__lowerCAmelCase: Optional[Any]					   =    pipe(UpperCamelCase__)
											self.assertEqual(UpperCamelCase__  ,						[{"generated_text": "a pink pokemon pokemon with a blue shirt and a blue shirt"}])

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



											'''simple docstring'''


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

											__lowerCAmelCase: Optional[int]					   =    pipe(UpperCamelCase__)
											self.assertEqual(UpperCamelCase__  ,						[{"generated_text": "a cartoon of a purple character."}])

				@slow
				@require_torch
				def 							lowercase_  (			self							:       List[str])->     List[str]:



											'''simple docstring'''


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

											__lowerCAmelCase: int					   =    'a photography of'

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

											with self.assertRaises(UpperCamelCase__):
																		__lowerCAmelCase: Union[str, Any]					   =    pipe([image, image]  ,						prompt=[prompt, prompt])

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



											'''simple docstring'''


											__lowerCAmelCase: Optional[int]					   =    pipeline("image-to-text"  ,						model="microsoft/git-base-coco")
											__lowerCAmelCase: int					   =    'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'
											__lowerCAmelCase: Optional[Any]					   =    Image.open(requests.get(UpperCamelCase__  ,						stream=UpperCamelCase__).raw)

											__lowerCAmelCase: Optional[int]					   =    'a photo of a'

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



											'''simple docstring'''


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

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

											__lowerCAmelCase: Union[str, Any]					   =    pipe(UpperCamelCase__  ,						prompt=UpperCamelCase__)
											self.assertEqual(UpperCamelCase__  ,						[{"generated_text": "ash cloud"}])

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




				@slow
				@require_tf
				def 							lowercase_  (			self							:       Dict)->     List[str]:



											'''simple docstring'''


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

											__lowerCAmelCase: Optional[Any]					   =    pipe(UpperCamelCase__)
											self.assertEqual(UpperCamelCase__  ,						[{"generated_text": "a cat laying on a blanket next to a cat laying on a bed "}])

											__lowerCAmelCase: List[Any]					   =    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 "}],
											    ]  ,						)





"""simple docstring"""


import math






def 					a__					(					__SCREAMING_SNAKE_CASE				)			->			list:
		if n <= 0:
				raise ValueError("Only positive integers have prime factors"				)
		__lowerCAmelCase: Tuple					   =    []
		while n % 2 == 0:
				pf.append(2				)
				__lowerCAmelCase: str					   =    int(n / 2				)
		for i in range(3      ,				int(math.sqrt(__SCREAMING_SNAKE_CASE				)				) + 1      ,				2				):
				while n % i == 0:
						pf.append(__SCREAMING_SNAKE_CASE				)
						__lowerCAmelCase: List[Any]					   =    int(n / i				)
		if n > 2:
				pf.append(__SCREAMING_SNAKE_CASE				)
		return pf






def 					a__					(					__SCREAMING_SNAKE_CASE				)			->			int:
		if n <= 0:
				raise ValueError("Only positive numbers are accepted"				)
		__lowerCAmelCase: int					   =    1
		__lowerCAmelCase: str					   =    1
		while n % 2 == 0:
				temp += 1
				__lowerCAmelCase: Dict					   =    int(n / 2				)
		div *= temp
		for i in range(3      ,				int(math.sqrt(__SCREAMING_SNAKE_CASE				)				) + 1      ,				2				):
				__lowerCAmelCase: int					   =    1
				while n % i == 0:
						temp += 1
						__lowerCAmelCase: Tuple					   =    int(n / i				)
				div *= temp
		if n > 1:
				div *= 2
		return div






def 					a__					(					__SCREAMING_SNAKE_CASE				)			->			int:
		if n <= 0:
				raise ValueError("Only positive numbers are accepted"				)
		__lowerCAmelCase: Dict					   =    1
		__lowerCAmelCase: int					   =    1
		while n % 2 == 0:
				temp += 1
				__lowerCAmelCase: Tuple					   =    int(n / 2				)
		if temp > 1:
				s *= (2**temp - 1) / (2 - 1)
		for i in range(3      ,				int(math.sqrt(__SCREAMING_SNAKE_CASE				)				) + 1      ,				2				):
				__lowerCAmelCase: List[Any]					   =    1
				while n % i == 0:
						temp += 1
						__lowerCAmelCase: List[str]					   =    int(n / i				)
				if temp > 1:
						s *= (i**temp - 1) / (i - 1)
		return int(__SCREAMING_SNAKE_CASE				)






def 					a__					(					__SCREAMING_SNAKE_CASE				)			->			int:
		__lowerCAmelCase: Optional[int]					   =    n
		for x in set(prime_factors(__SCREAMING_SNAKE_CASE				)				):
				s *= (x - 1) / x
		return int(__SCREAMING_SNAKE_CASE				)


if __name__ == "__main__":
			import doctest

			doctest.testmod()


