






"""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      _lowercase (     lowerCAmelCase ):
      _a   :     Dict								=   ['''image_processor''', '''tokenizer''']
      _a   :     Tuple								=   '''OwlViTImageProcessor'''
      _a   :     Any								=   ('''CLIPTokenizer''', '''CLIPTokenizerFast''')


      def __init__(    self				:	List[Any]							,   a				:	str=None							,   a				:	Any=None							,   **a				:	Tuple						):





            """simple docstring"""







            __snake_case      :    Optional[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							,   )
                  __snake_case      :    Any  			=kwargs.pop('''feature_extractor'''						)

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





            """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						)):
                        __snake_case      :    List[Any]  			=[self.tokenizer(__a							,   padding=__a							,   return_tensors=__a							,   **__a						)]

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

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

                              __snake_case      :    Union[str, Any]  			=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":
                        __snake_case      :    int  			=np.concatenate([encoding['''input_ids'''] for encoding in encodings]							,   axis=0						)
                        __snake_case      :    Optional[Any]  			=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      :    str  			=jnp.concatenate([encoding['''input_ids'''] for encoding in encodings]							,   axis=0						)
                        __snake_case      :    str  			=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      :    Optional[Any]  			=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      :    Optional[Any]  			=tf.stack([encoding['''input_ids'''] for encoding in encodings]							,   axis=0						)
                        __snake_case      :    Any  			=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      :    List[str]  			=input_ids
                  __snake_case      :    int  			=attention_mask

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

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

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





            """simple docstring"""







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


      def _UpperCamelCase						(    self				:	Any							,   *a				:	List[str]							,   **a				:	Any						):





            """simple docstring"""







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


      def _UpperCamelCase						(    self				:	List[Any]							,   *a				:	Any							,   **a				:	Dict						):





            """simple docstring"""







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


      def _UpperCamelCase						(    self				:	Union[str, Any]							,   *a				:	Optional[Any]							,   **a				:	Optional[int]						):





            """simple docstring"""







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


      def _UpperCamelCase						(    self				:	int							,   *a				:	str							,   **a				:	Tuple						):





            """simple docstring"""







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


      @property
      def _UpperCamelCase						(    self				:	List[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 _UpperCamelCase						(    self				:	Any						):





            """simple docstring"""







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










"""simple docstring"""





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tokenizers_available,
    is_torch_available,
)


UpperCamelCase_	:				Any										= {"""configuration_reformer""": ["""REFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP""", """ReformerConfig"""]}

try:
    if not is_sentencepiece_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    UpperCamelCase_	:				List[str]										= ["""ReformerTokenizer"""]

try:
    if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    UpperCamelCase_	:				List[str]										= ["""ReformerTokenizerFast"""]

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    UpperCamelCase_	:				Optional[int]										= [
        """REFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
        """ReformerAttention""",
        """ReformerForMaskedLM""",
        """ReformerForQuestionAnswering""",
        """ReformerForSequenceClassification""",
        """ReformerLayer""",
        """ReformerModel""",
        """ReformerModelWithLMHead""",
        """ReformerPreTrainedModel""",
    ]


if TYPE_CHECKING:
    from .configuration_reformer import REFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, ReformerConfig

    try:
        if not is_sentencepiece_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_reformer import ReformerTokenizer

    try:
        if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_reformer_fast import ReformerTokenizerFast

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_reformer import (
            REFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
            ReformerAttention,
            ReformerForMaskedLM,
            ReformerForQuestionAnswering,
            ReformerForSequenceClassification,
            ReformerLayer,
            ReformerModel,
            ReformerModelWithLMHead,
            ReformerPreTrainedModel,
        )

else:
    import sys

    UpperCamelCase_	:				Tuple										= _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


