



"""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 	__snake_case	:




     @staticmethod
     def 						SCREAMING_SNAKE_CASE    (			*__lowerCAmelCase					:						Optional[Any]						, **__lowerCAmelCase					:						Dict		):






            """simple docstring"""






            pass






@is_pipeline_test
@require_torch
@require_vision
class 	__snake_case	(     unittest.TestCase):
  snake_case__    :       List[str]        =						MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING




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






         """simple docstring"""






         _lowerCamelCase						:    Tuple         =			pipeline('''visual-question-answering'''						, model='''hf-internal-testing/tiny-vilt-random-vqa'''		)
         _lowerCamelCase						:    List[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 						SCREAMING_SNAKE_CASE    (			self					:						Optional[int]						, __lowerCAmelCase					:						Optional[int]						, __lowerCAmelCase					:						Optional[int]		):






         """simple docstring"""






         _lowerCamelCase						:    Optional[Any]         =			vqa_pipeline(__lowerCAmelCase						, top_k=1		)
         self.assertEqual(
             __lowerCAmelCase						, [
                 [{'''score''': ANY(__lowerCAmelCase		), '''answer''': ANY(__lowerCAmelCase		)}],
                 [{'''score''': ANY(__lowerCAmelCase		), '''answer''': ANY(__lowerCAmelCase		)}],
             ]						, )




  @require_torch
  def 						SCREAMING_SNAKE_CASE    (			self					:						Any		):






         """simple docstring"""






         _lowerCamelCase						:    Any         =			pipeline('''visual-question-answering'''						, model='''hf-internal-testing/tiny-vilt-random-vqa'''		)
         _lowerCamelCase						:    List[str]         =			'''./tests/fixtures/tests_samples/COCO/000000039769.png'''
         _lowerCamelCase						:    str         =			'''How many cats are there?'''

         _lowerCamelCase						:    List[Any]         =			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		)}]		)

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






         """simple docstring"""






         _lowerCamelCase						:    Optional[int]         =			pipeline('''visual-question-answering'''						, model='''dandelin/vilt-b32-finetuned-vqa'''		)
         _lowerCamelCase						:    Dict         =			'''./tests/fixtures/tests_samples/COCO/000000039769.png'''
         _lowerCamelCase						:    List[Any]         =			'''How many cats are there?'''

         _lowerCamelCase						:    Tuple         =			vqa_pipeline(image=__lowerCAmelCase						, question=__lowerCAmelCase						, top_k=2		)
         self.assertEqual(
             nested_simplify(__lowerCAmelCase						, decimals=4		)						, [{'''score''': 0.87_99, '''answer''': '''2'''}, {'''score''': 0.2_96, '''answer''': '''1'''}]		)

         _lowerCamelCase						:    Optional[Any]         =			vqa_pipeline({'''image''': image, '''question''': question}						, top_k=2		)
         self.assertEqual(
             nested_simplify(__lowerCAmelCase						, decimals=4		)						, [{'''score''': 0.87_99, '''answer''': '''2'''}, {'''score''': 0.2_96, '''answer''': '''1'''}]		)

         _lowerCamelCase						:    str         =			vqa_pipeline(
             [{'''image''': image, '''question''': question}, {'''image''': image, '''question''': question}]						, top_k=2		)
         self.assertEqual(
             nested_simplify(__lowerCAmelCase						, decimals=4		)						, [[{'''score''': 0.87_99, '''answer''': '''2'''}, {'''score''': 0.2_96, '''answer''': '''1'''}]] * 2						, )




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






         """simple docstring"""






         pass







"""simple docstring"""






from maths.prime_factors import prime_factors






def 	snake_case_  (				A_ :		int						):


       '''simple docstring'''





       if not isinstance(A_,    A_						):
              _lowerCamelCase						:    str         =			F'''Input value of [number={number}] must be an integer'''
              raise TypeError(A_						)
       if number < 1:
              raise ValueError('''Input must be a positive integer'''						)
       return -1 if len(prime_factors(A_						)						) % 2 else 1


if __name__ == "__main__":
   import doctest

   doctest.testmod()


