




'''simple docstring'''




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tensorflow_text_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowercase__  							=					{
    '''configuration_bert''': ['''BERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''BertConfig''', '''BertOnnxConfig'''],
    '''tokenization_bert''': ['''BasicTokenizer''', '''BertTokenizer''', '''WordpieceTokenizer'''],
}

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowercase__  							=					['''BertTokenizerFast''']

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowercase__  							=					[
					    '''BERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''BertForMaskedLM''',
					    '''BertForMultipleChoice''',
					    '''BertForNextSentencePrediction''',
					    '''BertForPreTraining''',
					    '''BertForQuestionAnswering''',
					    '''BertForSequenceClassification''',
					    '''BertForTokenClassification''',
					    '''BertLayer''',
					    '''BertLMHeadModel''',
					    '''BertModel''',
					    '''BertPreTrainedModel''',
					    '''load_tf_weights_in_bert''',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowercase__  							=					[
					    '''TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''TFBertEmbeddings''',
					    '''TFBertForMaskedLM''',
					    '''TFBertForMultipleChoice''',
					    '''TFBertForNextSentencePrediction''',
					    '''TFBertForPreTraining''',
					    '''TFBertForQuestionAnswering''',
					    '''TFBertForSequenceClassification''',
					    '''TFBertForTokenClassification''',
					    '''TFBertLMHeadModel''',
					    '''TFBertMainLayer''',
					    '''TFBertModel''',
					    '''TFBertPreTrainedModel''',
					]
try:
					if not is_tensorflow_text_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowercase__  							=					['''TFBertTokenizer''']

try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowercase__  							=					[
					    '''FlaxBertForCausalLM''',
					    '''FlaxBertForMaskedLM''',
					    '''FlaxBertForMultipleChoice''',
					    '''FlaxBertForNextSentencePrediction''',
					    '''FlaxBertForPreTraining''',
					    '''FlaxBertForQuestionAnswering''',
					    '''FlaxBertForSequenceClassification''',
					    '''FlaxBertForTokenClassification''',
					    '''FlaxBertModel''',
					    '''FlaxBertPreTrainedModel''',
					]

if TYPE_CHECKING:
					from .configuration_bert import BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, BertConfig, BertOnnxConfig
					from .tokenization_bert import BasicTokenizer, BertTokenizer, WordpieceTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_bert_fast import BertTokenizerFast

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_bert import (
										    BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    BertForMaskedLM,
										    BertForMultipleChoice,
										    BertForNextSentencePrediction,
										    BertForPreTraining,
										    BertForQuestionAnswering,
										    BertForSequenceClassification,
										    BertForTokenClassification,
										    BertLayer,
										    BertLMHeadModel,
										    BertModel,
										    BertPreTrainedModel,
										    load_tf_weights_in_bert,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_bert import (
										    TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFBertEmbeddings,
										    TFBertForMaskedLM,
										    TFBertForMultipleChoice,
										    TFBertForNextSentencePrediction,
										    TFBertForPreTraining,
										    TFBertForQuestionAnswering,
										    TFBertForSequenceClassification,
										    TFBertForTokenClassification,
										    TFBertLMHeadModel,
										    TFBertMainLayer,
										    TFBertModel,
										    TFBertPreTrainedModel,
										)

					try:
										if not is_tensorflow_text_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_bert_tf import TFBertTokenizer

					try:
										if not is_flax_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_flax_bert import (
										    FlaxBertForCausalLM,
										    FlaxBertForMaskedLM,
										    FlaxBertForMultipleChoice,
										    FlaxBertForNextSentencePrediction,
										    FlaxBertForPreTraining,
										    FlaxBertForQuestionAnswering,
										    FlaxBertForSequenceClassification,
										    FlaxBertForTokenClassification,
										    FlaxBertModel,
										    FlaxBertPreTrainedModel,
										)

else:
					import sys

					lowercase__  							=					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)











'''simple docstring'''
import os
from typing import List, Optional, Union

from ...image_processing_utils import BatchFeature
from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType
from ..auto import AutoTokenizer
class   __UpperCAmelCase				(     lowerCAmelCase				):



					'''simple docstring'''





					_UpperCamelCase							=		["""image_processor""", """tokenizer"""]
					_UpperCamelCase							=		"""BlipImageProcessor"""
					_UpperCamelCase							=		"""AutoTokenizer"""



					def __init__(	self     :						Union[str, Any]      ,       _lowercase     :						Union[str, Any]      ,       _lowercase     :						List[Any]      ,       _lowercase     :						List[str])    ->							Union[str, Any]:
								super().__init__(_lowercase      ,       _lowercase)

								# add QFormer tokenizer
								A_									= qformer_tokenizer



					def __call__(	self     :						Optional[int]      ,       _lowercase     :						ImageInput = None      ,       _lowercase     :						Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None      ,       _lowercase     :						bool = True      ,       _lowercase     :						Union[bool, str, PaddingStrategy] = False      ,       _lowercase     :						Union[bool, str, TruncationStrategy] = None      ,       _lowercase     :						Optional[int] = None      ,       _lowercase     :						int = 0      ,       _lowercase     :						Optional[int] = None      ,       _lowercase     :						Optional[bool] = None      ,       _lowercase     :						bool = False      ,       _lowercase     :						bool = False      ,       _lowercase     :						bool = False      ,       _lowercase     :						bool = False      ,       _lowercase     :						bool = False      ,       _lowercase     :						bool = True      ,       _lowercase     :						Optional[Union[str, TensorType]] = None      ,       **_lowercase     :						List[Any]      ,       )    ->							BatchFeature:
								if images is None and text is None:
											raise ValueError('You have to specify at least images or text.')

								A_									= BatchFeature()

								if text is not None:
											A_									= self.tokenizer(
											    text=_lowercase      ,       add_special_tokens=_lowercase      ,       padding=_lowercase      ,       truncation=_lowercase      ,       max_length=_lowercase      ,       stride=_lowercase      ,       pad_to_multiple_of=_lowercase      ,       return_attention_mask=_lowercase      ,       return_overflowing_tokens=_lowercase      ,       return_special_tokens_mask=_lowercase      ,       return_offsets_mapping=_lowercase      ,       return_token_type_ids=_lowercase      ,       return_length=_lowercase      ,       verbose=_lowercase      ,       return_tensors=_lowercase      ,       **_lowercase      ,       )
											encoding.update(_lowercase)
											A_									= self.qformer_tokenizer(
											    text=_lowercase      ,       add_special_tokens=_lowercase      ,       padding=_lowercase      ,       truncation=_lowercase      ,       max_length=_lowercase      ,       stride=_lowercase      ,       pad_to_multiple_of=_lowercase      ,       return_attention_mask=_lowercase      ,       return_overflowing_tokens=_lowercase      ,       return_special_tokens_mask=_lowercase      ,       return_offsets_mapping=_lowercase      ,       return_token_type_ids=_lowercase      ,       return_length=_lowercase      ,       verbose=_lowercase      ,       return_tensors=_lowercase      ,       **_lowercase      ,       )
											A_									= qformer_text_encoding.pop('input_ids')
											A_									= qformer_text_encoding.pop('attention_mask')

								if images is not None:
											A_									= self.image_processor(_lowercase      ,       return_tensors=_lowercase)
											encoding.update(_lowercase)

								return encoding



					def     __snake_case						(	self     :						List[Any]      ,       *_lowercase     :						Optional[Any]      ,       **_lowercase     :						List[Any])    ->							Union[str, Any]:
								return self.tokenizer.batch_decode(*_lowercase      ,       **_lowercase)



					def     __snake_case						(	self     :						Optional[int]      ,       *_lowercase     :						List[Any]      ,       **_lowercase     :						List[str])    ->							str:
								return self.tokenizer.decode(*_lowercase      ,       **_lowercase)



					@property
					# Copied from transformers.models.blip.processing_blip.BlipProcessor.model_input_names
					def     __snake_case						(	self     :						Any)    ->							Optional[int]:
								A_									= self.tokenizer.model_input_names
								A_									= self.image_processor.model_input_names
								return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))



					def     __snake_case						(	self     :						Optional[Any]      ,       _lowercase     :						Optional[int]      ,       **_lowercase     :						int)    ->							Tuple:
								if os.path.isfile(_lowercase):
											raise ValueError(F'Provided path ({save_directory}) should be a directory, not a file')
								os.makedirs(_lowercase      ,       exist_ok=_lowercase)
								A_									= os.path.join(_lowercase      ,       'qformer_tokenizer')
								self.qformer_tokenizer.save_pretrained(_lowercase)
								return super().save_pretrained(_lowercase      ,       **_lowercase)



					@classmethod
					def     __snake_case						(	cls     :						Dict      ,       _lowercase     :						Dict      ,       **_lowercase     :						int)    ->							Any:
								A_									= AutoTokenizer.from_pretrained(_lowercase      ,       subfolder='qformer_tokenizer')
								A_									= cls._get_arguments_from_pretrained(_lowercase      ,       **_lowercase)
								args.append(_lowercase)
								return cls(*_lowercase)




