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




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


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



"""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

