
"""simple docstring"""






import importlib.metadata
from typing import Union

from packaging.version import Version, parse

from .constants import STR_OPERATION_TO_FUNC


UpperCAmelCase        =				parse(importlib.metadata.version("""torch"""))




def __magic_name__	(				_lowerCamelCase:		Union[str, Version],					_lowerCamelCase:		str,					_lowerCamelCase:		str			)					->						Dict:

	'''simple docstring'''




	if operation not in STR_OPERATION_TO_FUNC.keys():
		raise ValueError(F"""`operation` must be one of {list(STR_OPERATION_TO_FUNC.keys()			)}, received {operation}"""			)
	lowerCAmelCase												=  STR_OPERATION_TO_FUNC[operation]
	if isinstance(_lowerCamelCase,					_lowerCamelCase			):
		lowerCAmelCase												=  parse(importlib.metadata.version(_lowerCamelCase			)			)
	return operation(_lowerCamelCase,					parse(_lowerCamelCase			)			)




def __magic_name__	(				_lowerCamelCase:		str,					_lowerCamelCase:		str			)					->						int:

	'''simple docstring'''




	return compare_versions(_lowerCamelCase,					_lowerCamelCase,					_lowerCamelCase			)




"""simple docstring"""






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 			lowercase					( lowercase__		):
			lowercase        =     ['''image_processor''', '''tokenizer''']
			lowercase        =     '''BlipImageProcessor'''
			lowercase        =     ('''BertTokenizer''', '''BertTokenizerFast''')






			def __init__(self  :	Any      ,SCREAMING_SNAKE_CASE_  :	List[str]      ,SCREAMING_SNAKE_CASE_  :	Optional[int]			)       ->	Dict:





				"""simple docstring"""


				lowerCAmelCase												=  False
				super().__init__(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  self.image_processor






			def __call__(self  :	int      ,SCREAMING_SNAKE_CASE_  :	ImageInput = None      ,SCREAMING_SNAKE_CASE_  :	Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None      ,SCREAMING_SNAKE_CASE_  :	bool = True      ,SCREAMING_SNAKE_CASE_  :	Union[bool, str, PaddingStrategy] = False      ,SCREAMING_SNAKE_CASE_  :	Union[bool, str, TruncationStrategy] = None      ,SCREAMING_SNAKE_CASE_  :	Optional[int] = None      ,SCREAMING_SNAKE_CASE_  :	int = 0      ,SCREAMING_SNAKE_CASE_  :	Optional[int] = None      ,SCREAMING_SNAKE_CASE_  :	Optional[bool] = None      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = True      ,SCREAMING_SNAKE_CASE_  :	Optional[Union[str, TensorType]] = None      ,**SCREAMING_SNAKE_CASE_  :	str      ,)       ->	BatchEncoding:





				"""simple docstring"""


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

				# Get only text
				if images is None:
					lowerCAmelCase												=  self.tokenizer
					lowerCAmelCase												=  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_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_token_type_ids=SCREAMING_SNAKE_CASE_      ,return_length=SCREAMING_SNAKE_CASE_      ,verbose=SCREAMING_SNAKE_CASE_      ,return_tensors=SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_      ,)
					return text_encoding

				# add pixel_values
				lowerCAmelCase												=  self.image_processor(SCREAMING_SNAKE_CASE_      ,return_tensors=SCREAMING_SNAKE_CASE_			)

				if text is not None:
					lowerCAmelCase												=  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_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_token_type_ids=SCREAMING_SNAKE_CASE_      ,return_length=SCREAMING_SNAKE_CASE_      ,verbose=SCREAMING_SNAKE_CASE_      ,return_tensors=SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_      ,)
				else:
					lowerCAmelCase												=  None

				if text_encoding is not None:
					encoding_image_processor.update(SCREAMING_SNAKE_CASE_			)

				return encoding_image_processor






			def 					UpperCAmelCase							(self  :	List[str]      ,*SCREAMING_SNAKE_CASE_  :	str      ,**SCREAMING_SNAKE_CASE_  :	str			)       ->	Union[str, Any]:





				"""simple docstring"""


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






			def 					UpperCAmelCase							(self  :	List[Any]      ,*SCREAMING_SNAKE_CASE_  :	str      ,**SCREAMING_SNAKE_CASE_  :	Optional[int]			)       ->	Any:





				"""simple docstring"""


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






			@property
			def 					UpperCAmelCase							(self  :	Dict			)       ->	Tuple:





				"""simple docstring"""


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


