





'''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					(						__UpperCAmelCase  ):
					_SCREAMING_SNAKE_CASE							   =    ["image_processor", "tokenizer"]
					_SCREAMING_SNAKE_CASE							   =    "BlipImageProcessor"
					_SCREAMING_SNAKE_CASE							   =    ("BertTokenizer", "BertTokenizerFast")


					def __init__(					self	:  Dict       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  Tuple       ):





											'''simple docstring'''





											_snake_case:   Any  					=		False
											super().__init__(__snake_case       ,     __snake_case       )
											_snake_case:   int  					=		self.image_processor


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





											'''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:
																	_snake_case:   List[Any]  					=		self.tokenizer
																	_snake_case:   Any  					=		self.tokenizer(
																	    text=__snake_case       ,     add_special_tokens=__snake_case       ,     padding=__snake_case       ,     truncation=__snake_case       ,     max_length=__snake_case       ,     stride=__snake_case       ,     pad_to_multiple_of=__snake_case       ,     return_attention_mask=__snake_case       ,     return_overflowing_tokens=__snake_case       ,     return_special_tokens_mask=__snake_case       ,     return_offsets_mapping=__snake_case       ,     return_token_type_ids=__snake_case       ,     return_length=__snake_case       ,     verbose=__snake_case       ,     return_tensors=__snake_case       ,     **__snake_case       ,     )
																	return text_encoding

											# add pixel_values
											_snake_case:   Any  					=		self.image_processor(__snake_case       ,     return_tensors=__snake_case       )

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

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

											return encoding_image_processor


					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ,     *__snake_case	:  Dict       ,     **__snake_case	:  List[Any]       ):





											'''simple docstring'''





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


					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ,     *__snake_case	:  str       ,     **__snake_case	:  Optional[Any]       ):





											'''simple docstring'''





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




					@property
					def    SCREAMING_SNAKE_CASE_		(					self	:  int       ):





											'''simple docstring'''





											_snake_case:   int  					=		self.tokenizer.model_input_names
											_snake_case:   Tuple  					=		self.image_processor.model_input_names
											return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names       )       )












'''simple docstring'''






import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin







class 			lowerCamelCase					(						__UpperCAmelCase  ):
					_SCREAMING_SNAKE_CASE							   =    "Speech2TextFeatureExtractor"
					_SCREAMING_SNAKE_CASE							   =    "Speech2TextTokenizer"


					def __init__(					self	:  List[str]       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  List[str]       ):





											'''simple docstring'''





											super().__init__(__snake_case       ,     __snake_case       )
											_snake_case:   Optional[int]  					=		self.feature_extractor
											_snake_case:   Dict  					=		False


					def __call__(					self	:  Optional[int]       ,     *__snake_case	:  Optional[Any]       ,     **__snake_case	:  Union[str, Any]       ):





											'''simple docstring'''





											if self._in_target_context_manager:
																	return self.current_processor(*__snake_case       ,     **__snake_case       )

											if "raw_speech" in kwargs:
																	warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'       )
																	_snake_case:   int  					=		kwargs.pop('raw_speech'       )
											else:
																	_snake_case:   Tuple  					=		kwargs.pop('audio'       ,     __snake_case       )
											_snake_case:   Optional[Any]  					=		kwargs.pop('sampling_rate'       ,     __snake_case       )
											_snake_case:   Optional[Any]  					=		kwargs.pop('text'       ,     __snake_case       )
											if len(__snake_case       ) > 0:
																	_snake_case:   Optional[Any]  					=		args[0]
																	_snake_case:   Union[str, Any]  					=		args[1:]

											if audio is None and text is None:
																	raise ValueError('You need to specify either an `audio` or `text` input to process.'       )

											if audio is not None:
																	_snake_case:   List[Any]  					=		self.feature_extractor(__snake_case       ,     *__snake_case       ,     sampling_rate=__snake_case       ,     **__snake_case       )
											if text is not None:
																	_snake_case:   Tuple  					=		self.tokenizer(__snake_case       ,     **__snake_case       )

											if text is None:
																	return inputs
											elif audio is None:
																	return encodings
											else:
																	_snake_case:   List[Any]  					=		encodings['input_ids']
																	return inputs


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ,     *__snake_case	:  Optional[int]       ,     **__snake_case	:  str       ):





											'''simple docstring'''





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


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ,     *__snake_case	:  List[str]       ,     **__snake_case	:  Tuple       ):





											'''simple docstring'''





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




					@contextmanager
					def    SCREAMING_SNAKE_CASE_		(					self	:  List[str]       ):





											'''simple docstring'''





											warnings.warn(
											    '`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your '
											    'labels by using the argument `text` of the regular `__call__` method (either in the same call as '
											    'your audio inputs, or in a separate call.'       )
											_snake_case:   Any  					=		True
											_snake_case:   str  					=		self.tokenizer
											yield
											_snake_case:   Union[str, Any]  					=		self.feature_extractor
											_snake_case:   Tuple  					=		False





