





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 					__a      (_lowercase     ):
							__a					:   int									=       ['''image_processor''', '''tokenizer''']
							__a					:   Optional[int]									=       '''BlipImageProcessor'''
							__a					:   Any									=       ('''BertTokenizer''', '''BertTokenizerFast''')

							def __init__(							self							:     str       ,     __magic_name__							:     str       ,     __magic_name__							:     Any   )					->       List[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Optional[int]     						=  False
													super().__init__(A_       ,     A_   )
													UpperCAmelCase_			:      Optional[int]     						=  self.image_processor

							def __call__(							self							:     Dict       ,     __magic_name__							:     ImageInput = None       ,     __magic_name__							:     Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None       ,     __magic_name__							:     bool = True       ,     __magic_name__							:     Union[bool, str, PaddingStrategy] = False       ,     __magic_name__							:     Union[bool, str, TruncationStrategy] = None       ,     __magic_name__							:     Optional[int] = None       ,     __magic_name__							:     int = 0       ,     __magic_name__							:     Optional[int] = None       ,     __magic_name__							:     Optional[bool] = None       ,     __magic_name__							:     bool = False       ,     __magic_name__							:     bool = False       ,     __magic_name__							:     bool = False       ,     __magic_name__							:     bool = False       ,     __magic_name__							:     bool = False       ,     __magic_name__							:     bool = True       ,     __magic_name__							:     Optional[Union[str, TensorType]] = None       ,     **__magic_name__							:     Tuple       ,     )					->       BatchEncoding:







													"""simple docstring"""
													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:
																			UpperCAmelCase_			:      Union[str, Any]     						=  self.tokenizer
																			UpperCAmelCase_			:      Union[str, Any]     						=  self.tokenizer(
																			    text=A_       ,     add_special_tokens=A_       ,     padding=A_       ,     truncation=A_       ,     max_length=A_       ,     stride=A_       ,     pad_to_multiple_of=A_       ,     return_attention_mask=A_       ,     return_overflowing_tokens=A_       ,     return_special_tokens_mask=A_       ,     return_offsets_mapping=A_       ,     return_token_type_ids=A_       ,     return_length=A_       ,     verbose=A_       ,     return_tensors=A_       ,     **A_       ,     )
																			return text_encoding

													# add pixel_values
													UpperCAmelCase_			:      List[Any]     						=  self.image_processor(A_       ,     return_tensors=A_   )

													if text is not None:
																			UpperCAmelCase_			:      List[Any]     						=  self.tokenizer(
																			    text=A_       ,     add_special_tokens=A_       ,     padding=A_       ,     truncation=A_       ,     max_length=A_       ,     stride=A_       ,     pad_to_multiple_of=A_       ,     return_attention_mask=A_       ,     return_overflowing_tokens=A_       ,     return_special_tokens_mask=A_       ,     return_offsets_mapping=A_       ,     return_token_type_ids=A_       ,     return_length=A_       ,     verbose=A_       ,     return_tensors=A_       ,     **A_       ,     )
													else:
																			UpperCAmelCase_			:      Tuple     						=  None

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

													return encoding_image_processor

							def     UpperCAmelCase__	(							self							:     int       ,     *__magic_name__							:     Any       ,     **__magic_name__							:     Optional[int]   )					->       Union[str, Any]:







													"""simple docstring"""
													return self.tokenizer.batch_decode(*A_       ,     **A_   )

							def     UpperCAmelCase__	(							self							:     List[str]       ,     *__magic_name__							:     str       ,     **__magic_name__							:     Any   )					->       Any:







													"""simple docstring"""
													return self.tokenizer.decode(*A_       ,     **A_   )



							@property
							def     UpperCAmelCase__	(							self							:     Union[str, Any]   )					->       Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      List[str]     						=  self.tokenizer.model_input_names
													UpperCAmelCase_			:      int     						=  self.image_processor.model_input_names
													return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names   )   )












'''simple docstring'''







import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
					import torch

					from transformers.generation import DisjunctiveConstraint


