






'''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 		A      (  *_A  :		Dict				, **_A  :		Optional[int]      )    ->							Union[str, Any]:
														pass


@is_pipeline_test
@require_torch
@require_vision
class  snake_case__      (					unittest.TestCase):
					a_        =					MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING




					def 		A      (  self  :		List[Any]				, _A  :		Optional[int]				, _A  :		List[str]				, _A  :		Union[str, Any]      )    ->							List[Any]:
								UpperCAmelCase_      :       Any          =       pipeline('''visual-question-answering'''				, model='''hf-internal-testing/tiny-vilt-random-vqa'''      )
								UpperCAmelCase_      :       Dict          =       [
								    {
								        '''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  :		Optional[int]				, _A  :		Union[str, Any]				, _A  :		List[Any]      )    ->							Any:
								UpperCAmelCase_      :       List[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  :		List[str]      )    ->							Dict:
								UpperCAmelCase_      :       List[str]          =       pipeline('''visual-question-answering'''				, model='''hf-internal-testing/tiny-vilt-random-vqa'''      )
								UpperCAmelCase_      :       Optional[int]          =       '''./tests/fixtures/tests_samples/COCO/000000039769.png'''
								UpperCAmelCase_      :       List[Any]          =       '''How many cats are there?'''

								UpperCAmelCase_      :       Dict          =       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_      :       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  :		Optional[int]      )    ->							int:
								UpperCAmelCase_      :       str          =       pipeline('''visual-question-answering'''				, model='''dandelin/vilt-b32-finetuned-vqa'''      )
								UpperCAmelCase_      :       Union[str, Any]          =       '''./tests/fixtures/tests_samples/COCO/000000039769.png'''
								UpperCAmelCase_      :       Union[str, Any]          =       '''How many cats are there?'''

								UpperCAmelCase_      :       Any          =       vqa_pipeline(image=_A				, question=_A				, top_k=2      )
								self.assertEqual(
								    nested_simplify(_A				, decimals=4      )				, [{'''score''': 0.8_799, '''answer''': '''2'''}, {'''score''': 0.296, '''answer''': '''1'''}]      )

								UpperCAmelCase_      :       Dict          =       vqa_pipeline({'''image''': image, '''question''': question}				, top_k=2      )
								self.assertEqual(
								    nested_simplify(_A				, decimals=4      )				, [{'''score''': 0.8_799, '''answer''': '''2'''}, {'''score''': 0.296, '''answer''': '''1'''}]      )

								UpperCAmelCase_      :       Any          =       vqa_pipeline(
								    [{'''image''': image, '''question''': question}, {'''image''': image, '''question''': question}]				, top_k=2      )
								self.assertEqual(
								    nested_simplify(_A				, decimals=4      )				, [[{'''score''': 0.8_799, '''answer''': '''2'''}, {'''score''': 0.296, '''answer''': '''1'''}]] * 2				, )





					@require_tf
					@unittest.skip('''Visual question answering not implemented in TF'''      )
					def 		A      (  self  :		str      )    ->							List[Any]:
								pass










'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_speech_available, is_torch_available


_UpperCamelCase						:						Tuple  =					{
    'configuration_audio_spectrogram_transformer': [
        'AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'ASTConfig',
    ]
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						_UpperCamelCase						:						Optional[int]  =					[
						    'AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
						    'ASTForAudioClassification',
						    'ASTModel',
						    'ASTPreTrainedModel',
						]

try:
						if not is_speech_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						_UpperCamelCase						:						int  =					['ASTFeatureExtractor']

if TYPE_CHECKING:
						from .configuration_audio_spectrogram_transformer import (
						    AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
						    ASTConfig,
						)

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_audio_spectrogram_transformer import (
												    AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
												    ASTForAudioClassification,
												    ASTModel,
												    ASTPreTrainedModel,
												)

						try:
												if not is_speech_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .feature_extraction_audio_spectrogram_transformer import ASTFeatureExtractor


else:
						import sys

						_UpperCamelCase						:						List[str]  =					_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)


