'''simple docstring'''





import warnings
from typing import List

import numpy as np

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
from ...utils import is_flax_available, is_tf_available, is_torch_available




class 			__A (					UpperCamelCase__      ):
    a__			:		Optional[int]			  =    ["""image_processor""", """tokenizer"""]
    a__			:		str			  =    """OwlViTImageProcessor"""
    a__			:		int			  =    ("""CLIPTokenizer""", """CLIPTokenizerFast""")



    def __init__(self       :       Optional[int]  ,     __a       :       List[Any]=None  ,     __a       :       str=None  ,     **__a       :       List[Any]					):
         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."  ,     __a  ,     )
              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__(__a  ,     __a					)



    def __call__(self       :       int  ,     __a       :       List[str]=None  ,     __a       :       Union[str, Any]=None  ,     __a       :       int=None  ,     __a       :       Dict="max_length"  ,     __a       :       List[Any]="np"  ,     **__a       :       Tuple					):

         if text is None and query_images is None and images is None:
              raise ValueError(
                  "You have to specify at least one text or query image or image. All three cannot be none."					)

         if text is not None:
              if isinstance(__a  ,     __a					) or (isinstance(__a  ,     __a					) and not isinstance(text[0]  ,     __a					)):
                   UpperCAmelCase_			       =  [self.tokenizer(__a  ,     padding=__a  ,     return_tensors=__a  ,     **__a					)]

              elif isinstance(__a  ,     __a					) and isinstance(text[0]  ,     __a					):
                   UpperCAmelCase_			       =  []

                   # Maximum number of queries across batch
                   UpperCAmelCase_			       =  max([len(__a					) for t in text]					)

                   # Pad all batch samples to max number of text queries
                   for t in text:
                        if len(__a					) != max_num_queries:
                             UpperCAmelCase_			       =  t + [" "] * (max_num_queries - len(__a					))

                        UpperCAmelCase_			       =  self.tokenizer(__a  ,     padding=__a  ,     return_tensors=__a  ,     **__a					)
                        encodings.append(__a					)
              else:
                   raise TypeError("Input text should be a string, a list of strings or a nested list of strings"					)

              if return_tensors == "np":
                   UpperCAmelCase_			       =  np.concatenate([encoding["input_ids"] for encoding in encodings]  ,     axis=0					)
                   UpperCAmelCase_			       =  np.concatenate([encoding["attention_mask"] for encoding in encodings]  ,     axis=0					)

              elif return_tensors == "jax" and is_flax_available():
                   import jax.numpy as jnp

                   UpperCAmelCase_			       =  jnp.concatenate([encoding["input_ids"] for encoding in encodings]  ,     axis=0					)
                   UpperCAmelCase_			       =  jnp.concatenate([encoding["attention_mask"] for encoding in encodings]  ,     axis=0					)

              elif return_tensors == "pt" and is_torch_available():
                   import torch

                   UpperCAmelCase_			       =  torch.cat([encoding["input_ids"] for encoding in encodings]  ,     dim=0					)
                   UpperCAmelCase_			       =  torch.cat([encoding["attention_mask"] for encoding in encodings]  ,     dim=0					)

              elif return_tensors == "tf" and is_tf_available():
                   import tensorflow as tf

                   UpperCAmelCase_			       =  tf.stack([encoding["input_ids"] for encoding in encodings]  ,     axis=0					)
                   UpperCAmelCase_			       =  tf.stack([encoding["attention_mask"] for encoding in encodings]  ,     axis=0					)

              else:
                   raise ValueError("Target return tensor type could not be returned"					)

              UpperCAmelCase_			       =  BatchEncoding()
              UpperCAmelCase_			       =  input_ids
              UpperCAmelCase_			       =  attention_mask

         if query_images is not None:
              UpperCAmelCase_			       =  BatchEncoding()
              UpperCAmelCase_			       =  self.image_processor(
                  __a  ,     return_tensors=__a  ,     **__a					).pixel_values
              UpperCAmelCase_			       =  query_pixel_values

         if images is not None:
              UpperCAmelCase_			       =  self.image_processor(__a  ,     return_tensors=__a  ,     **__a					)

         if text is not None and images is not None:
              UpperCAmelCase_			       =  image_features.pixel_values
              return encoding
         elif query_images is not None and images is not None:
              UpperCAmelCase_			       =  image_features.pixel_values
              return encoding
         elif text is not None or query_images is not None:
              return encoding
         else:
              return BatchEncoding(data=dict(**__a					)  ,     tensor_type=__a					)



    def    _lowercase		(self       :       List[str]  ,     *__a       :       Optional[Any]  ,     **__a       :       Dict					):
         return self.image_processor.post_process(*__a  ,     **__a					)



    def    _lowercase		(self       :       List[Any]  ,     *__a       :       Optional[int]  ,     **__a       :       Optional[int]					):
         return self.image_processor.post_process_object_detection(*__a  ,     **__a					)



    def    _lowercase		(self       :       Optional[int]  ,     *__a       :       int  ,     **__a       :       Union[str, Any]					):
         return self.image_processor.post_process_image_guided_detection(*__a  ,     **__a					)



    def    _lowercase		(self       :       List[str]  ,     *__a       :       List[str]  ,     **__a       :       List[str]					):
         return self.tokenizer.batch_decode(*__a  ,     **__a					)



    def    _lowercase		(self       :       int  ,     *__a       :       List[Any]  ,     **__a       :       Tuple					):
         return self.tokenizer.decode(*__a  ,     **__a					)



    @property
    def    _lowercase		(self       :       Optional[Any]					):
         warnings.warn(
             "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."  ,     __a  ,     )
         return self.image_processor_class






    @property
    def    _lowercase		(self       :       Union[str, Any]					):
         warnings.warn(
             "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."  ,     __a  ,     )
         return self.image_processor









