


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    UpperCAmelCase__	( A_		):



    """simple docstring"""






    UpperCAmelCase__						:		Tuple              =  ["image_processor", "tokenizer"]
    UpperCAmelCase__						:		List[Any]              =  "BlipImageProcessor"
    UpperCAmelCase__						:		Tuple              =  "AutoTokenizer"






    def __init__(      self ,       A_ ,       A_   )  ->	int:
         __UpperCamelCase   							=False
         super().__init__(A_ ,       A_   )
         __UpperCamelCase   							=self.image_processor






    def __call__(      self ,       A_ = None ,       A_ = None ,       A_ = True ,       A_ = False ,       A_ = None ,       A_ = None ,       A_ = 0 ,       A_ = None ,       A_ = None ,       A_ = False ,       A_ = False ,       A_ = False ,       A_ = False ,       A_ = False ,       A_ = True ,       A_ = None ,       **A_ ,       )  ->	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:
              __UpperCamelCase   							=self.tokenizer
              __UpperCamelCase   							=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   							=self.image_processor(A_ ,       return_tensors=A_   )

         if text is not None:
              __UpperCamelCase   							=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   							=None

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

         return encoding_image_processor






    def _a (      self ,       *A_ ,       **A_   )  ->	List[str]:
         return self.tokenizer.batch_decode(*A_ ,       **A_   )






    def _a (      self ,       *A_ ,       **A_   )  ->	Union[str, Any]:
         return self.tokenizer.decode(*A_ ,       **A_   )






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









import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin






class    UpperCAmelCase__	( A_		):



    """simple docstring"""






    UpperCAmelCase__						:		Optional[int]              =  "MCTCTFeatureExtractor"
    UpperCAmelCase__						:		str              =  "AutoTokenizer"






    def __init__(      self ,       A_ ,       A_   )  ->	Dict:
         super().__init__(A_ ,       A_   )
         __UpperCamelCase   							=self.feature_extractor
         __UpperCamelCase   							=False






    def __call__(      self ,       *A_ ,       **A_   )  ->	Optional[Any]:
         # For backward compatibility
         if self._in_target_context_manager:
              return self.current_processor(*A_ ,       **A_   )

         if "raw_speech" in kwargs:
              warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'   )
              __UpperCamelCase   							=kwargs.pop('raw_speech'   )
         else:
              __UpperCamelCase   							=kwargs.pop('audio' ,       A_   )
         __UpperCamelCase   							=kwargs.pop('sampling_rate' ,       A_   )
         __UpperCamelCase   							=kwargs.pop('text' ,       A_   )
         if len(A_   ) > 0:
              __UpperCamelCase   							=args[0]
              __UpperCamelCase   							=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:
              __UpperCamelCase   							=self.feature_extractor(A_ ,       *A_ ,       sampling_rate=A_ ,       **A_   )
         if text is not None:
              __UpperCamelCase   							=self.tokenizer(A_ ,       **A_   )

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






    def _a (      self ,       *A_ ,       **A_   )  ->	str:
         return self.tokenizer.batch_decode(*A_ ,       **A_   )






    def _a (      self ,       *A_ ,       **A_   )  ->	List[Any]:
         # For backward compatibility
         if self._in_target_context_manager:
              return self.current_processor.pad(*A_ ,       **A_   )

         __UpperCamelCase   							=kwargs.pop('input_features' ,       A_   )
         __UpperCamelCase   							=kwargs.pop('labels' ,       A_   )
         if len(A_   ) > 0:
              __UpperCamelCase   							=args[0]
              __UpperCamelCase   							=args[1:]

         if input_features is not None:
              __UpperCamelCase   							=self.feature_extractor.pad(A_ ,       *A_ ,       **A_   )
         if labels is not None:
              __UpperCamelCase   							=self.tokenizer.pad(A_ ,       **A_   )

         if labels is None:
              return input_features
         elif input_features is None:
              return labels
         else:
              __UpperCamelCase   							=labels['input_ids']
              return input_features






    def _a (      self ,       *A_ ,       **A_   )  ->	Optional[int]:
         return self.tokenizer.decode(*A_ ,       **A_   )






    @contextmanager
    def _a (      self   )  ->	str:
         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.'   )
         __UpperCamelCase   							=True
         __UpperCamelCase   							=self.tokenizer
         yield
         __UpperCamelCase   							=self.feature_extractor
         __UpperCamelCase   							=False





