





'''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    ( __SCREAMING_SNAKE_CASE  ):







 '''simple docstring'''

 a      :			List[Any]     =    ["image_processor", "tokenizer"]
 a      :			Union[str, Any]     =    "OwlViTImageProcessor"
 a      :			Tuple     =    ("CLIPTokenizer", "CLIPTokenizerFast")


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







    '''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.'''       ,__UpperCAmelCase       ,)
       __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__(__UpperCAmelCase       ,__UpperCAmelCase	)


 def __call__(self       ,_lowerCamelCase=None       ,_lowerCamelCase=None       ,_lowerCamelCase=None       ,_lowerCamelCase="max_length"       ,_lowerCamelCase="np"       ,**_lowerCamelCase	)							->							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(__UpperCAmelCase       ,__UpperCAmelCase	) or (isinstance(__UpperCAmelCase       ,__UpperCAmelCase	) and not isinstance(text[0]       ,__UpperCAmelCase	)):
          __lowercase			  =							[self.tokenizer(__UpperCAmelCase       ,padding=__UpperCAmelCase       ,return_tensors=__UpperCAmelCase       ,**__UpperCAmelCase	)]

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

          # Maximum number of queries across batch
          __lowercase			  =							max([len(__UpperCAmelCase	) for t in text]	)

          # Pad all batch samples to max number of text queries
          for t in text:
             if len(__UpperCAmelCase	) != max_num_queries:
                __lowercase			  =							t + [""" """] * (max_num_queries - len(__UpperCAmelCase	))

             __lowercase			  =							self.tokenizer(__UpperCAmelCase       ,padding=__UpperCAmelCase       ,return_tensors=__UpperCAmelCase       ,**__UpperCAmelCase	)
             encodings.append(__UpperCAmelCase	)
       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(
           __UpperCAmelCase       ,return_tensors=__UpperCAmelCase       ,**__UpperCAmelCase	).pixel_values
       __lowercase			  =							query_pixel_values

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

    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(**__UpperCAmelCase	)       ,tensor_type=__UpperCAmelCase	)


 def   _UpperCAmelCase       (self       ,*_lowerCamelCase       ,**_lowerCamelCase	)							->							List[str]:







    '''simple docstring'''





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


 def   _UpperCAmelCase       (self       ,*_lowerCamelCase       ,**_lowerCamelCase	)							->							Tuple:







    '''simple docstring'''





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


 def   _UpperCAmelCase       (self       ,*_lowerCamelCase       ,**_lowerCamelCase	)							->							Tuple:







    '''simple docstring'''





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


 def   _UpperCAmelCase       (self       ,*_lowerCamelCase       ,**_lowerCamelCase	)							->							Optional[Any]:







    '''simple docstring'''





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


 def   _UpperCAmelCase       (self       ,*_lowerCamelCase       ,**_lowerCamelCase	)							->							Dict:







    '''simple docstring'''





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


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







    '''simple docstring'''





    warnings.warn(
        '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'''       ,__UpperCAmelCase       ,)
    return self.image_processor_class


 @property
 def   _UpperCAmelCase       (self	)							->							int:







    '''simple docstring'''





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












'''simple docstring'''



from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available






@dataclass
class 							__lowercase    ( lowerCAmelCase__  ):







	'''simple docstring'''

	a      :			Union[List[PIL.Image.Image], np.ndarray]
	a      :			Optional[List[bool]]


if is_transformers_available() and is_torch_available():
	from .pipeline_semantic_stable_diffusion import SemanticStableDiffusionPipeline





