
"""simple docstring"""







from . import __version__

# Backward compatibility imports, to make sure all those objects can be found in file_utils
from .utils import (
    CLOUDFRONT_DISTRIB_PREFIX,
    CONFIG_NAME,
    DISABLE_TELEMETRY,
    DUMMY_INPUTS,
    DUMMY_MASK,
    ENV_VARS_TRUE_AND_AUTO_VALUES,
    ENV_VARS_TRUE_VALUES,
    FEATURE_EXTRACTOR_NAME,
    FLAX_WEIGHTS_NAME,
    HF_MODULES_CACHE,
    HUGGINGFACE_CO_PREFIX,
    HUGGINGFACE_CO_RESOLVE_ENDPOINT,
    MODEL_CARD_NAME,
    MULTIPLE_CHOICE_DUMMY_INPUTS,
    PYTORCH_PRETRAINED_BERT_CACHE,
    PYTORCH_TRANSFORMERS_CACHE,
    S3_BUCKET_PREFIX,
    SENTENCEPIECE_UNDERLINE,
    SPIECE_UNDERLINE,
    TF2_WEIGHTS_NAME,
    TF_WEIGHTS_NAME,
    TORCH_FX_REQUIRED_VERSION,
    TRANSFORMERS_CACHE,
    TRANSFORMERS_DYNAMIC_MODULE_NAME,
    USE_JAX,
    USE_TF,
    USE_TORCH,
    WEIGHTS_INDEX_NAME,
    WEIGHTS_NAME,
    ContextManagers,
    DummyObject,
    EntryNotFoundError,
    ExplicitEnum,
    ModelOutput,
    PaddingStrategy,
    PushToHubMixin,
    RepositoryNotFoundError,
    RevisionNotFoundError,
    TensorType,
    _LazyModule,
    add_code_sample_docstrings,
    add_end_docstrings,
    add_start_docstrings,
    add_start_docstrings_to_model_forward,
    cached_property,
    copy_func,
    default_cache_path,
    define_sagemaker_information,
    get_cached_models,
    get_file_from_repo,
    get_full_repo_name,
    get_torch_version,
    has_file,
    http_user_agent,
    is_apex_available,
    is_bsa_available,
    is_coloredlogs_available,
    is_datasets_available,
    is_detectrona_available,
    is_faiss_available,
    is_flax_available,
    is_ftfy_available,
    is_in_notebook,
    is_ipex_available,
    is_librosa_available,
    is_offline_mode,
    is_onnx_available,
    is_pandas_available,
    is_phonemizer_available,
    is_protobuf_available,
    is_psutil_available,
    is_pyanvml_available,
    is_pyctcdecode_available,
    is_pytesseract_available,
    is_pytorch_quantization_available,
    is_rjieba_available,
    is_sagemaker_dp_enabled,
    is_sagemaker_mp_enabled,
    is_scipy_available,
    is_sentencepiece_available,
    is_seqio_available,
    is_sklearn_available,
    is_soundfile_availble,
    is_spacy_available,
    is_speech_available,
    is_tensor,
    is_tensorflow_probability_available,
    is_tfaonnx_available,
    is_tf_available,
    is_timm_available,
    is_tokenizers_available,
    is_torch_available,
    is_torch_bfaa_available,
    is_torch_cuda_available,
    is_torch_fx_available,
    is_torch_fx_proxy,
    is_torch_mps_available,
    is_torch_tfaa_available,
    is_torch_tpu_available,
    is_torchaudio_available,
    is_training_run_on_sagemaker,
    is_vision_available,
    replace_return_docstrings,
    requires_backends,
    to_numpy,
    to_py_obj,
    torch_only_method,
)



"""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_						(lowerCamelCase_    ):
 """simple docstring"""




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




 def __init__(			self							:			Any  , a_							:			Any=None  , a_							:			str=None  , **a_							:			List[str]			)->       List[Any]:



      """simple docstring"""

      UpperCAmelCase_    :     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."""  , a_  , )
           UpperCAmelCase_    :     List[Any]            =	kwargs.pop("""feature_extractor"""			)

      UpperCAmelCase_    :     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__(a_  , a_			)




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



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

           elif isinstance(a_  , a_			) and isinstance(text[0]  , a_			):
                UpperCAmelCase_    :     Optional[int]            =	[]

                # Maximum number of queries across batch
                UpperCAmelCase_    :     Union[str, Any]            =	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_    :     str            =	t + [""" """] * (max_num_queries - len(a_			))

                     UpperCAmelCase_    :     Optional[int]            =	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_    :     List[Any]            =	np.concatenate([encoding["""input_ids"""] for encoding in encodings]  , axis=0			)
                UpperCAmelCase_    :     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

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

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

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

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

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

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

           UpperCAmelCase_    :     Union[str, Any]            =	BatchEncoding()
           UpperCAmelCase_    :     int            =	input_ids
           UpperCAmelCase_    :     List[str]            =	attention_mask

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

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

      if text is not None and images is not None:
           UpperCAmelCase_    :     List[Any]            =	image_features.pixel_values
           return encoding
      elif query_images is not None and images is not None:
           UpperCAmelCase_    :     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(**a_			)  , tensor_type=a_			)




 def 	a   (			self							:			Any  , *a_							:			Optional[Any]  , **a_							:			List[str]			)->       Union[str, Any]:



      """simple docstring"""

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




 def 	a   (			self							:			Tuple  , *a_							:			List[str]  , **a_							:			Dict			)->       Optional[int]:



      """simple docstring"""

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




 def 	a   (			self							:			Optional[int]  , *a_							:			Tuple  , **a_							:			Optional[int]			)->       Optional[Any]:



      """simple docstring"""

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




 def 	a   (			self							:			str  , *a_							:			Optional[int]  , **a_							:			str			)->       Optional[int]:



      """simple docstring"""

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




 def 	a   (			self							:			str  , *a_							:			List[Any]  , **a_							:			List[str]			)->       Union[str, Any]:



      """simple docstring"""

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




 @property
 def 	a   (			self							:			Tuple			)->       int:



      """simple docstring"""

      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 	a   (			self							:			Optional[Any]			)->       int:



      """simple docstring"""

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

