


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







     @staticmethod
     def 				lowerCamelCase	(			*UpperCamelCase__		,			**UpperCamelCase__		)			->	str:

         '''simple docstring'''




         pass







@is_pipeline_test
@require_torch
@require_vision
class _lowerCAmelCase       (   unittest.TestCase			):
   __UpperCAmelCase				: str													=						MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING







   def 				lowerCamelCase	(			self		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		)			->	List[Any]:

       '''simple docstring'''




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

       '''simple docstring'''




       snake_case					:   Dict         =					vqa_pipeline(UpperCamelCase__		,			top_k=1		)
       self.assertEqual(
           UpperCamelCase__		,			[
               [{"score": ANY(UpperCamelCase__		), "answer": ANY(UpperCamelCase__		)}],
               [{"score": ANY(UpperCamelCase__		), "answer": ANY(UpperCamelCase__		)}],
           ]		,			)







   @require_torch
   def 				lowerCamelCase	(			self		)			->	List[Any]:

       '''simple docstring'''




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

       snake_case					:   List[str]         =					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__		)}]		)

       snake_case					:   Union[str, Any]         =					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 				lowerCamelCase	(			self		)			->	int:

       '''simple docstring'''




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

       snake_case					:   Dict         =					vqa_pipeline(image=UpperCamelCase__		,			question=UpperCamelCase__		,			top_k=2		)
       self.assertEqual(
           nested_simplify(UpperCamelCase__		,			decimals=4		)		,			[{"score": 0.8799, "answer": "2"}, {"score": 0.296, "answer": "1"}]		)

       snake_case					:   Union[str, Any]         =					vqa_pipeline({"image": image, "question": question}		,			top_k=2		)
       self.assertEqual(
           nested_simplify(UpperCamelCase__		,			decimals=4		)		,			[{"score": 0.8799, "answer": "2"}, {"score": 0.296, "answer": "1"}]		)

       snake_case					:   Union[str, Any]         =					vqa_pipeline(
           [{"image": image, "question": question}, {"image": image, "question": question}]		,			top_k=2		)
       self.assertEqual(
           nested_simplify(UpperCamelCase__		,			decimals=4		)		,			[[{"score": 0.8799, "answer": "2"}, {"score": 0.296, "answer": "1"}]] * 2		,			)







   @require_tf
   @unittest.skip("Visual question answering not implemented in TF"		)
   def 				lowerCamelCase	(			self		)			->	Optional[Any]:

       '''simple docstring'''




       pass









"""simple docstring"""



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__snake_case         =					{
    """configuration_distilbert""": [
        """DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """DistilBertConfig""",
        """DistilBertOnnxConfig""",
    ],
    """tokenization_distilbert""": ["""DistilBertTokenizer"""],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __snake_case         =					["""DistilBertTokenizerFast"""]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __snake_case         =					[
      """DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """DistilBertForMaskedLM""",
      """DistilBertForMultipleChoice""",
      """DistilBertForQuestionAnswering""",
      """DistilBertForSequenceClassification""",
      """DistilBertForTokenClassification""",
      """DistilBertModel""",
      """DistilBertPreTrainedModel""",
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __snake_case         =					[
      """TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """TFDistilBertForMaskedLM""",
      """TFDistilBertForMultipleChoice""",
      """TFDistilBertForQuestionAnswering""",
      """TFDistilBertForSequenceClassification""",
      """TFDistilBertForTokenClassification""",
      """TFDistilBertMainLayer""",
      """TFDistilBertModel""",
      """TFDistilBertPreTrainedModel""",
  ]

try:
  if not is_flax_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __snake_case         =					[
      """FlaxDistilBertForMaskedLM""",
      """FlaxDistilBertForMultipleChoice""",
      """FlaxDistilBertForQuestionAnswering""",
      """FlaxDistilBertForSequenceClassification""",
      """FlaxDistilBertForTokenClassification""",
      """FlaxDistilBertModel""",
      """FlaxDistilBertPreTrainedModel""",
  ]


if TYPE_CHECKING:
  from .configuration_distilbert import (
      DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
      DistilBertConfig,
      DistilBertOnnxConfig,
  )
  from .tokenization_distilbert import DistilBertTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_distilbert_fast import DistilBertTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_distilbert import (
        DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        DistilBertForMaskedLM,
        DistilBertForMultipleChoice,
        DistilBertForQuestionAnswering,
        DistilBertForSequenceClassification,
        DistilBertForTokenClassification,
        DistilBertModel,
        DistilBertPreTrainedModel,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_distilbert import (
        TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFDistilBertForMaskedLM,
        TFDistilBertForMultipleChoice,
        TFDistilBertForQuestionAnswering,
        TFDistilBertForSequenceClassification,
        TFDistilBertForTokenClassification,
        TFDistilBertMainLayer,
        TFDistilBertModel,
        TFDistilBertPreTrainedModel,
    )

  try:
    if not is_flax_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_flax_distilbert import (
        FlaxDistilBertForMaskedLM,
        FlaxDistilBertForMultipleChoice,
        FlaxDistilBertForQuestionAnswering,
        FlaxDistilBertForSequenceClassification,
        FlaxDistilBertForTokenClassification,
        FlaxDistilBertModel,
        FlaxDistilBertPreTrainedModel,
    )

else:
  import sys

  __snake_case         =					_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)





