






"""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      UpperCamelCase		(A__     ):
						_SCREAMING_SNAKE_CASE  : Optional[Any]												=		["""image_processor""", """tokenizer"""]
						_SCREAMING_SNAKE_CASE  : Optional[int]												=		"""OwlViTImageProcessor"""
						_SCREAMING_SNAKE_CASE  : Optional[Any]												=		("""CLIPTokenizer""", """CLIPTokenizerFast""")






						def __init__(		self  :Any			, __magic_name__  :Any=None			, __magic_name__  :Optional[int]=None			, **__magic_name__  :Union[str, Any]				)      ->Tuple:
										lowercase    :      int       = None
										if "feature_extractor" in kwargs:
														warnings.warn(
														    """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
														    """ instead."""			, snake_case_			, )
														lowercase    :      int       = kwargs.pop("""feature_extractor"""				)

										lowercase    :      List[Any]       = 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__(snake_case_			, snake_case_				)






						def __call__(		self  :Any			, __magic_name__  :List[Any]=None			, __magic_name__  :Optional[int]=None			, __magic_name__  :Any=None			, __magic_name__  :Optional[int]="max_length"			, __magic_name__  :List[Any]="np"			, **__magic_name__  :Optional[int]				)      ->int:

										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(snake_case_			, snake_case_				) or (isinstance(snake_case_			, snake_case_				) and not isinstance(text[0]			, snake_case_				)):
																		lowercase    :      List[str]       = [self.tokenizer(snake_case_			, padding=snake_case_			, return_tensors=snake_case_			, **snake_case_				)]

														elif isinstance(snake_case_			, snake_case_				) and isinstance(text[0]			, snake_case_				):
																		lowercase    :      Optional[int]       = []

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

																		# Pad all batch samples to max number of text queries
																		for t in text:
																						if len(snake_case_				) != max_num_queries:
																										lowercase    :      Union[str, Any]       = t + [""" """] * (max_num_queries - len(snake_case_				))

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

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

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

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

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

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

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

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

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

														lowercase    :      str       = BatchEncoding()
														lowercase    :      Dict       = input_ids
														lowercase    :      Tuple       = attention_mask

										if query_images is not None:
														lowercase    :      int       = BatchEncoding()
														lowercase    :      str       = self.image_processor(
														    snake_case_			, return_tensors=snake_case_			, **snake_case_				).pixel_values
														lowercase    :      Optional[Any]       = query_pixel_values

										if images is not None:
														lowercase    :      Optional[Any]       = self.image_processor(snake_case_			, return_tensors=snake_case_			, **snake_case_				)

										if text is not None and images is not None:
														lowercase    :      Optional[int]       = image_features.pixel_values
														return encoding
										elif query_images is not None and images is not None:
														lowercase    :      List[str]       = image_features.pixel_values
														return encoding
										elif text is not None or query_images is not None:
														return encoding
										else:
														return BatchEncoding(data=dict(**snake_case_				)			, tensor_type=snake_case_				)






						def      __snake_case      (		self  :Tuple			, *__magic_name__  :Tuple			, **__magic_name__  :Dict				)      ->int:
										return self.image_processor.post_process(*snake_case_			, **snake_case_				)






						def      __snake_case      (		self  :Optional[int]			, *__magic_name__  :int			, **__magic_name__  :Optional[Any]				)      ->int:
										return self.image_processor.post_process_object_detection(*snake_case_			, **snake_case_				)






						def      __snake_case      (		self  :Dict			, *__magic_name__  :Union[str, Any]			, **__magic_name__  :Dict				)      ->Optional[int]:
										return self.image_processor.post_process_image_guided_detection(*snake_case_			, **snake_case_				)






						def      __snake_case      (		self  :Tuple			, *__magic_name__  :Any			, **__magic_name__  :List[Any]				)      ->Dict:
										return self.tokenizer.batch_decode(*snake_case_			, **snake_case_				)






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






						@property
						def      __snake_case      (		self  :str				)      ->Optional[int]:
										warnings.warn(
										    """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""			, snake_case_			, )
										return self.image_processor_class






						@property
						def      __snake_case      (		self  :List[str]				)      ->List[Any]:
										warnings.warn(
										    """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""			, snake_case_			, )
										return self.image_processor


"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE_					     =	logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_					     =	{
    '''alibaba-damo/mgp-str-base''': '''https://huggingface.co/alibaba-damo/mgp-str-base/resolve/main/config.json''',
}
class       lowerCAmelCase_		(				A__ ):



							'''simple docstring'''





							_snake_case						      =		'''mgp-str'''




							def __init__( self    ,				snake_case_=[32, 128]    ,				snake_case_=4    ,				snake_case_=3    ,				snake_case_=27    ,				snake_case_=38    ,				snake_case_=50_257    ,				snake_case_=30_522    ,				snake_case_=768    ,				snake_case_=12    ,				snake_case_=12    ,				snake_case_=4.0    ,				snake_case_=True    ,				snake_case_=False    ,				snake_case_=1e-5    ,				snake_case_=0.0    ,				snake_case_=0.0    ,				snake_case_=0.0    ,				snake_case_=False    ,				snake_case_=0.02    ,				**snake_case_    ,				)       ->  List[Any]:
													super().__init__(**snake_case_				)

													__lowerCAmelCase     =  image_size
													__lowerCAmelCase     =  patch_size
													__lowerCAmelCase     =  num_channels
													__lowerCAmelCase     =  max_token_length
													__lowerCAmelCase     =  num_character_labels
													__lowerCAmelCase     =  num_bpe_labels
													__lowerCAmelCase     =  num_wordpiece_labels
													__lowerCAmelCase     =  hidden_size
													__lowerCAmelCase     =  num_hidden_layers
													__lowerCAmelCase     =  num_attention_heads
													__lowerCAmelCase     =  mlp_ratio
													__lowerCAmelCase     =  distilled
													__lowerCAmelCase     =  layer_norm_eps
													__lowerCAmelCase     =  drop_rate
													__lowerCAmelCase     =  qkv_bias
													__lowerCAmelCase     =  attn_drop_rate
													__lowerCAmelCase     =  drop_path_rate
													__lowerCAmelCase     =  output_aa_attentions
													__lowerCAmelCase     =  initializer_range
