


'''simple docstring'''

from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType





class 						__SCREAMING_SNAKE_CASE					(      lowerCamelCase__ ):
     UpperCAmelCase 					=				['''image_processor''', '''tokenizer''']
     UpperCAmelCase 					=				'''BlipImageProcessor'''
     UpperCAmelCase 					=				'''AutoTokenizer'''






     def __init__(			self     ,							__UpperCamelCase     ,							__UpperCamelCase		)       ->    List[Any]:
          _a						=		False
          super().__init__(__UpperCamelCase     ,							__UpperCamelCase		)
          _a						=		self.image_processor






     def __call__(			self     ,							__UpperCamelCase = None     ,							__UpperCamelCase = None     ,							__UpperCamelCase = True     ,							__UpperCamelCase = False     ,							__UpperCamelCase = None     ,							__UpperCamelCase = None     ,							__UpperCamelCase = 0     ,							__UpperCamelCase = None     ,							__UpperCamelCase = None     ,							__UpperCamelCase = False     ,							__UpperCamelCase = False     ,							__UpperCamelCase = False     ,							__UpperCamelCase = False     ,							__UpperCamelCase = False     ,							__UpperCamelCase = True     ,							__UpperCamelCase = None     ,							**__UpperCamelCase     ,							)       ->    BatchEncoding:
          if images is None and text is None:
               raise ValueError("You have to specify either images or text."		)

          # Get only text
          if images is None:
               _a						=		self.tokenizer
               _a						=		self.tokenizer(
                   text=__UpperCamelCase     ,							add_special_tokens=__UpperCamelCase     ,							padding=__UpperCamelCase     ,							truncation=__UpperCamelCase     ,							max_length=__UpperCamelCase     ,							stride=__UpperCamelCase     ,							pad_to_multiple_of=__UpperCamelCase     ,							return_attention_mask=__UpperCamelCase     ,							return_overflowing_tokens=__UpperCamelCase     ,							return_special_tokens_mask=__UpperCamelCase     ,							return_offsets_mapping=__UpperCamelCase     ,							return_token_type_ids=__UpperCamelCase     ,							return_length=__UpperCamelCase     ,							verbose=__UpperCamelCase     ,							return_tensors=__UpperCamelCase     ,							**__UpperCamelCase     ,							)
               return text_encoding

          # add pixel_values
          _a						=		self.image_processor(__UpperCamelCase     ,							return_tensors=__UpperCamelCase		)

          if text is not None:
               _a						=		self.tokenizer(
                   text=__UpperCamelCase     ,							add_special_tokens=__UpperCamelCase     ,							padding=__UpperCamelCase     ,							truncation=__UpperCamelCase     ,							max_length=__UpperCamelCase     ,							stride=__UpperCamelCase     ,							pad_to_multiple_of=__UpperCamelCase     ,							return_attention_mask=__UpperCamelCase     ,							return_overflowing_tokens=__UpperCamelCase     ,							return_special_tokens_mask=__UpperCamelCase     ,							return_offsets_mapping=__UpperCamelCase     ,							return_token_type_ids=__UpperCamelCase     ,							return_length=__UpperCamelCase     ,							verbose=__UpperCamelCase     ,							return_tensors=__UpperCamelCase     ,							**__UpperCamelCase     ,							)
          else:
               _a						=		None

          if text_encoding is not None:
               encoding_image_processor.update(__UpperCamelCase		)

          return encoding_image_processor






     def  a_					(			self     ,							*__UpperCamelCase     ,							**__UpperCamelCase		)       ->    int:
          return self.tokenizer.batch_decode(*__UpperCamelCase     ,							**__UpperCamelCase		)






     def  a_					(			self     ,							*__UpperCamelCase     ,							**__UpperCamelCase		)       ->    Tuple:
          return self.tokenizer.decode(*__UpperCamelCase     ,							**__UpperCamelCase		)






     @property
     # Copied from transformers.models.blip.processing_blip.BlipProcessor.model_input_names
     def  a_					(			self		)       ->    str:
          _a						=		self.tokenizer.model_input_names
          _a						=		self.image_processor.model_input_names
          return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names		)		)





'''simple docstring'''

import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin





class 						__SCREAMING_SNAKE_CASE					(      unittest.TestCase ,			lowerCamelCase__ ):






     def  a_					(			self		)       ->    Tuple:
          _a						=		load_tool("text-classification"		)
          self.tool.setup()
          _a						=		load_tool("text-classification"     ,							remote=__UpperCamelCase		)






     def  a_					(			self		)       ->    Optional[int]:
          _a						=		self.tool("That's quite cool"     ,							["positive", "negative"]		)
          self.assertEqual(__UpperCamelCase     ,							"positive"		)






     def  a_					(			self		)       ->    Union[str, Any]:
          _a						=		self.remote_tool("That's quite cool"     ,							["positive", "negative"]		)
          self.assertEqual(__UpperCamelCase     ,							"positive"		)






     def  a_					(			self		)       ->    Optional[int]:
          _a						=		self.tool(text="That's quite cool"     ,							labels=["positive", "negative"]		)
          self.assertEqual(__UpperCamelCase     ,							"positive"		)






     def  a_					(			self		)       ->    str:
          _a						=		self.remote_tool(text="That's quite cool"     ,							labels=["positive", "negative"]		)
          self.assertEqual(__UpperCamelCase     ,							"positive"		)

