





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






       """simple docstring"""
       _snake_case     :					List[Any]						    =   ['image_processor', 'tokenizer']
       _snake_case     :					Optional[int]						    =   'BlipImageProcessor'
       _snake_case     :					Optional[int]						    =   'AutoTokenizer'





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

            '''simple docstring'''




            _UpperCamelCase       =	False
            super().__init__(lowerCAmelCase__	,			lowerCAmelCase__					)
            _UpperCamelCase       =	self.image_processor





       def __call__(							self       :		Any	,			lowerCAmelCase__       :		ImageInput = None	,			lowerCAmelCase__       :		Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None	,			lowerCAmelCase__       :		bool = True	,			lowerCAmelCase__       :		Union[bool, str, PaddingStrategy] = False	,			lowerCAmelCase__       :		Union[bool, str, TruncationStrategy] = None	,			lowerCAmelCase__       :		Optional[int] = None	,			lowerCAmelCase__       :		int = 0	,			lowerCAmelCase__       :		Optional[int] = None	,			lowerCAmelCase__       :		Optional[bool] = None	,			lowerCAmelCase__       :		bool = False	,			lowerCAmelCase__       :		bool = False	,			lowerCAmelCase__       :		bool = False	,			lowerCAmelCase__       :		bool = False	,			lowerCAmelCase__       :		bool = False	,			lowerCAmelCase__       :		bool = True	,			lowerCAmelCase__       :		Optional[Union[str, TensorType]] = None	,			**lowerCAmelCase__       :		int	,			)   ->					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       =	self.tokenizer
                 _UpperCamelCase       =	self.tokenizer(
                     text=lowerCAmelCase__	,			add_special_tokens=lowerCAmelCase__	,			padding=lowerCAmelCase__	,			truncation=lowerCAmelCase__	,			max_length=lowerCAmelCase__	,			stride=lowerCAmelCase__	,			pad_to_multiple_of=lowerCAmelCase__	,			return_attention_mask=lowerCAmelCase__	,			return_overflowing_tokens=lowerCAmelCase__	,			return_special_tokens_mask=lowerCAmelCase__	,			return_offsets_mapping=lowerCAmelCase__	,			return_token_type_ids=lowerCAmelCase__	,			return_length=lowerCAmelCase__	,			verbose=lowerCAmelCase__	,			return_tensors=lowerCAmelCase__	,			**lowerCAmelCase__	,			)
                 return text_encoding

            # add pixel_values
            _UpperCamelCase       =	self.image_processor(lowerCAmelCase__	,			return_tensors=lowerCAmelCase__					)

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

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

            return encoding_image_processor





       def snake_case__						(							self       :		str	,			*lowerCAmelCase__       :		List[str]	,			**lowerCAmelCase__       :		Any					)   ->					int:

            '''simple docstring'''




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





       def snake_case__						(							self       :		List[Any]	,			*lowerCAmelCase__       :		List[Any]	,			**lowerCAmelCase__       :		Dict					)   ->					Union[str, Any]:

            '''simple docstring'''




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







       @property
       # Copied from transformers.models.blip.processing_blip.BlipProcessor.model_input_names
       def snake_case__						(							self       :		str					)   ->					List[Any]:

            '''simple docstring'''




            _UpperCamelCase       =	self.tokenizer.model_input_names
            _UpperCamelCase       =	self.image_processor.model_input_names
            return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names					)					)










'''simple docstring'''

