




"""simple docstring"""

import importlib.metadata
import sys

from transformers.testing_utils import TestCasePlus
from transformers.utils.versions import require_version, require_version_core


__A 		=			importlib.metadata.version("numpy")
__A 		=			".".join([str(x) for x in sys.version_info[:3]])
class 			lowerCamelCase__    (  lowerCamelCase_			):


			def 							lowerCamelCase_				(     self							):



					"""simple docstring"""







					require_version_core("numpy<1000.4.5"							)
					require_version_core("numpy<1000.4"							)
					require_version_core("numpy<1000"							)

					# le
					require_version_core("numpy<=1000.4.5"							)
					require_version_core(F'''numpy<={numpy_ver}'''							)

					# eq
					require_version_core(F'''numpy=={numpy_ver}'''							)

					# ne
					require_version_core("numpy!=1000.4.5"							)

					# ge
					require_version_core("numpy>=1.0"							)
					require_version_core("numpy>=1.0.0"							)
					require_version_core(F'''numpy>={numpy_ver}'''							)

					# gt
					require_version_core("numpy>1.0.0"							)

					# mix
					require_version_core("numpy>1.0.0,<1000"							)

					# requirement w/o version
					require_version_core("numpy"							)

					# unmet requirements due to version conflict
					for req in ["numpy==1.0.0", "numpy>=1000.0.0", F'''numpy<{numpy_ver}''']:
							try:
									require_version_core(SCREAMING_SNAKE_CASE							)
							except ImportError as e:
									self.assertIn(F'''{req} is required'''				, str(SCREAMING_SNAKE_CASE							)							)
									self.assertIn("but found"				, str(SCREAMING_SNAKE_CASE							)							)

        # unmet requirements due to missing module
					for req in ["numpipypie>1", "numpipypie2"]:
							try:
									require_version_core(SCREAMING_SNAKE_CASE							)
							except importlib.metadata.PackageNotFoundError as e:
									self.assertIn(F'''The \'{req}\' distribution was not found and is required by this application'''				, str(SCREAMING_SNAKE_CASE							)							)
									self.assertIn("Try: pip install transformers -U"				, str(SCREAMING_SNAKE_CASE							)							)

        # bogus requirements formats:
        # 1. whole thing
					for req in ["numpy??1.0.0", "numpy1.0.0"]:
							try:
									require_version_core(SCREAMING_SNAKE_CASE							)
							except ValueError as e:
									self.assertIn("requirement needs to be in the pip package format"				, str(SCREAMING_SNAKE_CASE							)							)
        # 2. only operators
					for req in ["numpy=1.0.0", "numpy == 1.00", "numpy<>1.0.0", "numpy><1.00", "numpy>>1.0.0"]:
							try:
									require_version_core(SCREAMING_SNAKE_CASE							)
							except ValueError as e:
									self.assertIn("need one of "				, str(SCREAMING_SNAKE_CASE							)							)



			def 							lowerCamelCase_				(     self							):



					"""simple docstring"""







					require_version("python>=3.6.0"							)

					# not matching requirements
					for req in ["python>9.9.9", "python<3.0.0"]:
							try:
									require_version_core(SCREAMING_SNAKE_CASE							)
							except ImportError as e:
									self.assertIn(F'''{req} is required'''				, str(SCREAMING_SNAKE_CASE							)							)
									self.assertIn(F'''but found python=={python_ver}'''				, str(SCREAMING_SNAKE_CASE							)							)







"""simple docstring"""

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
class 			lowerCamelCase__    (  lowerCamelCase_			):
			a__ :      Tuple								=     ["""image_processor""", """tokenizer"""]
			a__ :      List[Any]								=     """EfficientNetImageProcessor"""
			a__ :      str								=     ("""BertTokenizer""", """BertTokenizerFast""")


			def __init__(     self				, SCREAMING_SNAKE_CASE				, SCREAMING_SNAKE_CASE							):



					"""simple docstring"""







					super().__init__(SCREAMING_SNAKE_CASE				, SCREAMING_SNAKE_CASE							)


			def __call__(     self				, SCREAMING_SNAKE_CASE=None				, SCREAMING_SNAKE_CASE=None				, SCREAMING_SNAKE_CASE="max_length"				, SCREAMING_SNAKE_CASE=64				, SCREAMING_SNAKE_CASE=None				, **SCREAMING_SNAKE_CASE							):



					"""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:
							snake_case		:						Dict								=				self.tokenizer(
							    SCREAMING_SNAKE_CASE				, padding=SCREAMING_SNAKE_CASE				, max_length=SCREAMING_SNAKE_CASE				, return_tensors=SCREAMING_SNAKE_CASE				, **SCREAMING_SNAKE_CASE							)

					if images is not None:
							snake_case		:						Tuple								=				self.image_processor(SCREAMING_SNAKE_CASE				, return_tensors=SCREAMING_SNAKE_CASE				, **SCREAMING_SNAKE_CASE							)

					if text is not None and images is not None:
							snake_case		:						Dict								=				image_features.pixel_values
							return encoding
					elif text is not None:
							return encoding
					else:
							return BatchEncoding(data=dict(**SCREAMING_SNAKE_CASE							)				, tensor_type=SCREAMING_SNAKE_CASE							)


			def 							lowerCamelCase_				(     self				, *SCREAMING_SNAKE_CASE				, **SCREAMING_SNAKE_CASE							):



					"""simple docstring"""







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


			def 							lowerCamelCase_				(     self				, *SCREAMING_SNAKE_CASE				, **SCREAMING_SNAKE_CASE							):



					"""simple docstring"""







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



			@property
			def 							lowerCamelCase_				(     self							):



					"""simple docstring"""







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

