


'''simple docstring'''


import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
from .feature_extraction_wavaveca import WavaVecaFeatureExtractor
from .tokenization_wavaveca import WavaVecaCTCTokenizer



class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							"""Wav2Vec2FeatureExtractor"""
  a_  					=							"""AutoTokenizer"""






  def __init__(							self :       str	,_a :       str	,_a :       Any ):

        '''simple docstring'''




        super().__init__(_a	,_a )
        A_						:  List[str]          =				self.feature_extractor
        A_						:  Dict          =				False






  @classmethod
  def        _a							(							cls :       Any	,_a :       List[str]	,**_a :       Optional[int] ):

        '''simple docstring'''




        try:
              return super().from_pretrained(_a	,**_a )
        except OSError:
              warnings.warn(
                  f'Loading a tokenizer inside {cls.__name__} from a config that does not'
                  """ include a `tokenizer_class` attribute is deprecated and will be """
                  """removed in v5. Please add `'tokenizer_class': 'Wav2Vec2CTCTokenizer'`"""
                  """ attribute to either your `config.json` or `tokenizer_config.json` """
                  """file to suppress this warning: """	,_a	,)

              A_						:  List[str]          =				WavaVecaFeatureExtractor.from_pretrained(_a	,**_a )
              A_						:  Any          =				WavaVecaCTCTokenizer.from_pretrained(_a	,**_a )

              return cls(feature_extractor=_a	,tokenizer=_a )






  def __call__(							self :       int	,*_a :       List[Any]	,**_a :       Optional[int] ):

        '''simple docstring'''




        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.""" )
              A_						:  str          =				kwargs.pop("""raw_speech""" )
        else:
              A_						:  List[Any]          =				kwargs.pop("""audio"""	,_a )
        A_						:  Optional[Any]          =				kwargs.pop("""sampling_rate"""	,_a )
        A_						:  List[str]          =				kwargs.pop("""text"""	,_a )
        if len(_a ) > 0:
              A_						:  List[Any]          =				args[0]
              A_						:  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:
              A_						:  Union[str, Any]          =				self.feature_extractor(_a	,*_a	,sampling_rate=_a	,**_a )
        if text is not None:
              A_						:  Dict          =				self.tokenizer(_a	,**_a )

        if text is None:
              return inputs
        elif audio is None:
              return encodings
        else:
              A_						:  Dict          =				encodings["""input_ids"""]
              return inputs






  def        _a							(							self :       Optional[int]	,*_a :       Union[str, Any]	,**_a :       List[Any] ):

        '''simple docstring'''




        if self._in_target_context_manager:
              return self.current_processor.pad(*_a	,**_a )

        A_						:  Optional[int]          =				kwargs.pop("""input_features"""	,_a )
        A_						:  Union[str, Any]          =				kwargs.pop("""labels"""	,_a )
        if len(_a ) > 0:
              A_						:  int          =				args[0]
              A_						:  Tuple          =				args[1:]

        if input_features is not None:
              A_						:  List[str]          =				self.feature_extractor.pad(_a	,*_a	,**_a )
        if labels is not None:
              A_						:  Tuple          =				self.tokenizer.pad(_a	,**_a )

        if labels is None:
              return input_features
        elif input_features is None:
              return labels
        else:
              A_						:  str          =				labels["""input_ids"""]
              return input_features






  def        _a							(							self :       Optional[int]	,*_a :       Tuple	,**_a :       Dict ):

        '''simple docstring'''




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






  def        _a							(							self :       Union[str, Any]	,*_a :       List[str]	,**_a :       Optional[Any] ):

        '''simple docstring'''




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






  @contextmanager
  def        _a							(							self :       Union[str, Any] ):

        '''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.""" )
        A_						:  int          =				True
        A_						:  List[str]          =				self.tokenizer
        yield
        A_						:  Optional[int]          =				self.feature_extractor
        A_						:  Optional[Any]          =				False




'''simple docstring'''


import warnings
from typing import List, Optional, Union

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



class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							["""image_processor""", """tokenizer"""]
  a_  					=							"""ViltImageProcessor"""
  a_  					=							("""BertTokenizer""", """BertTokenizerFast""")






  def __init__(							self :       List[Any]	,_a :       Optional[Any]=None	,_a :       List[str]=None	,**_a :       Any ):

        '''simple docstring'''




        A_						:  Any          =				None
        if "feature_extractor" in kwargs:
              warnings.warn(
                  """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
                  """ instead."""	,_a	,)
              A_						:  List[str]          =				kwargs.pop("""feature_extractor""" )

        A_						:  List[Any]          =				image_processor if image_processor is not None else feature_extractor
        if image_processor is None:
              raise ValueError("""You need to specify an `image_processor`.""" )
        if tokenizer is None:
              raise ValueError("""You need to specify a `tokenizer`.""" )

        super().__init__(_a	,_a )
        A_						:  Optional[Any]          =				self.image_processor






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

        '''simple docstring'''




        A_						:  int          =				self.tokenizer(
            text=_a	,add_special_tokens=_a	,padding=_a	,truncation=_a	,max_length=_a	,stride=_a	,pad_to_multiple_of=_a	,return_token_type_ids=_a	,return_attention_mask=_a	,return_overflowing_tokens=_a	,return_special_tokens_mask=_a	,return_offsets_mapping=_a	,return_length=_a	,verbose=_a	,return_tensors=_a	,**_a	,)
        # add pixel_values + pixel_mask
        A_						:  Optional[int]          =				self.image_processor(_a	,return_tensors=_a )
        encoding.update(_a )

        return encoding






  def        _a							(							self :       List[Any]	,*_a :       Any	,**_a :       Any ):

        '''simple docstring'''




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






  def        _a							(							self :       int	,*_a :       int	,**_a :       Optional[int] ):

        '''simple docstring'''




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






  @property
  def        _a							(							self :       List[Any] ):

        '''simple docstring'''




        A_						:  Optional[int]          =				self.tokenizer.model_input_names
        A_						:  str          =				self.image_processor.model_input_names
        return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names ) )






  @property
  def        _a							(							self :       str ):

        '''simple docstring'''




        warnings.warn(
            """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""	,_a	,)
        return self.image_processor_class






  @property
  def        _a							(							self :       int ):

        '''simple docstring'''




        warnings.warn(
            """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""	,_a	,)
        return self.image_processor