import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)
class     __lowerCAmelCase					(   unittest.TestCase			):






       """simple docstring"""





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

            '''simple docstring'''




            _UpperCamelCase       =	['''a''', '''b''', '''c''']

            # Defaults to last layer if both are None
            _UpperCamelCase   ,    _UpperCamelCase       =	get_aligned_output_features_output_indices(lowerCAmelCase__	,			lowerCAmelCase__	,			lowerCAmelCase__					)
            self.assertEqual(lowerCAmelCase__	,			['''c''']					)
            self.assertEqual(lowerCAmelCase__	,			[2]					)

            # Out indices set to match out features
            _UpperCamelCase   ,    _UpperCamelCase       =	get_aligned_output_features_output_indices(['''a''', '''c''']	,			lowerCAmelCase__	,			lowerCAmelCase__					)
            self.assertEqual(lowerCAmelCase__	,			['''a''', '''c''']					)
            self.assertEqual(lowerCAmelCase__	,			[0, 2]					)

            # Out features set to match out indices
            _UpperCamelCase   ,    _UpperCamelCase       =	get_aligned_output_features_output_indices(lowerCAmelCase__	,			[0, 2]	,			lowerCAmelCase__					)
            self.assertEqual(lowerCAmelCase__	,			['''a''', '''c''']					)
            self.assertEqual(lowerCAmelCase__	,			[0, 2]					)

            # Out features selected from negative indices
            _UpperCamelCase   ,    _UpperCamelCase       =	get_aligned_output_features_output_indices(lowerCAmelCase__	,			[-3, -1]	,			lowerCAmelCase__					)
            self.assertEqual(lowerCAmelCase__	,			['''a''', '''c''']					)
            self.assertEqual(lowerCAmelCase__	,			[-3, -1]					)





       def snake_case__						(							self       :		Any					)   ->					Union[str, Any]:

            '''simple docstring'''




            with self.assertRaises(lowerCAmelCase__					):
                 verify_out_features_out_indices(['''a''', '''b''']	,			(0, 1)	,			lowerCAmelCase__					)

            # Out features must be a list
            with self.assertRaises(lowerCAmelCase__					):
                 verify_out_features_out_indices(('''a''', '''b''')	,			(0, 1)	,			['''a''', '''b''']					)

            # Out features must be a subset of stage names
            with self.assertRaises(lowerCAmelCase__					):
                 verify_out_features_out_indices(['''a''', '''b''']	,			(0, 1)	,			['''a''']					)

            # Out indices must be a list or tuple
            with self.assertRaises(lowerCAmelCase__					):
                 verify_out_features_out_indices(lowerCAmelCase__	,			0	,			['''a''', '''b''']					)

            # Out indices must be a subset of stage names
            with self.assertRaises(lowerCAmelCase__					):
                 verify_out_features_out_indices(lowerCAmelCase__	,			(0, 1)	,			['''a''']					)

            # Out features and out indices must be the same length
            with self.assertRaises(lowerCAmelCase__					):
                 verify_out_features_out_indices(['''a''', '''b''']	,			(0,)	,			['''a''', '''b''', '''c''']					)

            # Out features should match out indices
            with self.assertRaises(lowerCAmelCase__					):
                 verify_out_features_out_indices(['''a''', '''b''']	,			(0, 2)	,			['''a''', '''b''', '''c''']					)

            # Out features and out indices should be in order
            with self.assertRaises(lowerCAmelCase__					):
                 verify_out_features_out_indices(['''b''', '''a''']	,			(0, 1)	,			['''a''', '''b''']					)

            # Check passes with valid inputs
            verify_out_features_out_indices(['''a''', '''b''', '''d''']	,			(0, 1, -1)	,			['''a''', '''b''', '''c''', '''d''']					)







       def snake_case__						(							self       :		Any					)   ->					str:

            '''simple docstring'''




            _UpperCamelCase       =	BackboneMixin()

            _UpperCamelCase       =	['''a''', '''b''', '''c''']
            _UpperCamelCase       =	['''a''', '''c''']
            _UpperCamelCase       =	[0, 2]

            # Check that the output features and indices are set correctly
            self.assertEqual(backbone.out_features	,			['''a''', '''c''']					)
            self.assertEqual(backbone.out_indices	,			[0, 2]					)

            # Check out features and indices are updated correctly
            _UpperCamelCase       =	['''a''', '''b''']
            self.assertEqual(backbone.out_features	,			['''a''', '''b''']					)
            self.assertEqual(backbone.out_indices	,			[0, 1]					)

            _UpperCamelCase       =	[-3, -1]
            self.assertEqual(backbone.out_features	,			['''a''', '''c''']					)
            self.assertEqual(backbone.out_indices	,			[-3, -1]					)



