




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





										@staticmethod
										def       __UpperCamelCase     (							*a__      :	Optional[int]     ,**a__      :	Any)						->       Dict:




															"""simple docstring"""







															pass




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





						def       __UpperCamelCase     (							self      :	List[str]     ,a__      :	int     ,a__      :	Any     ,a__      :	Any)						->       Tuple:




											"""simple docstring"""







											_lowerCAmelCase:List[Any]									=  pipeline('''visual-question-answering'''     ,model='''hf-internal-testing/tiny-vilt-random-vqa''')
											_lowerCAmelCase:Union[str, 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       __UpperCamelCase     (							self      :	int     ,a__      :	Dict     ,a__      :	Optional[Any])						->       int:




											"""simple docstring"""







											_lowerCAmelCase: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       __UpperCamelCase     (							self      :	Dict)						->       List[str]:




											"""simple docstring"""







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

											_lowerCAmelCase:str									=  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:List[str]									=  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       __UpperCamelCase     (							self      :	Union[str, Any])						->       Optional[int]:




											"""simple docstring"""







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

											_lowerCAmelCase:Tuple									=  vqa_pipeline(image=a__     ,question=a__     ,top_k=2)
											self.assertEqual(
											    nested_simplify(a__     ,decimals=4)     ,[{'''score''': 0.8799, '''answer''': '''2'''}, {'''score''': 0.296, '''answer''': '''1'''}])

											_lowerCAmelCase:Any									=  vqa_pipeline({'''image''': image, '''question''': question}     ,top_k=2)
											self.assertEqual(
											    nested_simplify(a__     ,decimals=4)     ,[{'''score''': 0.8799, '''answer''': '''2'''}, {'''score''': 0.296, '''answer''': '''1'''}])

											_lowerCAmelCase:List[str]									=  vqa_pipeline(
											    [{'''image''': image, '''question''': question}, {'''image''': image, '''question''': question}]     ,top_k=2)
											self.assertEqual(
											    nested_simplify(a__     ,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       __UpperCamelCase     (							self      :	List[str])						->       int:




											"""simple docstring"""







											pass












"""simple docstring"""






import warnings

from ...utils import logging
from .image_processing_poolformer import PoolFormerImageProcessor


UpperCamelCase__						=			logging.get_logger(__name__)




class   a__			(       UpperCamelCase_  ):





						def __init__(							self      :	Dict     ,*a__      :	List[str]     ,**a__      :	str)						->       None:




											"""simple docstring"""







											warnings.warn(
											    '''The class PoolFormerFeatureExtractor is deprecated and will be removed in version 5 of Transformers.'''
											    ''' Please use PoolFormerImageProcessor instead.'''     ,a__     ,)
											super().__init__(*a__     ,**a__)






