


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     a		(_UpperCAmelCase				):




       """simple docstring"""


       __UpperCAmelCase   :							int					  =  ["image_processor", "tokenizer"]
       __UpperCAmelCase   :							List[Any]					  =  "BlipImageProcessor"
       __UpperCAmelCase   :							Any					  =  "AutoTokenizer"

       def __init__(							self	:  Union[str, Any]   ,     lowerCamelCase	:  Optional[int]   ,     lowerCamelCase	:  int    )     ->   Any:
              __snake_case		:      Dict										=       False
              super().__init__(_UpperCAmelCase   ,     _UpperCAmelCase    )
              __snake_case		:      Dict										=       self.image_processor

       def __call__(							self	:  int   ,     lowerCamelCase	:  Optional[int] = None   ,     lowerCamelCase	:  int = None   ,     lowerCamelCase	:  List[str] = True   ,     lowerCamelCase	:  Optional[Any] = False   ,     lowerCamelCase	:  Optional[int] = None   ,     lowerCamelCase	:  Optional[Any] = None   ,     lowerCamelCase	:  Any = 0   ,     lowerCamelCase	:  Any = None   ,     lowerCamelCase	:  Optional[int] = None   ,     lowerCamelCase	:  List[str] = False   ,     lowerCamelCase	:  Union[str, Any] = False   ,     lowerCamelCase	:  Union[str, Any] = False   ,     lowerCamelCase	:  Optional[int] = False   ,     lowerCamelCase	:  Optional[Any] = False   ,     lowerCamelCase	:  List[Any] = True   ,     lowerCamelCase	:  Optional[int] = None   ,     **lowerCamelCase	:  int   ,     )     ->   Optional[int]:
              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:
                     __snake_case		:      Optional[int]										=       self.tokenizer
                     __snake_case		:      List[str]										=       self.tokenizer(
                         text=_UpperCAmelCase   ,     add_special_tokens=_UpperCAmelCase   ,     padding=_UpperCAmelCase   ,     truncation=_UpperCAmelCase   ,     max_length=_UpperCAmelCase   ,     stride=_UpperCAmelCase   ,     pad_to_multiple_of=_UpperCAmelCase   ,     return_attention_mask=_UpperCAmelCase   ,     return_overflowing_tokens=_UpperCAmelCase   ,     return_special_tokens_mask=_UpperCAmelCase   ,     return_offsets_mapping=_UpperCAmelCase   ,     return_token_type_ids=_UpperCAmelCase   ,     return_length=_UpperCAmelCase   ,     verbose=_UpperCAmelCase   ,     return_tensors=_UpperCAmelCase   ,     **_UpperCAmelCase   ,     )
                     return text_encoding

              # add pixel_values
              __snake_case		:      Optional[int]										=       self.image_processor(_UpperCAmelCase   ,     return_tensors=_UpperCAmelCase    )

              if text is not None:
                     __snake_case		:      Any										=       self.tokenizer(
                         text=_UpperCAmelCase   ,     add_special_tokens=_UpperCAmelCase   ,     padding=_UpperCAmelCase   ,     truncation=_UpperCAmelCase   ,     max_length=_UpperCAmelCase   ,     stride=_UpperCAmelCase   ,     pad_to_multiple_of=_UpperCAmelCase   ,     return_attention_mask=_UpperCAmelCase   ,     return_overflowing_tokens=_UpperCAmelCase   ,     return_special_tokens_mask=_UpperCAmelCase   ,     return_offsets_mapping=_UpperCAmelCase   ,     return_token_type_ids=_UpperCAmelCase   ,     return_length=_UpperCAmelCase   ,     verbose=_UpperCAmelCase   ,     return_tensors=_UpperCAmelCase   ,     **_UpperCAmelCase   ,     )
              else:
                     __snake_case		:      Dict										=       None

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

              return encoding_image_processor

       def    __snake_case (							self	:  Optional[int]   ,     *lowerCamelCase	:  int   ,     **lowerCamelCase	:  List[str]    )     ->   List[str]:
              return self.tokenizer.batch_decode(*_UpperCAmelCase   ,     **_UpperCAmelCase    )

       def    __snake_case (							self	:  Tuple   ,     *lowerCamelCase	:  Union[str, Any]   ,     **lowerCamelCase	:  Optional[int]    )     ->   str:
              return self.tokenizer.decode(*_UpperCAmelCase   ,     **_UpperCAmelCase    )






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





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		(_lowerCAmelCase				):




							"""simple docstring"""


							__UpperCAmelCase   :							List[str]					  =  ["image_processor", "tokenizer"]
							__UpperCAmelCase   :							str					  =  "OwlViTImageProcessor"
							__UpperCAmelCase   :							Dict					  =  ("CLIPTokenizer", "CLIPTokenizerFast")

							def __init__(							self	:  str   ,     lowerCamelCase	:  Any=None   ,     lowerCamelCase	:  Any=None   ,     **lowerCamelCase	:  Union[str, Any]    )     ->   List[Any]:
														__snake_case		:      List[Any]										=       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   ,     )
																					__snake_case		:      List[Any]										=       kwargs.pop("feature_extractor"    )

														__snake_case		:      str										=       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	:  Union[str, Any]   ,     lowerCamelCase	:  Tuple=None   ,     lowerCamelCase	:  int=None   ,     lowerCamelCase	:  Union[str, Any]=None   ,     lowerCamelCase	:  List[str]="max_length"   ,     lowerCamelCase	:  Dict="np"   ,     **lowerCamelCase	:  str    )     ->   List[Any]:

														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    )):
																												__snake_case		:      Union[str, Any]										=       [self.tokenizer(lowerCamelCase   ,     padding=lowerCamelCase   ,     return_tensors=lowerCamelCase   ,     **lowerCamelCase    )]

																					elif isinstance(lowerCamelCase   ,     lowerCamelCase    ) and isinstance(text[0]   ,     lowerCamelCase    ):
																												__snake_case		:      Tuple										=       []

																												# Maximum number of queries across batch
																												__snake_case		:      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:
																																										__snake_case		:      Dict										=       t + [" "] * (max_num_queries - len(lowerCamelCase    ))

																																			__snake_case		:      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":
																												__snake_case		:      Any										=       np.concatenate([encoding["input_ids"] for encoding in encodings]   ,     axis=0    )
																												__snake_case		:      Tuple										=       np.concatenate([encoding["attention_mask"] for encoding in encodings]   ,     axis=0    )

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

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

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

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

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

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

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

																					__snake_case		:      Any										=       BatchEncoding()
																					__snake_case		:      Tuple										=       input_ids
																					__snake_case		:      int										=       attention_mask

														if query_images is not None:
																					__snake_case		:      List[Any]										=       BatchEncoding()
																					__snake_case		:      Union[str, Any]										=       self.image_processor(
																					    lowerCamelCase   ,     return_tensors=lowerCamelCase   ,     **lowerCamelCase    ).pixel_values
																					__snake_case		:      str										=       query_pixel_values

														if images is not None:
																					__snake_case		:      Optional[int]										=       self.image_processor(lowerCamelCase   ,     return_tensors=lowerCamelCase   ,     **lowerCamelCase    )

														if text is not None and images is not None:
																					__snake_case		:      List[str]										=       image_features.pixel_values
																					return encoding
														elif query_images is not None and images is not None:
																					__snake_case		:      int										=       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    __snake_case (							self	:  Dict   ,     *lowerCamelCase	:  List[Any]   ,     **lowerCamelCase	:  Union[str, Any]    )     ->   str:
														return self.image_processor.post_process(*lowerCamelCase   ,     **lowerCamelCase    )

							def    __snake_case (							self	:  Union[str, Any]   ,     *lowerCamelCase	:  str   ,     **lowerCamelCase	:  List[str]    )     ->   Tuple:
														return self.image_processor.post_process_object_detection(*lowerCamelCase   ,     **lowerCamelCase    )

							def    __snake_case (							self	:  Optional[Any]   ,     *lowerCamelCase	:  Optional[Any]   ,     **lowerCamelCase	:  Optional[Any]    )     ->   Any:
														return self.image_processor.post_process_image_guided_detection(*lowerCamelCase   ,     **lowerCamelCase    )

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

							def    __snake_case (							self	:  Union[str, Any]   ,     *lowerCamelCase	:  Tuple   ,     **lowerCamelCase	:  List[Any]    )     ->   Tuple:
														return self.tokenizer.decode(*lowerCamelCase   ,     **lowerCamelCase    )

							@property
							def    __snake_case (							self	:  Any    )     ->   Dict:
														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    __snake_case (							self	:  List[str]    )     ->   Union[str, Any]:
														warnings.warn(
														    "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."   ,     lowerCamelCase   ,     )
														return self.image_processor

