'''simple docstring'''






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 lowercase_       :







      """simple docstring"""

      @staticmethod
      def 	__UpperCAmelCase   (      *UpperCamelCase__      :			Optional[Any], **UpperCamelCase__      :			str     )  ->			int:
           pass







@is_pipeline_test
@require_torch
@require_vision
class lowercase_       (		unittest.TestCase			):







   """simple docstring"""

   __lowerCAmelCase         =   MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING
   def 	__UpperCAmelCase   (      self      :			int, UpperCamelCase__      :			Dict, UpperCamelCase__      :			List[Any], UpperCamelCase__      :			Optional[Any]     )  ->			List[str]:
        _A    		=  pipeline('visual-question-answering', model='hf-internal-testing/tiny-vilt-random-vqa'     )
        _A    		=  [
            {
                '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 	__UpperCAmelCase   (      self      :			Union[str, Any], UpperCamelCase__      :			Optional[int], UpperCamelCase__      :			Union[str, Any]     )  ->			Any:
        _A    		=  vqa_pipeline(UpperCamelCase__, top_k=1     )
        self.assertEqual(
            UpperCamelCase__, [
                [{'score': ANY(UpperCamelCase__     ), 'answer': ANY(UpperCamelCase__     )}],
                [{'score': ANY(UpperCamelCase__     ), 'answer': ANY(UpperCamelCase__     )}],
            ], )
   @require_torch
   def 	__UpperCAmelCase   (      self      :			int     )  ->			Dict:
        _A    		=  pipeline('visual-question-answering', model='hf-internal-testing/tiny-vilt-random-vqa'     )
        _A    		=  './tests/fixtures/tests_samples/COCO/000000039769.png'
        _A    		=  'How many cats are there?'

        _A    		=  vqa_pipeline(image=UpperCamelCase__, question='How many cats are there?', top_k=2     )
        self.assertEqual(
            UpperCamelCase__, [{'score': ANY(UpperCamelCase__     ), 'answer': ANY(UpperCamelCase__     )}, {'score': ANY(UpperCamelCase__     ), 'answer': ANY(UpperCamelCase__     )}]     )

        _A    		=  vqa_pipeline({'image': image, 'question': question}, top_k=2     )
        self.assertEqual(
            UpperCamelCase__, [{'score': ANY(UpperCamelCase__     ), 'answer': ANY(UpperCamelCase__     )}, {'score': ANY(UpperCamelCase__     ), 'answer': ANY(UpperCamelCase__     )}]     )
   @slow
   @require_torch
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			Any:
        _A    		=  pipeline('visual-question-answering', model='dandelin/vilt-b32-finetuned-vqa'     )
        _A    		=  './tests/fixtures/tests_samples/COCO/000000039769.png'
        _A    		=  'How many cats are there?'

        _A    		=  vqa_pipeline(image=UpperCamelCase__, question=UpperCamelCase__, top_k=2     )
        self.assertEqual(
            nested_simplify(UpperCamelCase__, decimals=4     ), [{'score': 0.8_799, 'answer': '2'}, {'score': 0.296, 'answer': '1'}]     )

        _A    		=  vqa_pipeline({'image': image, 'question': question}, top_k=2     )
        self.assertEqual(
            nested_simplify(UpperCamelCase__, decimals=4     ), [{'score': 0.8_799, 'answer': '2'}, {'score': 0.296, 'answer': '1'}]     )

        _A    		=  vqa_pipeline(
            [{'image': image, 'question': question}, {'image': image, 'question': question}], top_k=2     )
        self.assertEqual(
            nested_simplify(UpperCamelCase__, decimals=4     ), [[{'score': 0.8_799, 'answer': '2'}, {'score': 0.296, 'answer': '1'}]] * 2, )

   @require_tf
   @unittest.skip('Visual question answering not implemented in TF'     )
   def 	__UpperCAmelCase   (      self      :			Any     )  ->			List[str]:
        pass






"""simple docstring"""




import numpy as np

def 						A							(  snake_case__     ):




			'''simple docstring'''


			return (2 / (1 + np.exp(-2 * vector     ))) - 1


if __name__ == "__main__":
						import doctest

						doctest.testmod()


