



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



    """simple docstring"""

    @staticmethod
    def     snake_case_      (    *__lowerCAmelCase					:					List[str]			,						**__lowerCAmelCase					:					Tuple      )   ->	List[Any]:
       pass


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



 """simple docstring"""

 a__					: Tuple =  MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING

 def     snake_case_      (    self					:					Tuple			,						__lowerCAmelCase					:					Union[str, Any]			,						__lowerCAmelCase					:					List[str]			,						__lowerCAmelCase					:					List[str]      )   ->	int:
    _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     snake_case_      (    self					:					Union[str, Any]			,						__lowerCAmelCase					:					List[Any]			,						__lowerCAmelCase					:					Tuple      )   ->	Tuple:
    _A      =       vqa_pipeline(__lowerCAmelCase			,						top_k=1      )
    self.assertEqual(
        __lowerCAmelCase			,						[
            [{'''score''': ANY(__lowerCAmelCase      ), '''answer''': ANY(__lowerCAmelCase      )}],
            [{'''score''': ANY(__lowerCAmelCase      ), '''answer''': ANY(__lowerCAmelCase      )}],
        ]			,						)

 @require_torch
 def     snake_case_      (    self					:					Dict      )   ->	Any:
    _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=__lowerCAmelCase			,						question='''How many cats are there?'''			,						top_k=2      )
    self.assertEqual(
        __lowerCAmelCase			,						[{'''score''': ANY(__lowerCAmelCase      ), '''answer''': ANY(__lowerCAmelCase      )}, {'''score''': ANY(__lowerCAmelCase      ), '''answer''': ANY(__lowerCAmelCase      )}]      )

    _A      =       vqa_pipeline({'''image''': image, '''question''': question}			,						top_k=2      )
    self.assertEqual(
        __lowerCAmelCase			,						[{'''score''': ANY(__lowerCAmelCase      ), '''answer''': ANY(__lowerCAmelCase      )}, {'''score''': ANY(__lowerCAmelCase      ), '''answer''': ANY(__lowerCAmelCase      )}]      )

 @slow
 @require_torch
 def     snake_case_      (    self					:					Dict      )   ->	List[str]:
    _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=__lowerCAmelCase			,						question=__lowerCAmelCase			,						top_k=2      )
    self.assertEqual(
        nested_simplify(__lowerCAmelCase			,						decimals=4      )			,						[{'''score''': 0.8799, '''answer''': '''2'''}, {'''score''': 0.296, '''answer''': '''1'''}]      )

    _A      =       vqa_pipeline({'''image''': image, '''question''': question}			,						top_k=2      )
    self.assertEqual(
        nested_simplify(__lowerCAmelCase			,						decimals=4      )			,						[{'''score''': 0.8799, '''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(__lowerCAmelCase			,						decimals=4      )			,						[[{'''score''': 0.8799, '''answer''': '''2'''}, {'''score''': 0.296, '''answer''': '''1'''}]] * 2			,						)

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








def 	SCREAMING_SNAKE_CASE_							(	_snake_case	:int				)  ->     int:
   if not isinstance(_snake_case	,   _snake_case				):
      raise ValueError('''Input must be an integer'''				)
   if input_num <= 0:
      raise ValueError('''Input must be positive'''				)
   return sum(
       divisor for divisor in range(1	,   input_num // 2 + 1				) if input_num % divisor == 0				)


if __name__ == "__main__":
   import doctest

   doctest.testmod()



