



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


if is_vision_available():
      from PIL import Image
else:






      class        UpperCAmelCase_       :

       '''simple docstring'''







       @staticmethod
       def        UpperCamelCase     (				*snake_case__		:     Any ,							**snake_case__		:     List[Any]   ):



         '''simple docstring'''




         pass






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

 '''simple docstring'''
 lowercase_				:						int				=       MODEL_FOR_VISION_2_SEQ_MAPPING
 lowercase_				:						int				=       TF_MODEL_FOR_VISION_2_SEQ_MAPPING







 def        UpperCamelCase     (				self		:     int ,							snake_case__		:     Union[str, Any] ,							snake_case__		:     Optional[int] ,							snake_case__		:     Union[str, Any]   ):



   '''simple docstring'''




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







 def        UpperCamelCase     (				self		:     List[Any] ,							snake_case__		:     Any ,							snake_case__		:     List[str]   ):



   '''simple docstring'''




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







 @require_tf
 def        UpperCamelCase     (				self		:     Union[str, Any]   ):



   '''simple docstring'''




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

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

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

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







 @require_torch
 def        UpperCamelCase     (				self		:     Tuple   ):



   '''simple docstring'''




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

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

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







 @require_torch
 def        UpperCamelCase     (				self		:     Dict   ):



   '''simple docstring'''




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

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







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



   '''simple docstring'''




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

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

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



   '''simple docstring'''




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

   UpperCAmelCase__			:				Optional[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        UpperCamelCase     (				self		:     List[str]   ):



   '''simple docstring'''




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

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







 @slow
 @require_torch
 def        UpperCamelCase     (				self		:     List[str]   ):



   '''simple docstring'''




   UpperCAmelCase__			:				List[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__			:				List[str]												=       Image.open(requests.get(snake_case__ ,							stream=snake_case__   ).raw   )

   UpperCAmelCase__			:				int												=       'a photography of'

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

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







 @slow
 @require_torch
 def        UpperCamelCase     (				self		:     int   ):



   '''simple docstring'''




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

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

   UpperCAmelCase__			:				Optional[int]												=       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__   ):
     UpperCAmelCase__			:				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        UpperCamelCase     (				self		:     Any   ):



   '''simple docstring'''




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

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

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

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







 @slow
 @require_tf
 def        UpperCamelCase     (				self		:     Dict   ):



   '''simple docstring'''




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

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

   UpperCAmelCase__			:				List[Any]												=       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 snake_case_    (				lowercase__      ,					lowercase__ = 1_3		):
  UpperCAmelCase__			:				Optional[Any]												=       ""
  for c in s:
    if "A" <= c <= "Z":
      out += chr(ord("A"		) + (ord(lowercase__		) - ord("A"		) + n) % 2_6		)
    elif "a" <= c <= "z":
      out += chr(ord("a"		) + (ord(lowercase__		) - ord("a"		) + n) % 2_6		)
    else:
      out += c
  return out







def snake_case_    (				):
  UpperCAmelCase__			:				Dict												=       input("Enter message: "		)

  UpperCAmelCase__			:				Optional[int]												=       dencrypt(lowercase__      ,					1_3		)
  print("Encryption:"      ,					lowercase__		)

  UpperCAmelCase__			:				Union[str, Any]												=       dencrypt(lowercase__      ,					1_3		)
  print("Decryption: "      ,					lowercase__		)


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      main()