@require_torch
class 					__a      (unittest.TestCase     ):

							def     UpperCAmelCase__	(							self							:     Optional[Any]   )					->       List[Any]:







													"""simple docstring"""
													# For consistency across different places the DisjunctiveConstraint is called,
													# dc.token_ids is a list of integers. It is also initialized only by integers.

													UpperCAmelCase_			:      List[str]     						=  [[1, 2, 4], [1, 2, 3, 4]]
													UpperCAmelCase_			:      List[str]     						=  DisjunctiveConstraint(__magic_name__   )
													self.assertTrue(isinstance(dc.token_ids       ,     __magic_name__   )   )

													with self.assertRaises(__magic_name__   ):
																			DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]   )   )

													with self.assertRaises(__magic_name__   ):
																			DisjunctiveConstraint([torch.LongTensor([1, 2, 4]   ), torch.LongTensor([1, 2, 3, 4, 5]   )]   )

							def     UpperCAmelCase__	(							self							:     List[str]   )					->       Dict:







													"""simple docstring"""
													# We can't have constraints that are complete subsets of another. This leads to a preverse
													# interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
													# It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
													# fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
													# will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
													UpperCAmelCase_			:      Tuple     						=  [[1, 2], [1, 2, 3, 4]]

													with self.assertRaises(__magic_name__   ):
																			DisjunctiveConstraint(__magic_name__   )  # fails here

							def     UpperCAmelCase__	(							self							:     Optional[int]   )					->       Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Optional[int]     						=  [[1, 2, 3], [1, 2, 4]]

													UpperCAmelCase_			:      List[str]     						=  DisjunctiveConstraint(__magic_name__   )

													UpperCAmelCase_						,       UpperCAmelCase_						,       UpperCAmelCase_			:      List[Any]     						=  dc.update(1   )
													UpperCAmelCase_			:      Dict     						=  stepped is True and completed is False and reset is False
													self.assertTrue(__magic_name__   )
													self.assertTrue(not dc.completed   )
													self.assertTrue(dc.current_seq == [1]   )

													UpperCAmelCase_						,       UpperCAmelCase_						,       UpperCAmelCase_			:      str     						=  dc.update(2   )
													UpperCAmelCase_			:      Optional[Any]     						=  stepped is True and completed is False and reset is False
													self.assertTrue(__magic_name__   )
													self.assertTrue(not dc.completed   )
													self.assertTrue(dc.current_seq == [1, 2]   )

													UpperCAmelCase_						,       UpperCAmelCase_						,       UpperCAmelCase_			:      List[Any]     						=  dc.update(3   )
													UpperCAmelCase_			:      Dict     						=  stepped is True and completed is True and reset is False
													self.assertTrue(__magic_name__   )
													self.assertTrue(dc.completed   )  # Completed!
													self.assertTrue(dc.current_seq == [1, 2, 3]   )



							def     UpperCAmelCase__	(							self							:     int   )					->       Dict:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

													UpperCAmelCase_			:      Tuple     						=  DisjunctiveConstraint(__magic_name__   )

													UpperCAmelCase_						,       UpperCAmelCase_						,       UpperCAmelCase_			:      List[Any]     						=  dc.update(1   )
													self.assertTrue(not dc.completed   )
													self.assertTrue(dc.current_seq == [1]   )

													UpperCAmelCase_						,       UpperCAmelCase_						,       UpperCAmelCase_			:      Optional[int]     						=  dc.update(2   )
													self.assertTrue(not dc.completed   )
													self.assertTrue(dc.current_seq == [1, 2]   )

													UpperCAmelCase_						,       UpperCAmelCase_						,       UpperCAmelCase_			:      int     						=  dc.update(4   )
													self.assertTrue(not dc.completed   )
													self.assertTrue(dc.current_seq == [1, 2, 4]   )

													UpperCAmelCase_						,       UpperCAmelCase_						,       UpperCAmelCase_			:      int     						=  dc.update(5   )
													self.assertTrue(dc.completed   )  # Completed!
													self.assertTrue(dc.current_seq == [1, 2, 4, 5]   )

													dc.reset()

													UpperCAmelCase_						,       UpperCAmelCase_						,       UpperCAmelCase_			:      List[Any]     						=  dc.update(1   )
													self.assertTrue(not dc.completed   )
													self.assertTrue(dc.remaining() == 3   )
													self.assertTrue(dc.current_seq == [1]   )

													UpperCAmelCase_						,       UpperCAmelCase_						,       UpperCAmelCase_			:      Optional[Any]     						=  dc.update(2   )
													self.assertTrue(not dc.completed   )
													self.assertTrue(dc.remaining() == 2   )
													self.assertTrue(dc.current_seq == [1, 2]   )

													UpperCAmelCase_						,       UpperCAmelCase_						,       UpperCAmelCase_			:      Optional[int]     						=  dc.update(5   )
													self.assertTrue(dc.completed   )  # Completed!
													self.assertTrue(dc.remaining() == 0   )
													self.assertTrue(dc.current_seq == [1, 2, 5]   )





