


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 			_lowercase (							lowercase__):


       """simple docstring"""




       A__											=			["image_processor", "tokenizer"]
       A__											=			"OwlViTImageProcessor"
       A__											=			("CLIPTokenizer", "CLIPTokenizerFast")





       def __init__(   self							:			List[Any]					,      __lowerCamelCase							:			Any=None					,      __lowerCamelCase							:			List[Any]=None					,      **__lowerCamelCase							:			str       ):


             '''simple docstring'''



             lowerCamelCase__		:				Tuple    =  None
             if "feature_extractor" in kwargs:
                   warnings.warn(
                       "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
                       " instead."					,      __lowerCamelCase					,      )
                   lowerCamelCase__		:				List[str]    =  kwargs.pop("feature_extractor"       )

             lowerCamelCase__		:				Tuple    =  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__(__lowerCamelCase					,      __lowerCamelCase       )





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


             '''simple docstring'''



             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(__lowerCamelCase					,      __lowerCamelCase       ) or (isinstance(__lowerCamelCase					,      __lowerCamelCase       ) and not isinstance(text[0]					,      __lowerCamelCase       )):
                         lowerCamelCase__		:				int    =  [self.tokenizer(__lowerCamelCase					,      padding=__lowerCamelCase					,      return_tensors=__lowerCamelCase					,      **__lowerCamelCase       )]

                   elif isinstance(__lowerCamelCase					,      __lowerCamelCase       ) and isinstance(text[0]					,      __lowerCamelCase       ):
                         lowerCamelCase__		:				Any    =  []

                         # Maximum number of queries across batch
                         lowerCamelCase__		:				List[str]    =  max([len(__lowerCamelCase       ) for t in text]       )

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

                               lowerCamelCase__		:				Optional[int]    =  self.tokenizer(__lowerCamelCase					,      padding=__lowerCamelCase					,      return_tensors=__lowerCamelCase					,      **__lowerCamelCase       )
                               encodings.append(__lowerCamelCase       )
                   else:
                         raise TypeError("Input text should be a string, a list of strings or a nested list of strings"       )

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

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

                         lowerCamelCase__		:				List[Any]    =  jnp.concatenate([encoding["input_ids"] for encoding in encodings]					,      axis=0       )
                         lowerCamelCase__		:				str    =  jnp.concatenate([encoding["attention_mask"] for encoding in encodings]					,      axis=0       )

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

                         lowerCamelCase__		:				List[str]    =  torch.cat([encoding["input_ids"] for encoding in encodings]					,      dim=0       )
                         lowerCamelCase__		:				Tuple    =  torch.cat([encoding["attention_mask"] for encoding in encodings]					,      dim=0       )

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

                         lowerCamelCase__		:				Union[str, Any]    =  tf.stack([encoding["input_ids"] for encoding in encodings]					,      axis=0       )
                         lowerCamelCase__		:				List[str]    =  tf.stack([encoding["attention_mask"] for encoding in encodings]					,      axis=0       )

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

                   lowerCamelCase__		:				List[Any]    =  BatchEncoding()
                   lowerCamelCase__		:				List[str]    =  input_ids
                   lowerCamelCase__		:				Any    =  attention_mask

             if query_images is not None:
                   lowerCamelCase__		:				List[str]    =  BatchEncoding()
                   lowerCamelCase__		:				Dict    =  self.image_processor(
                       __lowerCamelCase					,      return_tensors=__lowerCamelCase					,      **__lowerCamelCase       ).pixel_values
                   lowerCamelCase__		:				List[str]    =  query_pixel_values

             if images is not None:
                   lowerCamelCase__		:				List[Any]    =  self.image_processor(__lowerCamelCase					,      return_tensors=__lowerCamelCase					,      **__lowerCamelCase       )

             if text is not None and images is not None:
                   lowerCamelCase__		:				List[Any]    =  image_features.pixel_values
                   return encoding
             elif query_images is not None and images is not None:
                   lowerCamelCase__		:				Tuple    =  image_features.pixel_values
                   return encoding
             elif text is not None or query_images is not None:
                   return encoding
             else:
                   return BatchEncoding(data=dict(**__lowerCamelCase       )					,      tensor_type=__lowerCamelCase       )





       def 						lowerCAmelCase     (   self							:			str					,      *__lowerCamelCase							:			str					,      **__lowerCamelCase							:			int       ):


             '''simple docstring'''



             return self.image_processor.post_process(*__lowerCamelCase					,      **__lowerCamelCase       )





       def 						lowerCAmelCase     (   self							:			List[str]					,      *__lowerCamelCase							:			Union[str, Any]					,      **__lowerCamelCase							:			Dict       ):


             '''simple docstring'''



             return self.image_processor.post_process_object_detection(*__lowerCamelCase					,      **__lowerCamelCase       )





       def 						lowerCAmelCase     (   self							:			Union[str, Any]					,      *__lowerCamelCase							:			List[Any]					,      **__lowerCamelCase							:			Union[str, Any]       ):


             '''simple docstring'''



             return self.image_processor.post_process_image_guided_detection(*__lowerCamelCase					,      **__lowerCamelCase       )





       def 						lowerCAmelCase     (   self							:			Dict					,      *__lowerCamelCase							:			Optional[Any]					,      **__lowerCamelCase							:			List[Any]       ):


             '''simple docstring'''



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





       def 						lowerCAmelCase     (   self							:			Tuple					,      *__lowerCamelCase							:			Optional[int]					,      **__lowerCamelCase							:			Optional[int]       ):


             '''simple docstring'''



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





       @property
       def 						lowerCAmelCase     (   self							:			Optional[Any]       ):


             '''simple docstring'''



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





       @property
       def 						lowerCAmelCase     (   self							:			str       ):


             '''simple docstring'''



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






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


