




import warnings
from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType



class       a_       (     SCREAMING_SNAKE_CASE__     ):
	A    							= ['''image_processor''', '''tokenizer''']
	A    							= '''FlavaImageProcessor'''
	A    							= ('''BertTokenizer''', '''BertTokenizerFast''')





	def __init__(							self      ,     SCREAMING_SNAKE_CASE=None      ,     SCREAMING_SNAKE_CASE=None      ,     **SCREAMING_SNAKE_CASE      )  ->					List[Any]:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						None
				if "feature_extractor" in kwargs:
							warnings.warn(
							    'The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'
							    ' instead.'      ,     SCREAMING_SNAKE_CASE      ,     )
							SCREAMING_SNAKE_CASE_								=						kwargs.pop('feature_extractor'      )

				SCREAMING_SNAKE_CASE_								=						image_processor if image_processor is not None else feature_extractor
				if image_processor is None:
							raise ValueError('You need to specify an `image_processor`.'      )
				if tokenizer is None:
							raise ValueError('You need to specify a `tokenizer`.'      )

				super().__init__(SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE      )
				SCREAMING_SNAKE_CASE_								=						self.image_processor





	def __call__(							self      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = True      ,     SCREAMING_SNAKE_CASE = False      ,     SCREAMING_SNAKE_CASE = False      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = 0      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = False      ,     SCREAMING_SNAKE_CASE = False      ,     SCREAMING_SNAKE_CASE = False      ,     SCREAMING_SNAKE_CASE = False      ,     SCREAMING_SNAKE_CASE = True      ,     SCREAMING_SNAKE_CASE = None      ,     **SCREAMING_SNAKE_CASE      ,     )  ->					str:




				"""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_								=						self.tokenizer(
							    text=SCREAMING_SNAKE_CASE      ,     add_special_tokens=SCREAMING_SNAKE_CASE      ,     padding=SCREAMING_SNAKE_CASE      ,     truncation=SCREAMING_SNAKE_CASE      ,     max_length=SCREAMING_SNAKE_CASE      ,     stride=SCREAMING_SNAKE_CASE      ,     pad_to_multiple_of=SCREAMING_SNAKE_CASE      ,     return_token_type_ids=SCREAMING_SNAKE_CASE      ,     return_attention_mask=SCREAMING_SNAKE_CASE      ,     return_overflowing_tokens=SCREAMING_SNAKE_CASE      ,     return_special_tokens_mask=SCREAMING_SNAKE_CASE      ,     return_offsets_mapping=SCREAMING_SNAKE_CASE      ,     return_length=SCREAMING_SNAKE_CASE      ,     verbose=SCREAMING_SNAKE_CASE      ,     return_tensors=SCREAMING_SNAKE_CASE      ,     **SCREAMING_SNAKE_CASE      ,     )
				if images is not None:
							SCREAMING_SNAKE_CASE_								=						self.image_processor(
							    SCREAMING_SNAKE_CASE      ,     return_image_mask=SCREAMING_SNAKE_CASE      ,     return_codebook_pixels=SCREAMING_SNAKE_CASE      ,     return_tensors=SCREAMING_SNAKE_CASE      ,     **SCREAMING_SNAKE_CASE      ,     )

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





	def 						A_(							self      ,     *SCREAMING_SNAKE_CASE      ,     **SCREAMING_SNAKE_CASE      )  ->					Union[str, Any]:




				"""simple docstring"""



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





	def 						A_(							self      ,     *SCREAMING_SNAKE_CASE      ,     **SCREAMING_SNAKE_CASE      )  ->					Tuple:




				"""simple docstring"""



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





	@property
	def 						A_(							self      )  ->					Dict:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						self.tokenizer.model_input_names
				SCREAMING_SNAKE_CASE_								=						self.image_processor.model_input_names
				return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names      )      )





	@property
	def 						A_(							self      )  ->					Optional[Any]:




				"""simple docstring"""



				warnings.warn(
				    '`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'      ,     SCREAMING_SNAKE_CASE      ,     )
				return self.image_processor_class





	@property
	def 						A_(							self      )  ->					Tuple:




				"""simple docstring"""



				warnings.warn(
				    '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'      ,     SCREAMING_SNAKE_CASE      ,     )
				return self.image_processor






from packaging import version

from .import_utils import is_accelerate_available


if is_accelerate_available():
				import accelerate

def lowercase    (  SCREAMING_SNAKE_CASE )			->							Union[str, Any]:


			'''simple docstring'''







			if not is_accelerate_available():
						return method
			SCREAMING_SNAKE_CASE_								=						version.parse(accelerate.__version__ ).base_version
			if version.parse(SCREAMING_SNAKE_CASE ) < version.parse('0.17.0' ):
						return method

			def wrapper(self       ,    *SCREAMING_SNAKE_CASE       ,    **SCREAMING_SNAKE_CASE ):
						if hasattr(self       ,    '_hf_hook' ) and hasattr(self._hf_hook       ,    'pre_forward' ):
									self._hf_hook.pre_forward(self )
						return method(self       ,    *SCREAMING_SNAKE_CASE       ,    **SCREAMING_SNAKE_CASE )

			return wrapper
