


from importlib import import_module

from .logging import get_logger


__snake_case            =   get_logger(__name__)




class    UpperCAmelCase					:




			def __init__(						self							:		List[str]       ,       __magic_name__							:		Optional[int]       ,       __magic_name__							:		Optional[int]=None						):







						"""simple docstring"""







						UpperCamelCase         =					attrs or []
						if module is not None:
									for key in module.__dict__:
												if key in attrs or not key.startswith("""__"""						):
															setattr(self       ,       __magic_name__       ,       getattr(__magic_name__       ,       __magic_name__						)						)
						UpperCamelCase         =					module._original_module if isinstance(__magic_name__       ,       _PatchedModuleObj						) else module




class    UpperCAmelCase					:
			lowercase						= []




			def __init__(						self							:		List[Any]       ,       __magic_name__							:		str       ,       __magic_name__							:		str       ,       __magic_name__							:		Tuple       ,       __magic_name__							:		Dict=None						):







						"""simple docstring"""







						UpperCamelCase         =					obj
						UpperCamelCase         =					target
						UpperCamelCase         =					new
						UpperCamelCase         =					target.split("""."""						)[0]
						UpperCamelCase         =					{}
						UpperCamelCase         =					attrs or []




			def __enter__(						self							:		Any						):







						"""simple docstring"""







						*UpperCamelCase  ,  UpperCamelCase         =					self.target.split("""."""						)

						# Patch modules:
						# it's used to patch attributes of submodules like "os.path.join";
						# in this case we need to patch "os" and "os.path"

						for i in range(len(__magic_name__						)						):
									try:
												UpperCamelCase         =					import_module(""".""".join(submodules[: i + 1]						)						)
									except ModuleNotFoundError:
												continue
									# We iterate over all the globals in self.obj in case we find "os" or "os.path"
									for attr in self.obj.__dir__():
												UpperCamelCase         =					getattr(self.obj       ,       __magic_name__						)
												# We don't check for the name of the global, but rather if its value *is* "os" or "os.path".
												# This allows to patch renamed modules like "from os import path as ospath".
												if obj_attr is submodule or (
												    (isinstance(__magic_name__       ,       _PatchedModuleObj						) and obj_attr._original_module is submodule)
												):
															UpperCamelCase         =					obj_attr
															# patch at top level
															setattr(self.obj       ,       __magic_name__       ,       _PatchedModuleObj(__magic_name__       ,       attrs=self.attrs						)						)
															UpperCamelCase         =					getattr(self.obj       ,       __magic_name__						)
															# construct lower levels patches
															for key in submodules[i + 1 :]:
																		setattr(__magic_name__       ,       __magic_name__       ,       _PatchedModuleObj(getattr(__magic_name__       ,       __magic_name__       ,       __magic_name__						)       ,       attrs=self.attrs						)						)
																		UpperCamelCase         =					getattr(__magic_name__       ,       __magic_name__						)
															# finally set the target attribute
															setattr(__magic_name__       ,       __magic_name__       ,       self.new						)

        # Patch attribute itself:
        # it's used for builtins like "open",
        # and also to patch "os.path.join" we may also need to patch "join"
        # itself if it was imported as "from os.path import join".

						if submodules:  # if it's an attribute of a submodule like "os.path.join"
									try:
												UpperCamelCase         =					getattr(import_module(""".""".join(__magic_name__						)						)       ,       __magic_name__						)
									except (AttributeError, ModuleNotFoundError):
												return
									# We iterate over all the globals in self.obj in case we find "os.path.join"
									for attr in self.obj.__dir__():
												# We don't check for the name of the global, but rather if its value *is* "os.path.join".
												# This allows to patch renamed attributes like "from os.path import join as pjoin".
												if getattr(self.obj       ,       __magic_name__						) is attr_value:
															UpperCamelCase         =					getattr(self.obj       ,       __magic_name__						)
															setattr(self.obj       ,       __magic_name__       ,       self.new						)
						elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
									UpperCamelCase         =					globals()["""__builtins__"""][target_attr]
									setattr(self.obj       ,       __magic_name__       ,       self.new						)
						else:
									raise RuntimeError(F'Tried to patch attribute {target_attr} instead of a submodule.'						)




			def __exit__(						self							:		Union[str, Any]       ,       *__magic_name__							:		List[str]						):







						"""simple docstring"""







						for attr in list(self.original						):
									setattr(self.obj       ,       __magic_name__       ,       self.original.pop(__magic_name__						)						)




			def   lowerCamelCase_					(						self							:		str						):







						"""simple docstring"""







						self.__enter__()
						self._active_patches.append(self						)





			def   lowerCamelCase_					(						self							:		Union[str, Any]						):







						"""simple docstring"""







						try:
									self._active_patches.remove(self						)
						except ValueError:
									# If the patch hasn't been started this will fail
									return None

						return self.__exit__()








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    UpperCAmelCase					(       __snake_case    ):
			lowercase						= ["""image_processor""", """tokenizer"""]
			lowercase						= """FlavaImageProcessor"""
			lowercase						= ("""BertTokenizer""", """BertTokenizerFast""")




			def __init__(						self							:		Optional[int]       ,       __magic_name__							:		Optional[int]=None       ,       __magic_name__							:		str=None       ,       **__magic_name__							:		Any						):







						"""simple docstring"""







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

						UpperCamelCase         =					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__(__magic_name__       ,       __magic_name__						)
						UpperCamelCase         =					self.image_processor




			def __call__(						self							:		int       ,       __magic_name__							:		Optional[ImageInput] = None       ,       __magic_name__							:		Optional[Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]] = None       ,       __magic_name__							:		bool = True       ,       __magic_name__							:		Union[bool, str, PaddingStrategy] = False       ,       __magic_name__							:		Union[bool, str, TruncationStrategy] = False       ,       __magic_name__							:		Optional[int] = None       ,       __magic_name__							:		int = 0       ,       __magic_name__							:		Optional[int] = None       ,       __magic_name__							:		Optional[bool] = None       ,       __magic_name__							:		Optional[bool] = None       ,       __magic_name__							:		Optional[bool] = None       ,       __magic_name__							:		Optional[bool] = None       ,       __magic_name__							:		bool = False       ,       __magic_name__							:		bool = False       ,       __magic_name__							:		bool = False       ,       __magic_name__							:		bool = False       ,       __magic_name__							:		bool = True       ,       __magic_name__							:		Optional[Union[str, TensorType]] = None       ,       **__magic_name__							:		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:
									UpperCamelCase         =					self.tokenizer(
									    text=__magic_name__       ,       add_special_tokens=__magic_name__       ,       padding=__magic_name__       ,       truncation=__magic_name__       ,       max_length=__magic_name__       ,       stride=__magic_name__       ,       pad_to_multiple_of=__magic_name__       ,       return_token_type_ids=__magic_name__       ,       return_attention_mask=__magic_name__       ,       return_overflowing_tokens=__magic_name__       ,       return_special_tokens_mask=__magic_name__       ,       return_offsets_mapping=__magic_name__       ,       return_length=__magic_name__       ,       verbose=__magic_name__       ,       return_tensors=__magic_name__       ,       **__magic_name__       ,       )
						if images is not None:
									UpperCamelCase         =					self.image_processor(
									    __magic_name__       ,       return_image_mask=__magic_name__       ,       return_codebook_pixels=__magic_name__       ,       return_tensors=__magic_name__       ,       **__magic_name__       ,       )

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




			def   lowerCamelCase_					(						self							:		Tuple       ,       *__magic_name__							:		Dict       ,       **__magic_name__							:		List[Any]						):







						"""simple docstring"""







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




			def   lowerCamelCase_					(						self							:		int       ,       *__magic_name__							:		Tuple       ,       **__magic_name__							:		Optional[Any]						):







						"""simple docstring"""







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




			@property
			def   lowerCamelCase_					(						self							:		Tuple						):







						"""simple docstring"""







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




			@property
			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







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





			@property
			def   lowerCamelCase_					(						self							:		Tuple						):







						"""simple docstring"""







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




