

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


if is_vision_available():
       from PIL import Image
else:
       class 					a					:



             """simple docstring"""


             @staticmethod
             def 			UpperCAmelCase   (   *__lowercase      :    List[Any]	,   **__lowercase      :    Tuple      )							->   int:
               pass
@is_pipeline_test
@require_vision
class 					a					(				unittest.TestCase     ):



      """simple docstring"""


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

        __UpperCAmelCase							:			Dict     =						pipe(lowerCamelCase__      )
        self.assertEqual(
            lowerCamelCase__	,   [
                {
                    """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                },
            ]	,   )

        __UpperCAmelCase							:			Dict     =						pipe([image, image]      )
        self.assertEqual(
            lowerCamelCase__	,   [
                [
                    {
                        """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                    }
                ],
                [
                    {
                        """generated_text""": """growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"""
                    }
                ],
            ]	,   )

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

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

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

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

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

        __UpperCAmelCase							:			Optional[Any]     =						pipe([image, image]      )
        self.assertEqual(
            lowerCamelCase__	,   [
                [{"""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 			UpperCAmelCase   (   self      :    Tuple      )							->   Tuple:
        __UpperCAmelCase							:			Dict     =						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(lowerCamelCase__	,   stream=lowerCamelCase__      ).raw      )

        __UpperCAmelCase							:			List[Any]     =						pipe(lowerCamelCase__      )
        self.assertEqual(lowerCamelCase__	,   [{"""generated_text""": """a pink pokemon pokemon with a blue shirt and a blue shirt"""}]      )
      @slow
      @require_torch
      def 			UpperCAmelCase   (   self      :    List[Any]      )							->   Any:
        __UpperCAmelCase							:			int     =						pipeline("""image-to-text"""	,   model="""microsoft/git-base-coco"""      )
        __UpperCAmelCase							:			Union[str, Any]     =						"https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
        __UpperCAmelCase							:			Tuple     =						Image.open(requests.get(lowerCamelCase__	,   stream=lowerCamelCase__      ).raw      )

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

        __UpperCAmelCase							:			List[str]     =						"a photography of"

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

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

        __UpperCAmelCase							:			Optional[int]     =						"a photo of a"

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

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

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

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

        with self.assertRaises(lowerCamelCase__      ):
          __UpperCAmelCase							:			List[str]     =						pipe([image, image]	,   prompt=[prompt, prompt]      )




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

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

        __UpperCAmelCase							:			Tuple     =						pipe([image, image]      )
        self.assertEqual(
            lowerCamelCase__	,   [
                [{"""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 decimal






def        lowerCamelCase__   (					):
  __UpperCAmelCase							:			str     =						0
  __UpperCAmelCase							:			Tuple     =						decimal.Context(prec=105	)
  for i in range(2						,	100	):
    __UpperCAmelCase							:			Optional[int]     =						decimal.Decimal(__lowerCamelCase	)
    __UpperCAmelCase							:			Any     =						number.sqrt(__lowerCamelCase	)
    if len(str(__lowerCamelCase	)	) > 1:
      answer += int(str(__lowerCamelCase	)[0]	)
      __UpperCAmelCase							:			Optional[Any]     =						str(__lowerCamelCase	)[2:101]
      answer += sum(int(__lowerCamelCase	) for x in sqrt_number_str	)
  return answer


if __name__ == "__main__":
       import doctest

       doctest.testmod()
       print(f"""{solution() = }""")


