




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

      UpperCamelCase_	:       int       	=		['image_processor', 'tokenizer']
      UpperCamelCase_	:       Dict       	=		'OwlViTImageProcessor'
      UpperCamelCase_	:       List[str]       	=		('CLIPTokenizer', 'CLIPTokenizerFast')






      def __init__( self :     str				,							lowerCamelCase__ :     Any=None				,							lowerCamelCase__ :     List[Any]=None				,							**lowerCamelCase__ :     Union[str, Any]				)    ->						Tuple:
             """simple docstring"""


             __lowercase      =    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__				,							)
                    __lowercase      =    kwargs.pop('''feature_extractor'''				)

             __lowercase      =    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 :     List[Any]				,							lowerCamelCase__ :     List[str]=None				,							lowerCamelCase__ :     int=None				,							lowerCamelCase__ :     Any=None				,							lowerCamelCase__ :     str="max_length"				,							lowerCamelCase__ :     Union[str, Any]="np"				,							**lowerCamelCase__ :     Dict				)    ->						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__				)):
                           __lowercase      =    [self.tokenizer(lowerCamelCase__				,							padding=lowerCamelCase__				,							return_tensors=lowerCamelCase__				,							**lowerCamelCase__				)]

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

                           # Maximum number of queries across batch
                           __lowercase      =    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:
                                         __lowercase      =    t + [''' '''] * (max_num_queries - len(lowerCamelCase__				))

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

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

                           __lowercase      =    torch.cat([encoding['''input_ids'''] for encoding in encodings]				,							dim=0				)
                           __lowercase      =    torch.cat([encoding['''attention_mask'''] for encoding in encodings]				,							dim=0				)

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

                           __lowercase      =    tf.stack([encoding['''input_ids'''] for encoding in encodings]				,							axis=0				)
                           __lowercase      =    tf.stack([encoding['''attention_mask'''] for encoding in encodings]				,							axis=0				)

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

                    __lowercase      =    BatchEncoding()
                    __lowercase      =    input_ids
                    __lowercase      =    attention_mask

             if query_images is not None:
                    __lowercase      =    BatchEncoding()
                    __lowercase      =    self.image_processor(
                        lowerCamelCase__				,							return_tensors=lowerCamelCase__				,							**lowerCamelCase__				).pixel_values
                    __lowercase      =    query_pixel_values

             if images is not None:
                    __lowercase      =    self.image_processor(lowerCamelCase__				,							return_tensors=lowerCamelCase__				,							**lowerCamelCase__				)

             if text is not None and images is not None:
                    __lowercase      =    image_features.pixel_values
                    return encoding
             elif query_images is not None and images is not None:
                    __lowercase      =    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     UpperCAmelCase_      ( self :     int				,							*lowerCamelCase__ :     str				,							**lowerCamelCase__ :     Optional[int]				)    ->						Tuple:
             """simple docstring"""


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






      def     UpperCAmelCase_      ( self :     Optional[int]				,							*lowerCamelCase__ :     Tuple				,							**lowerCamelCase__ :     Tuple				)    ->						Union[str, Any]:
             """simple docstring"""


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






      def     UpperCAmelCase_      ( self :     List[str]				,							*lowerCamelCase__ :     List[str]				,							**lowerCamelCase__ :     Optional[Any]				)    ->						List[Any]:
             """simple docstring"""


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






      def     UpperCAmelCase_      ( self :     Optional[int]				,							*lowerCamelCase__ :     str				,							**lowerCamelCase__ :     Union[str, Any]				)    ->						Optional[Any]:
             """simple docstring"""


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






      def     UpperCAmelCase_      ( self :     str				,							*lowerCamelCase__ :     Optional[int]				,							**lowerCamelCase__ :     Union[str, Any]				)    ->						List[str]:
             """simple docstring"""


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






      @property
      def     UpperCAmelCase_      ( self :     Tuple				)    ->						List[str]:
             """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     UpperCAmelCase_      ( self :     str				)    ->						Any:
             """simple docstring"""


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












import argparse


UpperCAmelCase__				     = "docs/source/_static/js/custom.js"







def 		_A(       UpperCamelCase__							:			Optional[int]				)    -> Optional[int]:
							'''simple docstring'''


							with open(UpperCamelCase__				,       encoding='''utf-8'''				,       newline='''\n'''				) as f:
														__lowercase      =    f.readlines()
							__lowercase      =    0

							# First let's put the right version
							while not lines[index].startswith('''const stableVersion ='''				):
														index += 1
							__lowercase      =    F'const stableVersion = "v{version}"\n'

							# Then update the dictionary
							while not lines[index].startswith('''const versionMapping = {'''				):
														index += 1

							# We go until the end
							while not lines[index].startswith('''}'''				):
														index += 1
							# We add the new version at the end
							lines[index - 1] += F'    "v{version}": "v{version}",\n'

							with open(UpperCamelCase__				,       '''w'''				,       encoding='''utf-8'''				,       newline='''\n'''				) as f:
														f.writelines(UpperCamelCase__				)


if __name__ == "__main__":
			UpperCAmelCase__				     = argparse.ArgumentParser()
			parser.add_argument("--version", help="Release version.")
			UpperCAmelCase__				     = parser.parse_args()
			update_custom_js(args.version)






