





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 				__lowerCAmelCase       (    UpperCamelCase__):
      _lowercase				:					Union[str, Any]						=			["""image_processor""", """tokenizer"""]
      _lowercase				:					Optional[Any]						=			"""BlipImageProcessor"""
      _lowercase				:					Any						=			"""AutoTokenizer"""







      def __init__(    self		,      lowerCAmelCase__		,      lowerCAmelCase__							)   ->						Union[str, Any]:



        '''simple docstring'''




        a__	:					Optional[Any]										=False
        super().__init__(lowerCAmelCase__		,      lowerCAmelCase__							)
        a__	:					Tuple										=self.image_processor







      def __call__(    self		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = True		,      lowerCAmelCase__ = False		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = 0		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = None		,      lowerCAmelCase__ = False		,      lowerCAmelCase__ = False		,      lowerCAmelCase__ = False		,      lowerCAmelCase__ = False		,      lowerCAmelCase__ = False		,      lowerCAmelCase__ = True		,      lowerCAmelCase__ = None		,      **lowerCAmelCase__		,      )   ->						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:
          a__	:					Tuple										=self.tokenizer
          a__	:					str										=self.tokenizer(
              text=lowerCAmelCase__		,      add_special_tokens=lowerCAmelCase__		,      padding=lowerCAmelCase__		,      truncation=lowerCAmelCase__		,      max_length=lowerCAmelCase__		,      stride=lowerCAmelCase__		,      pad_to_multiple_of=lowerCAmelCase__		,      return_attention_mask=lowerCAmelCase__		,      return_overflowing_tokens=lowerCAmelCase__		,      return_special_tokens_mask=lowerCAmelCase__		,      return_offsets_mapping=lowerCAmelCase__		,      return_token_type_ids=lowerCAmelCase__		,      return_length=lowerCAmelCase__		,      verbose=lowerCAmelCase__		,      return_tensors=lowerCAmelCase__		,      **lowerCAmelCase__		,      )
          return text_encoding

        # add pixel_values
        a__	:					Dict										=self.image_processor(lowerCAmelCase__		,      return_tensors=lowerCAmelCase__							)

        if text is not None:
          a__	:					List[str]										=self.tokenizer(
              text=lowerCAmelCase__		,      add_special_tokens=lowerCAmelCase__		,      padding=lowerCAmelCase__		,      truncation=lowerCAmelCase__		,      max_length=lowerCAmelCase__		,      stride=lowerCAmelCase__		,      pad_to_multiple_of=lowerCAmelCase__		,      return_attention_mask=lowerCAmelCase__		,      return_overflowing_tokens=lowerCAmelCase__		,      return_special_tokens_mask=lowerCAmelCase__		,      return_offsets_mapping=lowerCAmelCase__		,      return_token_type_ids=lowerCAmelCase__		,      return_length=lowerCAmelCase__		,      verbose=lowerCAmelCase__		,      return_tensors=lowerCAmelCase__		,      **lowerCAmelCase__		,      )
        else:
          a__	:					List[str]										=None

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

        return encoding_image_processor







      def    _lowercase  (    self		,      *lowerCAmelCase__		,      **lowerCAmelCase__							)   ->						int:



        '''simple docstring'''




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







      def    _lowercase  (    self		,      *lowerCAmelCase__		,      **lowerCAmelCase__							)   ->						Optional[Any]:



        '''simple docstring'''




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







      @property
      # Copied from transformers.models.blip.processing_blip.BlipProcessor.model_input_names
      def    _lowercase  (    self							)   ->						str:



        '''simple docstring'''




        a__	:					str										=self.tokenizer.model_input_names
        a__	:					List[str]										=self.image_processor.model_input_names
        return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names							)							)













from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCAmelCase	:	Optional[Any]		     =       logging.get_logger(__name__)

UpperCAmelCase	:	Optional[int]		     =       {
    """google/canine-s""": """https://huggingface.co/google/canine-s/resolve/main/config.json""",
    # See all CANINE models at https://huggingface.co/models?filter=canine
}







class 				__lowerCAmelCase       (    UpperCamelCase__):
      _lowercase				:					List[Any]						=			"""canine"""







      def __init__(    self		,      lowerCAmelCase__=7_6_8		,      lowerCAmelCase__=1_2		,      lowerCAmelCase__=1_2		,      lowerCAmelCase__=3_0_7_2		,      lowerCAmelCase__="gelu"		,      lowerCAmelCase__=0.1		,      lowerCAmelCase__=0.1		,      lowerCAmelCase__=1_6_3_8_4		,      lowerCAmelCase__=1_6		,      lowerCAmelCase__=0.02		,      lowerCAmelCase__=1E-12		,      lowerCAmelCase__=0		,      lowerCAmelCase__=0XE0_00		,      lowerCAmelCase__=0XE0_01		,      lowerCAmelCase__=4		,      lowerCAmelCase__=4		,      lowerCAmelCase__=8		,      lowerCAmelCase__=1_6_3_8_4		,      lowerCAmelCase__=1_2_8		,      **lowerCAmelCase__		,      )   ->						Dict:



        '''simple docstring'''




        super().__init__(pad_token_id=lowerCAmelCase__		,      bos_token_id=lowerCAmelCase__		,      eos_token_id=lowerCAmelCase__		,      **lowerCAmelCase__							)

        a__	:					Optional[int]										=max_position_embeddings
        a__	:					str										=hidden_size
        a__	:					Optional[Any]										=num_hidden_layers
        a__	:					Tuple										=num_attention_heads
        a__	:					Optional[Any]										=intermediate_size
        a__	:					Optional[int]										=hidden_act
        a__	:					List[Any]										=hidden_dropout_prob
        a__	:					Union[str, Any]										=attention_probs_dropout_prob
        a__	:					Optional[Any]										=initializer_range
        a__	:					Union[str, Any]										=type_vocab_size
        a__	:					Optional[int]										=layer_norm_eps

        # Character config:
        a__	:					int										=downsampling_rate
        a__	:					Optional[Any]										=upsampling_kernel_size
        a__	:					Union[str, Any]										=num_hash_functions
        a__	:					Any										=num_hash_buckets
        a__	:					int										=local_transformer_stride