"""simple docstring"""







import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_electra import ElectraTokenizer


UpperCamelCase     =							{"""vocab_file""": """vocab.txt""", """tokenizer_file""": """tokenizer.json"""}

UpperCamelCase     =							{
    """vocab_file""": {
        """google/electra-small-generator""": (
            """https://huggingface.co/google/electra-small-generator/resolve/main/vocab.txt"""
        ),
        """google/electra-base-generator""": """https://huggingface.co/google/electra-base-generator/resolve/main/vocab.txt""",
        """google/electra-large-generator""": (
            """https://huggingface.co/google/electra-large-generator/resolve/main/vocab.txt"""
        ),
        """google/electra-small-discriminator""": (
            """https://huggingface.co/google/electra-small-discriminator/resolve/main/vocab.txt"""
        ),
        """google/electra-base-discriminator""": (
            """https://huggingface.co/google/electra-base-discriminator/resolve/main/vocab.txt"""
        ),
        """google/electra-large-discriminator""": (
            """https://huggingface.co/google/electra-large-discriminator/resolve/main/vocab.txt"""
        ),
    },
    """tokenizer_file""": {
        """google/electra-small-generator""": (
            """https://huggingface.co/google/electra-small-generator/resolve/main/tokenizer.json"""
        ),
        """google/electra-base-generator""": (
            """https://huggingface.co/google/electra-base-generator/resolve/main/tokenizer.json"""
        ),
        """google/electra-large-generator""": (
            """https://huggingface.co/google/electra-large-generator/resolve/main/tokenizer.json"""
        ),
        """google/electra-small-discriminator""": (
            """https://huggingface.co/google/electra-small-discriminator/resolve/main/tokenizer.json"""
        ),
        """google/electra-base-discriminator""": (
            """https://huggingface.co/google/electra-base-discriminator/resolve/main/tokenizer.json"""
        ),
        """google/electra-large-discriminator""": (
            """https://huggingface.co/google/electra-large-discriminator/resolve/main/tokenizer.json"""
        ),
    },
}

UpperCamelCase     =							{
    """google/electra-small-generator""": 512,
    """google/electra-base-generator""": 512,
    """google/electra-large-generator""": 512,
    """google/electra-small-discriminator""": 512,
    """google/electra-base-discriminator""": 512,
    """google/electra-large-discriminator""": 512,
}

