


"""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   _UpperCamelCase  :
								'''simple docstring'''







								@staticmethod
								def 			snake_case				(     *__a    ,   **__a	):
											pass
@is_pipeline_test
@require_torch
@require_vision
class   _UpperCamelCase  (   unittest.TestCase		):
							'''simple docstring'''







							__UpperCAmelCase						:    Union[str, Any]				      =MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			pipeline("visual-question-answering"    ,   model="hf-internal-testing/tiny-vilt-random-vqa"	)
										__lowerCAmelCase				    =			[
										    {
										        "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    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			vqa_pipeline(__a    ,   top_k=1	)
										self.assertEqual(
										    __a    ,   [
										        [{"score": ANY(__a	), "answer": ANY(__a	)}],
										        [{"score": ANY(__a	), "answer": ANY(__a	)}],
										    ]    ,   )

							@require_torch
							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			pipeline("visual-question-answering"    ,   model="hf-internal-testing/tiny-vilt-random-vqa"	)
										__lowerCAmelCase				    =			"./tests/fixtures/tests_samples/COCO/000000039769.png"
										__lowerCAmelCase				    =			"How many cats are there?"

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

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

							@slow
							@require_torch
							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			pipeline("visual-question-answering"    ,   model="dandelin/vilt-b32-finetuned-vqa"	)
										__lowerCAmelCase				    =			"./tests/fixtures/tests_samples/COCO/000000039769.png"
										__lowerCAmelCase				    =			"How many cats are there?"

										__lowerCAmelCase				    =			vqa_pipeline(image=__a    ,   question=__a    ,   top_k=2	)
										self.assertEqual(
										    nested_simplify(__a    ,   decimals=4	)    ,   [{"score": 0.8_7_9_9, "answer": "2"}, {"score": 0.2_9_6, "answer": "1"}]	)

										__lowerCAmelCase				    =			vqa_pipeline({"image": image, "question": question}    ,   top_k=2	)
										self.assertEqual(
										    nested_simplify(__a    ,   decimals=4	)    ,   [{"score": 0.8_7_9_9, "answer": "2"}, {"score": 0.2_9_6, "answer": "1"}]	)

										__lowerCAmelCase				    =			vqa_pipeline(
										    [{"image": image, "question": question}, {"image": image, "question": question}]    ,   top_k=2	)
										self.assertEqual(
										    nested_simplify(__a    ,   decimals=4	)    ,   [[{"score": 0.8_7_9_9, "answer": "2"}, {"score": 0.2_9_6, "answer": "1"}]] * 2    ,   )



							@require_tf
							@unittest.skip("Visual question answering not implemented in TF"	)
							def 			snake_case				(     self	):
										pass








"""simple docstring"""


A     :   int			    =			{
    "Pillow": "Pillow",
    "accelerate": "accelerate>=0.11.0",
    "compel": "compel==0.1.8",
    "black": "black~=23.1",
    "datasets": "datasets",
    "filelock": "filelock",
    "flax": "flax>=0.4.1",
    "hf-doc-builder": "hf-doc-builder>=0.3.0",
    "huggingface-hub": "huggingface-hub>=0.13.2",
    "requests-mock": "requests-mock==1.10.0",
    "importlib_metadata": "importlib_metadata",
    "invisible-watermark": "invisible-watermark",
    "isort": "isort>=5.5.4",
    "jax": "jax>=0.2.8,!=0.3.2",
    "jaxlib": "jaxlib>=0.1.65",
    "Jinja2": "Jinja2",
    "k-diffusion": "k-diffusion>=0.0.12",
    "torchsde": "torchsde",
    "note_seq": "note_seq",
    "librosa": "librosa",
    "numpy": "numpy",
    "omegaconf": "omegaconf",
    "parameterized": "parameterized",
    "protobuf": "protobuf>=3.20.3,<4",
    "pytest": "pytest",
    "pytest-timeout": "pytest-timeout",
    "pytest-xdist": "pytest-xdist",
    "ruff": "ruff>=0.0.241",
    "safetensors": "safetensors",
    "sentencepiece": "sentencepiece>=0.1.91,!=0.1.92",
    "scipy": "scipy",
    "onnx": "onnx",
    "regex": "regex!=2019.12.17",
    "requests": "requests",
    "tensorboard": "tensorboard",
    "torch": "torch>=1.4",
    "torchvision": "torchvision",
    "transformers": "transformers>=4.25.1",
    "urllib3": "urllib3<=2.0.0",
}




