

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						:







         """simple docstring"""





         @staticmethod
         def 						snake_case__     (      *lowercase_ :       Tuple,**lowercase_ :       List[str]		)->    Optional[Any]:





             '''simple docstring'''







             pass


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







    """simple docstring"""





    lowerCamelCase			=							MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING


    def 						snake_case__     (      self :       Dict,lowercase_ :       Union[str, Any],lowercase_ :       Optional[Any],lowercase_ :       Tuple		)->    int:





        '''simple docstring'''







        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 :       Optional[Any],lowercase_ :       List[str],lowercase_ :       Dict		)->    Tuple:





        '''simple docstring'''







        A__          =   vqa_pipeline(lowercase_,top_k=1		)
        self.assertEqual(
            lowercase_,[
                [{'score': ANY(lowercase_		), 'answer': ANY(lowercase_		)}],
                [{'score': ANY(lowercase_		), 'answer': ANY(lowercase_		)}],
            ],)


    @require_torch
    def 						snake_case__     (      self :       List[str]		)->    Optional[int]:





        '''simple docstring'''







        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=lowercase_,question='How many cats are there?',top_k=2		)
        self.assertEqual(
            lowercase_,[{'score': ANY(lowercase_		), 'answer': ANY(lowercase_		)}, {'score': ANY(lowercase_		), 'answer': ANY(lowercase_		)}]		)

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


    @slow
    @require_torch
    def 						snake_case__     (      self :       Dict		)->    Optional[int]:





        '''simple docstring'''







        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=lowercase_,question=lowercase_,top_k=2		)
        self.assertEqual(
            nested_simplify(lowercase_,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(lowercase_,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(lowercase_,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 						snake_case__     (      self :       str		)->    Optional[Any]:





        '''simple docstring'''







        pass





"""simple docstring"""


def _lowerCamelCase	(		):

			'''simple docstring'''




			__lowerCAmelCase				    =			[]
			__lowerCAmelCase				    =			1

			while len(_UpperCamelCase      ) < 1e6:
						constant.append(str(_UpperCamelCase      )      )
						i += 1

			__lowerCAmelCase				    =			"".join(_UpperCamelCase      )

			return (
			    int(constant[0]      )
			    * int(constant[9]      )
			    * int(constant[99]      )
			    * int(constant[999]      )
			    * int(constant[9999]      )
			    * int(constant[9_9999]      )
			    * int(constant[99_9999]      )
			)


if __name__ == "__main__":
	print(solution())