UpperCamelCase     =							{
    """google/electra-small-generator""": {"""do_lower_case""": True},
    """google/electra-base-generator""": {"""do_lower_case""": True},
    """google/electra-large-generator""": {"""do_lower_case""": True},
    """google/electra-small-discriminator""": {"""do_lower_case""": True},
    """google/electra-base-discriminator""": {"""do_lower_case""": True},
    """google/electra-large-discriminator""": {"""do_lower_case""": True},
}






class       UpperCamelCase__			(   _lowerCAmelCase      ):

			"""simple docstring"""


			A__	:					Dict							  =     VOCAB_FILES_NAMES
			A__	:					str							  =     PRETRAINED_VOCAB_FILES_MAP
			A__	:					List[Any]							  =     PRETRAINED_INIT_CONFIGURATION
			A__	:					Any							  =     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			A__	:					List[str]							  =     ElectraTokenizer


			def __init__(      self						,	SCREAMING_SNAKE_CASE__=None						,	SCREAMING_SNAKE_CASE__=None						,	SCREAMING_SNAKE_CASE__=True						,	SCREAMING_SNAKE_CASE__="[UNK]"						,	SCREAMING_SNAKE_CASE__="[SEP]"						,	SCREAMING_SNAKE_CASE__="[PAD]"						,	SCREAMING_SNAKE_CASE__="[CLS]"						,	SCREAMING_SNAKE_CASE__="[MASK]"						,	SCREAMING_SNAKE_CASE__=True						,	SCREAMING_SNAKE_CASE__=None						,	**SCREAMING_SNAKE_CASE__						,	)      ->	str:
				super().__init__(
				    SCREAMING_SNAKE_CASE__						,	tokenizer_file=SCREAMING_SNAKE_CASE__						,	do_lower_case=SCREAMING_SNAKE_CASE__						,	unk_token=SCREAMING_SNAKE_CASE__						,	sep_token=SCREAMING_SNAKE_CASE__						,	pad_token=SCREAMING_SNAKE_CASE__						,	cls_token=SCREAMING_SNAKE_CASE__						,	mask_token=SCREAMING_SNAKE_CASE__						,	tokenize_chinese_chars=SCREAMING_SNAKE_CASE__						,	strip_accents=SCREAMING_SNAKE_CASE__						,	**SCREAMING_SNAKE_CASE__						,	)

				A__											=					json.loads(self.backend_tokenizer.normalizer.__getstate__()		)
				if (
				    normalizer_state.get("lowercase"						,	SCREAMING_SNAKE_CASE__		) != do_lower_case
				    or normalizer_state.get("strip_accents"						,	SCREAMING_SNAKE_CASE__		) != strip_accents
				    or normalizer_state.get("handle_chinese_chars"						,	SCREAMING_SNAKE_CASE__		) != tokenize_chinese_chars
				):
					A__											=					getattr(SCREAMING_SNAKE_CASE__						,	normalizer_state.pop("type"		)		)
					A__											=					do_lower_case
					A__											=					strip_accents
					A__											=					tokenize_chinese_chars
					A__											=					normalizer_class(**SCREAMING_SNAKE_CASE__		)

				A__											=					do_lower_case


			def   snake_case__	(      self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__=None		)      ->	List[str]:
				A__											=					[self.cls_token_id] + token_ids_a + [self.sep_token_id]

				if token_ids_a:
					output += token_ids_a + [self.sep_token_id]

				return output


			def   snake_case__	(      self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__ = None		)      ->	List[int]:
				A__											=					[self.sep_token_id]
				A__											=					[self.cls_token_id]
				if token_ids_a is None:
					return len(cls + token_ids_a + sep		) * [0]
				return len(cls + token_ids_a + sep		) * [0] + len(token_ids_a + sep		) * [1]







			def   snake_case__	(      self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__ = None		)      ->	Tuple[str]:
				A__											=					self._tokenizer.model.save(SCREAMING_SNAKE_CASE__						,	name=SCREAMING_SNAKE_CASE__		)
				return tuple(SCREAMING_SNAKE_CASE__		)




