


from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding







class      __lowercase  (_a   ):





							"""simple docstring"""







							_UpperCAmelCase     =		["""image_processor""", """tokenizer"""]
							_UpperCAmelCase     =		"""EfficientNetImageProcessor"""
							_UpperCAmelCase     =		("""BertTokenizer""", """BertTokenizerFast""")






							def __init__(	self       ,		lowerCAmelCase__       ,		lowerCAmelCase__    ):





										"""simple docstring"""




										super().__init__(lowerCAmelCase_       ,		lowerCAmelCase_    )






							def __call__(	self       ,		lowerCAmelCase__=None       ,		lowerCAmelCase__=None       ,		lowerCAmelCase__="max_length"       ,		lowerCAmelCase__=6_4       ,		lowerCAmelCase__=None       ,		**lowerCAmelCase__    ):





										"""simple docstring"""




										if text is None and images is None:
													raise ValueError('You have to specify either text or images. Both cannot be none.'    )

										if text is not None:
													SCREAMING_SNAKE_CASE_						:			List[str]       						= self.tokenizer(
													    lowerCAmelCase_       ,		padding=lowerCAmelCase_       ,		max_length=lowerCAmelCase_       ,		return_tensors=lowerCAmelCase_       ,		**lowerCAmelCase_    )

										if images is not None:
													SCREAMING_SNAKE_CASE_						:			Optional[Any]       						= self.image_processor(lowerCAmelCase_       ,		return_tensors=lowerCAmelCase_       ,		**lowerCAmelCase_    )

										if text is not None and images is not None:
													SCREAMING_SNAKE_CASE_						:			List[Any]       						= image_features.pixel_values
													return encoding
										elif text is not None:
													return encoding
										else:
													return BatchEncoding(data=dict(**lowerCAmelCase_    )       ,		tensor_type=lowerCAmelCase_    )






							def  UpperCamelCase__			(	self       ,		*lowerCAmelCase__       ,		**lowerCAmelCase__    ):





										"""simple docstring"""




										return self.tokenizer.batch_decode(*lowerCAmelCase_       ,		**lowerCAmelCase_    )






							def  UpperCamelCase__			(	self       ,		*lowerCAmelCase__       ,		**lowerCAmelCase__    ):





										"""simple docstring"""




										return self.tokenizer.decode(*lowerCAmelCase_       ,		**lowerCAmelCase_    )






							@property
							def  UpperCamelCase__			(	self    ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_						:			int       						= self.tokenizer.model_input_names
										SCREAMING_SNAKE_CASE_						:			Optional[Any]       						= self.image_processor.model_input_names
										return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names    )    )











'''simple docstring'''


import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
				from PIL import Image

class 			A    (		unittest.TestCase     ,_a    ):







							def    __lowerCAmelCase			(  self       :  Optional[int]					)			->							Optional[int]:


														"""simple docstring"""


														_a	     =				load_tool('''image-question-answering'''					)
														self.tool.setup()
														_a	     =				load_tool('''image-question-answering'''							,			remote=lowerCAmelCase_					)







							def    __lowerCAmelCase			(  self       :  Tuple					)			->							Optional[int]:


														"""simple docstring"""


														_a	     =				Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''					)					) / '''000000039769.png'''					)
														_a	     =				self.tool(lowerCAmelCase_							,			'''How many cats are sleeping on the couch?'''					)
														self.assertEqual(lowerCAmelCase_							,			'''2'''					)







							def    __lowerCAmelCase			(  self       :  List[str]					)			->							Union[str, Any]:


														"""simple docstring"""


														_a	     =				Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''					)					) / '''000000039769.png'''					)
														_a	     =				self.remote_tool(lowerCAmelCase_							,			'''How many cats are sleeping on the couch?'''					)
														self.assertEqual(lowerCAmelCase_							,			'''2'''					)







							def    __lowerCAmelCase			(  self       :  Dict					)			->							Tuple:


														"""simple docstring"""


														_a	     =				Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''					)					) / '''000000039769.png'''					)
														_a	     =				self.tool(image=lowerCAmelCase_							,			question='''How many cats are sleeping on the couch?'''					)
														self.assertEqual(lowerCAmelCase_							,			'''2'''					)







							def    __lowerCAmelCase			(  self       :  Tuple					)			->							Dict:


														"""simple docstring"""


														_a	     =				Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''					)					) / '''000000039769.png'''					)
														_a	     =				self.remote_tool(image=lowerCAmelCase_							,			question='''How many cats are sleeping on the couch?'''					)
														self.assertEqual(lowerCAmelCase_							,			'''2'''					)

