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				(  __snake_case  ):
      UpperCamelCase								=       ['''image_processor''', '''tokenizer''']
      UpperCamelCase								=       '''OwlViTImageProcessor'''
      UpperCamelCase								=       ('''CLIPTokenizer''', '''CLIPTokenizerFast''')





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






         """simple docstring"""







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






         """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							=     [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						:					Dict					,       *__lowerCamelCase						:					Tuple					,       **__lowerCamelCase						:					Any       )    ->   str:






         """simple docstring"""







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





      def        _lowercase				(		self						:					List[Any]					,       *__lowerCamelCase						:					List[str]					,       **__lowerCamelCase						:					str       )    ->   Dict:






         """simple docstring"""







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





      def        _lowercase				(		self						:					int					,       *__lowerCamelCase						:					List[str]					,       **__lowerCamelCase						:					List[str]       )    ->   Optional[Any]:






         """simple docstring"""







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





      def        _lowercase				(		self						:					Optional[Any]					,       *__lowerCamelCase						:					Optional[Any]					,       **__lowerCamelCase						:					Optional[Any]       )    ->   Optional[int]:






         """simple docstring"""







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





      def        _lowercase				(		self						:					Optional[Any]					,       *__lowerCamelCase						:					Tuple					,       **__lowerCamelCase						:					str       )    ->   Optional[Any]:






         """simple docstring"""







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





      @property
      def        _lowercase				(		self						:					Optional[Any]       )    ->   str:






         """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        _lowercase				(		self						:					str       )    ->   Optional[Any]:






         """simple docstring"""







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







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available


__a     =			{"""tokenization_herbert""": ["""HerbertTokenizer"""]}

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __a     =			["""HerbertTokenizerFast"""]


if TYPE_CHECKING:
 from .tokenization_herbert import HerbertTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_herbert_fast import HerbertTokenizerFast

else:
 import sys

 __a     =			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



