





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	:







          @staticmethod
          def        _lowercase  (   *lowerCAmelCase__		,				**lowerCAmelCase__							)       ->						Union[str, Any]:



            '''simple docstring'''




            pass







@is_pipeline_test
@require_torch
@require_vision
class     __lowerCAmelCase	(   unittest.TestCase):
      _lowercase    : Optional[int]            =      MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING







      def        _lowercase  (   self		,				lowerCAmelCase__		,				lowerCAmelCase__		,				lowerCAmelCase__							)       ->						Optional[Any]:



        '''simple docstring'''




        a__     : Tuple  =pipeline("visual-question-answering"		,				model="hf-internal-testing/tiny-vilt-random-vqa"							)
        a__     : Any  =[
            {
                "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		,				lowerCAmelCase__		,				lowerCAmelCase__							)       ->						str:



        '''simple docstring'''




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







      @require_torch
      def        _lowercase  (   self							)       ->						Optional[int]:



        '''simple docstring'''




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

        a__     : Any  =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__     : Tuple  =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        _lowercase  (   self							)       ->						List[str]:



        '''simple docstring'''




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

        a__     : int  =vqa_pipeline(image=_UpperCAmelCase		,				question=_UpperCAmelCase		,				top_k=2							)
        self.assertEqual(
            nested_simplify(_UpperCAmelCase		,				decimals=4							)		,				[{"score": 0.87_99, "answer": "2"}, {"score": 0.2_96, "answer": "1"}]							)

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

        a__     : Tuple  =vqa_pipeline(
            [{"image": image, "question": question}, {"image": image, "question": question}]		,				top_k=2							)
        self.assertEqual(
            nested_simplify(_UpperCAmelCase		,				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        _lowercase  (   self							)       ->						Dict:



        '''simple docstring'''




        pass













UpperCAmelCase     :     Dict							=	[0, 2, 4, 6, 8]
UpperCAmelCase     :     Tuple							=	[1, 3, 5, 7, 9]
def 					_A	(		SCREAMING_SNAKE_CASE					:       int	,	SCREAMING_SNAKE_CASE					:       int	,	SCREAMING_SNAKE_CASE					:       list[int]	,	SCREAMING_SNAKE_CASE					:       int						):





  """simple docstring"""



  if remaining_length == 0:
    if digits[0] == 0 or digits[-1] == 0:
      return 0

    for i in range(length // 2 - 1	,	-1	,	-1						):
      remainder += digits[i] + digits[length - i - 1]

      if remainder % 2 == 0:
        return 0

      remainder //= 10

    return 1

  if remaining_length == 1:
    if remainder % 2 == 0:
      return 0

    a__     : str  =0
    for digit in range(10						):
      a__     : int  =digit
      result += reversible_numbers(
          0	,	(remainder + 2 * digit) // 10	,	SCREAMING_SNAKE_CASE	,	SCREAMING_SNAKE_CASE						)
    return result

  a__     : List[str]  =0
  for digita in range(10						):
    a__     : Optional[int]  =digita

    if (remainder + digita) % 2 == 0:
      a__     : Dict  =ODD_DIGITS
    else:
      a__     : Any  =EVEN_DIGITS

    for digita in other_parity_digits:
      a__     : Union[str, Any]  =digita
      result += reversible_numbers(
          remaining_length - 2	,	(remainder + digita + digita) // 10	,	SCREAMING_SNAKE_CASE	,	SCREAMING_SNAKE_CASE	,	)
  return result
def 					_A	(		SCREAMING_SNAKE_CASE					:       int = 9						):





  """simple docstring"""



  a__     : List[str]  =0
  for length in range(1	,	max_power + 1						):
    result += reversible_numbers(SCREAMING_SNAKE_CASE	,	0	,	[0] * length	,	SCREAMING_SNAKE_CASE						)
  return result


if __name__ == "__main__":
     print(F"""{solution() = }""")