A      :    str		=					logging.get_logger(__name__)

A      :    int		=					{
    "alibaba-damo/mgp-str-base": "https://huggingface.co/alibaba-damo/mgp-str-base/resolve/main/config.json",
}







class 			_lowercase (							lowercase__):


       """simple docstring"""




       A__											=			"mgp-str"





       def __init__(   self							:			List[str]					,      __lowerCamelCase							:			List[Any]=[32, 128]					,      __lowerCamelCase							:			Optional[int]=4					,      __lowerCamelCase							:			str=3					,      __lowerCamelCase							:			Optional[Any]=27					,      __lowerCamelCase							:			List[str]=38					,      __lowerCamelCase							:			Dict=50257					,      __lowerCamelCase							:			List[Any]=30522					,      __lowerCamelCase							:			Optional[Any]=768					,      __lowerCamelCase							:			str=12					,      __lowerCamelCase							:			Optional[int]=12					,      __lowerCamelCase							:			List[str]=4.0					,      __lowerCamelCase							:			Union[str, Any]=True					,      __lowerCamelCase							:			Any=False					,      __lowerCamelCase							:			Dict=1E-5					,      __lowerCamelCase							:			int=0.0					,      __lowerCamelCase							:			Optional[int]=0.0					,      __lowerCamelCase							:			List[Any]=0.0					,      __lowerCamelCase							:			Union[str, Any]=False					,      __lowerCamelCase							:			str=0.0_2					,      **__lowerCamelCase							:			Dict					,      ):


             '''simple docstring'''



             super().__init__(**__lowerCamelCase       )

             lowerCamelCase__		:				int    =  image_size
             lowerCamelCase__		:				Union[str, Any]    =  patch_size
             lowerCamelCase__		:				Dict    =  num_channels
             lowerCamelCase__		:				Union[str, Any]    =  max_token_length
             lowerCamelCase__		:				Optional[int]    =  num_character_labels
             lowerCamelCase__		:				Union[str, Any]    =  num_bpe_labels
             lowerCamelCase__		:				Optional[int]    =  num_wordpiece_labels
             lowerCamelCase__		:				List[str]    =  hidden_size
             lowerCamelCase__		:				Dict    =  num_hidden_layers
             lowerCamelCase__		:				Any    =  num_attention_heads
             lowerCamelCase__		:				Any    =  mlp_ratio
             lowerCamelCase__		:				List[Any]    =  distilled
             lowerCamelCase__		:				Optional[Any]    =  layer_norm_eps
             lowerCamelCase__		:				Union[str, Any]    =  drop_rate
             lowerCamelCase__		:				List[Any]    =  qkv_bias
             lowerCamelCase__		:				int    =  attn_drop_rate
             lowerCamelCase__		:				List[Any]    =  drop_path_rate
             lowerCamelCase__		:				List[str]    =  output_aa_attentions
             lowerCamelCase__		:				Dict    =  initializer_range


