





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

					"""simple docstring"""







					@staticmethod
					def   _a      (      *_A						,   **_A    ):






											'''simple docstring'''







											pass






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

			"""simple docstring"""
			__lowerCAmelCase     :				List[str]										=  MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING







			def   _a      (      self						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase				:		List[str]				   =			pipeline("""visual-question-answering"""						,   model="""hf-internal-testing/tiny-vilt-random-vqa"""    )
									UpperCamelCase				:		List[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   _a      (      self						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase				:		str				   =			vqa_pipeline(_A						,   top_k=1    )
									self.assertEqual(
									    _A						,   [
									        [{"""score""": ANY(_A    ), """answer""": ANY(_A    )}],
									        [{"""score""": ANY(_A    ), """answer""": ANY(_A    )}],
									    ]						,   )







			@require_torch
			def   _a      (      self    ):






									'''simple docstring'''







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

									UpperCamelCase				:		Tuple				   =			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    )}]    )

									UpperCamelCase				:		Optional[int]				   =			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   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		List[Any]				   =			pipeline("""visual-question-answering"""						,   model="""dandelin/vilt-b32-finetuned-vqa"""    )
									UpperCamelCase				:		Tuple				   =			"""./tests/fixtures/tests_samples/COCO/000000039769.png"""
									UpperCamelCase				:		str				   =			"""How many cats are there?"""

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

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

									UpperCamelCase				:		int				   =			vqa_pipeline(
									    [{"""image""": image, """question""": question}, {"""image""": image, """question""": question}]						,   top_k=2    )
									self.assertEqual(
									    nested_simplify(_A						,   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   _a      (      self    ):






									'''simple docstring'''







									pass







from . import (
    albert,
    align,
    altclip,
    audio_spectrogram_transformer,
    auto,
    autoformer,
    bark,
    bart,
    barthez,
    bartpho,
    beit,
    bert,
    bert_generation,
    bert_japanese,
    bertweet,
    big_bird,
    bigbird_pegasus,
    biogpt,
    bit,
    blenderbot,
    blenderbot_small,
    blip,
    blip_a,
    bloom,
    bridgetower,
    byta,
    camembert,
    canine,
    chinese_clip,
    clap,
    clip,
    clipseg,
    codegen,
    conditional_detr,
    convbert,
    convnext,
    convnextva,
    cpm,
    cpmant,
    ctrl,
    cvt,
    dataavec,
    deberta,
    deberta_va,
    decision_transformer,
    deformable_detr,
    deit,
    deprecated,
    deta,
    detr,
    dialogpt,
    dinat,
    distilbert,
    dit,
    donut,
    dpr,
    dpt,
    efficientformer,
    efficientnet,
    electra,
    encodec,
    encoder_decoder,
    ernie,
    ernie_m,
    esm,
    falcon,
    flaubert,
    flava,
    fnet,
    focalnet,
    fsmt,
    funnel,
    git,
    glpn,
    gpta,
    gpt_bigcode,
    gpt_neo,
    gpt_neox,
    gpt_neox_japanese,
    gpt_swa,
    gptj,
    gptsan_japanese,
    graphormer,
    groupvit,
    herbert,
    hubert,
    ibert,
    imagegpt,
    informer,
    instructblip,
    jukebox,
    layoutlm,
    layoutlmva,
    layoutlmva,
    layoutxlm,
    led,
    levit,
    lilt,
    llama,
    longformer,
    longta,
    luke,
    lxmert,
    mam_aaa,
    marian,
    markuplm,
    maskaformer,
    maskformer,
    mbart,
    mbartaa,
    mega,
    megatron_bert,
    megatron_gpta,
    mgp_str,
    mluke,
    mobilebert,
    mobilenet_va,
    mobilenet_va,
    mobilevit,
    mobilevitva,
    mpnet,
    mra,
    mta,
    musicgen,
    mvp,
    nat,
    nezha,
    nllb,
    nllb_moe,
    nystromformer,
    oneformer,
    open_llama,
    openai,
    opt,
    owlvit,
    pegasus,
    pegasus_x,
    perceiver,
    phobert,
    pixastruct,
    plbart,
    poolformer,
    prophetnet,
    qdqbert,
    rag,
    realm,
    reformer,
    regnet,
    rembert,
    resnet,
    roberta,
    roberta_prelayernorm,
    roc_bert,
    roformer,
    rwkv,
    sam,
    segformer,
    sew,
    sew_d,
    speech_encoder_decoder,
    speech_to_text,
    speech_to_text_a,
    speechta,
    splinter,
    squeezebert,
    swiftformer,
    swin,
    swinasr,
    swinva,
    switch_transformers,
    ta,
    table_transformer,
    tapas,
    time_series_transformer,
    timesformer,
    timm_backbone,
    transfo_xl,
    trocr,
    tvlt,
    umta,
    unispeech,
    unispeech_sat,
    upernet,
    videomae,
    vilt,
    vision_encoder_decoder,
    vision_text_dual_encoder,
    visual_bert,
    vit,
    vit_hybrid,
    vit_mae,
    vit_msn,
    vivit,
    wavaveca,
    wavaveca_conformer,
    wavaveca_phoneme,
    wavaveca_with_lm,
    wavlm,
    whisper,
    x_clip,
    xglm,
    xlm,
    xlm_prophetnet,
    xlm_roberta,
    xlm_roberta_xl,
    xlnet,
    xmod,
    yolos,
    yoso,
)





