




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


if is_vision_available():
				from PIL import Image
else:



				class  A		:




								'''simple docstring'''





								@staticmethod
								def 	a_	(*_UpperCAmelCase			,  **_UpperCAmelCase      )     ->	List[str]:
											pass



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




				'''simple docstring'''





				A				     =    MODEL_FOR_VISION_2_SEQ_MAPPING
				A				     =    TF_MODEL_FOR_VISION_2_SEQ_MAPPING
				def 	a_	(self			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase      )     ->	Optional[int]:
							__UpperCamelCase				:      Dict									=       pipeline("image-to-text"			,  model=_UpperCAmelCase			,  tokenizer=_UpperCAmelCase			,  image_processor=_UpperCAmelCase      )
							__UpperCamelCase				:      Tuple									=       [
							    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"      ),
							    "./tests/fixtures/tests_samples/COCO/000000039769.png",
							]
							return pipe, examples
				def 	a_	(self			,  _UpperCAmelCase			,  _UpperCAmelCase      )     ->	Optional[int]:
							__UpperCamelCase				:      Optional[Any]									=       pipe(_UpperCAmelCase      )
							self.assertEqual(
							    _UpperCAmelCase			,  [
							        [{"generated_text": ANY(_UpperCAmelCase      )}],
							        [{"generated_text": ANY(_UpperCAmelCase      )}],
							    ]			,  )
				@require_tf
				def 	a_	(self      )     ->	Any:
							__UpperCamelCase				:      Union[str, Any]									=       pipeline("image-to-text"			,  model="hf-internal-testing/tiny-random-vit-gpt2"			,  framework="tf"      )
							__UpperCamelCase				:      Dict									=       "./tests/fixtures/tests_samples/COCO/000000039769.png"

							__UpperCamelCase				:      Union[str, Any]									=       pipe(_UpperCAmelCase      )
							self.assertEqual(
							    _UpperCAmelCase			,  [
							        {
							            "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
							        },
							    ]			,  )

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

							__UpperCamelCase				:      List[Any]									=       pipe(_UpperCAmelCase			,  max_new_tokens=1      )
							self.assertEqual(
							    _UpperCAmelCase			,  [{"generated_text": "growth"}]			,  )
				@require_torch
				def 	a_	(self      )     ->	List[str]:
							__UpperCamelCase				:      Optional[Any]									=       pipeline("image-to-text"			,  model="hf-internal-testing/tiny-random-vit-gpt2"      )
							__UpperCamelCase				:      List[str]									=       "./tests/fixtures/tests_samples/COCO/000000039769.png"

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

							__UpperCamelCase				:      Union[str, Any]									=       pipe([image, image]      )
							self.assertEqual(
							    _UpperCAmelCase			,  [
							        [
							            {
							                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
							            }
							        ],
							        [
							            {
							                "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
							            }
							        ],
							    ]			,  )
				@require_torch
				def 	a_	(self      )     ->	List[Any]:
							__UpperCamelCase				:      Any									=       pipeline("image-to-text"			,  model="hf-internal-testing/tiny-random-BlipForConditionalGeneration"      )
							__UpperCamelCase				:      str									=       "./tests/fixtures/tests_samples/COCO/000000039769.png"
							__UpperCamelCase				:      str									=       "a photo of"

							__UpperCamelCase				:      str									=       pipe(_UpperCAmelCase			,  prompt=_UpperCAmelCase      )
							self.assertTrue(outputs[0]["generated_text"].startswith(_UpperCAmelCase      )      )
				@slow
				@require_torch
				def 	a_	(self      )     ->	int:
							__UpperCamelCase				:      Optional[int]									=       pipeline("image-to-text"			,  model="ydshieh/vit-gpt2-coco-en"      )
							__UpperCamelCase				:      str									=       "./tests/fixtures/tests_samples/COCO/000000039769.png"

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

							__UpperCamelCase				:      int									=       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]:
							__UpperCamelCase				:      Optional[Any]									=       pipeline("image-to-text"			,  model="Salesforce/blip-image-captioning-base"      )
							__UpperCamelCase				:      Dict									=       "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
							__UpperCamelCase				:      Any									=       Image.open(requests.get(_UpperCAmelCase			,  stream=_UpperCAmelCase      ).raw      )

							__UpperCamelCase				:      Any									=       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      )     ->	Dict:
							__UpperCamelCase				:      Union[str, Any]									=       pipeline("image-to-text"			,  model="microsoft/git-base-coco"      )
							__UpperCamelCase				:      List[Any]									=       "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
							__UpperCamelCase				:      Optional[Any]									=       Image.open(requests.get(_UpperCAmelCase			,  stream=_UpperCAmelCase      ).raw      )

							__UpperCamelCase				:      Dict									=       pipe(_UpperCAmelCase      )
							self.assertEqual(_UpperCAmelCase			,  [{"generated_text": "a cartoon of a purple character."}]      )
				@slow
				@require_torch
				def 	a_	(self      )     ->	Union[str, Any]:
							__UpperCamelCase				:      Any									=       pipeline("image-to-text"			,  model="Salesforce/blip-image-captioning-base"      )
							__UpperCamelCase				:      int									=       "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
							__UpperCamelCase				:      str									=       Image.open(requests.get(_UpperCAmelCase			,  stream=_UpperCAmelCase      ).raw      )

							__UpperCamelCase				:      List[Any]									=       "a photography of"

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

							with self.assertRaises(_UpperCAmelCase      ):
										__UpperCamelCase				:      Optional[int]									=       pipe([image, image]			,  prompt=[prompt, prompt]      )
				@slow
				@require_torch
				def 	a_	(self      )     ->	Optional[Any]:
							__UpperCamelCase				:      Union[str, Any]									=       pipeline("image-to-text"			,  model="microsoft/git-base-coco"      )
							__UpperCamelCase				:      List[str]									=       "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
							__UpperCamelCase				:      Tuple									=       Image.open(requests.get(_UpperCAmelCase			,  stream=_UpperCAmelCase      ).raw      )

							__UpperCamelCase				:      Dict									=       "a photo of a"

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

							__UpperCamelCase				:      Union[str, Any]									=       "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"

							__UpperCamelCase				:      Tuple									=       pipe(_UpperCAmelCase			,  prompt=_UpperCAmelCase      )
							self.assertEqual(_UpperCAmelCase			,  [{"generated_text": "ash cloud"}]      )

							with self.assertRaises(_UpperCAmelCase      ):
										__UpperCamelCase				:      int									=       pipe([image, image]			,  prompt=[prompt, prompt]      )





				@slow
				@require_tf
				def 	a_	(self      )     ->	List[Any]:
							__UpperCamelCase				:      Optional[Any]									=       pipeline("image-to-text"			,  model="ydshieh/vit-gpt2-coco-en"			,  framework="tf"      )
							__UpperCamelCase				:      Optional[int]									=       "./tests/fixtures/tests_samples/COCO/000000039769.png"

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

							__UpperCamelCase				:      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'''






from doctest import testmod
from math import sqrt

def       __lowerCAmelCase (   snake_case__						):
			__UpperCamelCase				:      list[int]									=       []
			if num < 1:
						return facs
			facs.append(1						)
			if num == 1:
						return facs
			facs.append(snake_case__						)
			for i in range(2 ,				int(sqrt(snake_case__						)						) + 1						):
						if num % i == 0:  # If i is a factor of num
									facs.append(snake_case__						)
									__UpperCamelCase				:      List[str]									=       num // i  # num//i is the other factor of num
									if d != i:  # If d and i are distinct
												facs.append(snake_case__						)  # we have found another factor
			facs.sort()
			return facs


if __name__ == "__main__":
				testmod(name='''factors_of_a_number''', verbose=True)



