






import unittest

from transformers import MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING, is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
 from PIL import Image
else:





 class       __a  :







  @staticmethod
  def  __lowercase (		*SCREAMING_SNAKE_CASE :       Tuple							,       **SCREAMING_SNAKE_CASE :       Any						):


       '''simple docstring'''






       pass





@is_pipeline_test
@require_torch
@require_vision
class       __a  (   unittest.TestCase	):
 _lowerCAmelCase	:	Optional[Any]				=			MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING







 def  __lowercase (		self :       str							,       SCREAMING_SNAKE_CASE :       List[str]							,       SCREAMING_SNAKE_CASE :       Any							,       SCREAMING_SNAKE_CASE :       Optional[Any]						):


      '''simple docstring'''






      UpperCamelCase__      :       List[Any]	    =  pipeline("visual-question-answering"							,       model="hf-internal-testing/tiny-vilt-random-vqa"						)
      UpperCamelCase__      :       str	    =  [
          {
              "image": Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"						),
              "question": "How many cats are there?",
          },
          {
              "image": "./tests/fixtures/tests_samples/COCO/000000039769.png",
              "question": "How many cats are there?",
          },
      ]
      return vqa_pipeline, examples







 def  __lowercase (		self :       int							,       SCREAMING_SNAKE_CASE :       int							,       SCREAMING_SNAKE_CASE :       Optional[int]						):


      '''simple docstring'''






      UpperCamelCase__      :       Any	    =  vqa_pipeline(SCREAMING_SNAKE_CASE							,       top_k=1						)
      self.assertEqual(
          SCREAMING_SNAKE_CASE							,       [
              [{"score": ANY(SCREAMING_SNAKE_CASE						), "answer": ANY(SCREAMING_SNAKE_CASE						)}],
              [{"score": ANY(SCREAMING_SNAKE_CASE						), "answer": ANY(SCREAMING_SNAKE_CASE						)}],
          ]							,       )







 @require_torch
 def  __lowercase (		self :       Dict						):


      '''simple docstring'''






      UpperCamelCase__      :       Dict	    =  pipeline("visual-question-answering"							,       model="hf-internal-testing/tiny-vilt-random-vqa"						)
      UpperCamelCase__      :       int	    =  "./tests/fixtures/tests_samples/COCO/000000039769.png"
      UpperCamelCase__      :       Optional[int]	    =  "How many cats are there?"

      UpperCamelCase__      :       Union[str, Any]	    =  vqa_pipeline(image=SCREAMING_SNAKE_CASE							,       question="How many cats are there?"							,       top_k=2						)
      self.assertEqual(
          SCREAMING_SNAKE_CASE							,       [{"score": ANY(SCREAMING_SNAKE_CASE						), "answer": ANY(SCREAMING_SNAKE_CASE						)}, {"score": ANY(SCREAMING_SNAKE_CASE						), "answer": ANY(SCREAMING_SNAKE_CASE						)}]						)

      UpperCamelCase__      :       Optional[int]	    =  vqa_pipeline({"image": image, "question": question}							,       top_k=2						)
      self.assertEqual(
          SCREAMING_SNAKE_CASE							,       [{"score": ANY(SCREAMING_SNAKE_CASE						), "answer": ANY(SCREAMING_SNAKE_CASE						)}, {"score": ANY(SCREAMING_SNAKE_CASE						), "answer": ANY(SCREAMING_SNAKE_CASE						)}]						)







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


      '''simple docstring'''






      UpperCamelCase__      :       Tuple	    =  pipeline("visual-question-answering"							,       model="dandelin/vilt-b32-finetuned-vqa"						)
      UpperCamelCase__      :       Union[str, Any]	    =  "./tests/fixtures/tests_samples/COCO/000000039769.png"
      UpperCamelCase__      :       Dict	    =  "How many cats are there?"

      UpperCamelCase__      :       Union[str, Any]	    =  vqa_pipeline(image=SCREAMING_SNAKE_CASE							,       question=SCREAMING_SNAKE_CASE							,       top_k=2						)
      self.assertEqual(
          nested_simplify(SCREAMING_SNAKE_CASE							,       decimals=4						)							,       [{"score": 0.8_7_9_9, "answer": "2"}, {"score": 0.2_9_6, "answer": "1"}]						)

      UpperCamelCase__      :       Optional[Any]	    =  vqa_pipeline({"image": image, "question": question}							,       top_k=2						)
      self.assertEqual(
          nested_simplify(SCREAMING_SNAKE_CASE							,       decimals=4						)							,       [{"score": 0.8_7_9_9, "answer": "2"}, {"score": 0.2_9_6, "answer": "1"}]						)

      UpperCamelCase__      :       Tuple	    =  vqa_pipeline(
          [{"image": image, "question": question}, {"image": image, "question": question}]							,       top_k=2						)
      self.assertEqual(
          nested_simplify(SCREAMING_SNAKE_CASE							,       decimals=4						)							,       [[{"score": 0.8_7_9_9, "answer": "2"}, {"score": 0.2_9_6, "answer": "1"}]] * 2							,       )







 @require_tf
 @unittest.skip("Visual question answering not implemented in TF"						)
 def  __lowercase (		self :       List[Any]						):


      '''simple docstring'''






      pass







from __future__ import annotations







def 		SCREAMING_SNAKE_CASE							( __lowerCAmelCase ,   __lowerCAmelCase      )			->     list[int]:
     UpperCamelCase__      :       Optional[Any]	    =  0
     UpperCamelCase__      :       Any	    =  len(__lowerCAmelCase      ) - 1

     while i < j:
          if nums[i] + nums[j] == target:
               return [i, j]
          elif nums[i] + nums[j] < target:
               UpperCamelCase__      :       Optional[int]	    =  i + 1
          else:
               UpperCamelCase__      :       Dict	    =  j - 1

     return []


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 print(F"""{two_pointer([2, 7, 11, 15], 9) = }""")