


import warnings
from contextlib import contextmanager

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

class       __magic_name__	(     __lowerCAmelCase):
     A:		Optional[int]			=      "Wav2Vec2FeatureExtractor"
     A:		Dict			=      "AutoTokenizer"


     def __init__(      self							:     Union[str, Any]							,	lowerCamelCase__							:     Optional[Any]							,	lowerCamelCase__							:     Tuple			)  ->      int:





      '''simple docstring'''






      super().__init__(lowerCamelCase__							,	lowerCamelCase__			)
      UpperCamelCase__					:    Optional[Any]          =   self.feature_extractor
      UpperCamelCase__					:    Optional[int]          =   False


     @classmethod
     def      UpperCAmelCase__	(      cls							:     Optional[Any]							,	lowerCamelCase__							:     int							,	**lowerCamelCase__							:     Union[str, Any]			)  ->      Union[str, Any]:





      '''simple docstring'''






      try:
       return super().from_pretrained(lowerCamelCase__							,	**lowerCamelCase__			)
      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: '''							,	lowerCamelCase__							,	)

       UpperCamelCase__					:    Optional[Any]          =   WavaVecaFeatureExtractor.from_pretrained(lowerCamelCase__							,	**lowerCamelCase__			)
       UpperCamelCase__					:    List[Any]          =   WavaVecaCTCTokenizer.from_pretrained(lowerCamelCase__							,	**lowerCamelCase__			)

       return cls(feature_extractor=lowerCamelCase__							,	tokenizer=lowerCamelCase__			)


     def __call__(      self							:     Any							,	*lowerCamelCase__							:     Optional[int]							,	**lowerCamelCase__							:     Dict			)  ->      Any:





      '''simple docstring'''






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

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

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


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





      '''simple docstring'''






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

      UpperCamelCase__					:    Optional[Any]          =   kwargs.pop('''input_features'''							,	lowerCamelCase__			)
      UpperCamelCase__					:    List[Any]          =   kwargs.pop('''labels'''							,	lowerCamelCase__			)
      if len(lowerCamelCase__			) > 0:
       UpperCamelCase__					:    str          =   args[0]
       UpperCamelCase__					:    List[str]          =   args[1:]

      if input_features is not None:
       UpperCamelCase__					:    Any          =   self.feature_extractor.pad(lowerCamelCase__							,	*lowerCamelCase__							,	**lowerCamelCase__			)
      if labels is not None:
       UpperCamelCase__					:    Tuple          =   self.tokenizer.pad(lowerCamelCase__							,	**lowerCamelCase__			)

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


     def      UpperCAmelCase__	(      self							:     Optional[Any]							,	*lowerCamelCase__							:     Tuple							,	**lowerCamelCase__							:     int			)  ->      List[str]:





      '''simple docstring'''






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


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





      '''simple docstring'''






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


     @contextmanager
     def      UpperCAmelCase__	(      self							:     Optional[int]			)  ->      Optional[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.'''			)
      UpperCamelCase__					:    int          =   True
      UpperCamelCase__					:    str          =   self.tokenizer
      yield
      UpperCamelCase__					:    str          =   self.feature_extractor
      UpperCamelCase__					:    Union[str, Any]          =   False






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


__UpperCamelCase       :       Optional[int]						       =				{
    "configuration_rag": ["RagConfig"],
    "retrieval_rag": ["RagRetriever"],
    "tokenization_rag": ["RagTokenizer"],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase       :       Optional[int]						       =				[
           "RagModel",
           "RagPreTrainedModel",
           "RagSequenceForGeneration",
           "RagTokenForGeneration",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase       :       List[Any]						       =				[
           "TFRagModel",
           "TFRagPreTrainedModel",
           "TFRagSequenceForGeneration",
           "TFRagTokenForGeneration",
       ]


if TYPE_CHECKING:
       from .configuration_rag import RagConfig
       from .retrieval_rag import RagRetriever
       from .tokenization_rag import RagTokenizer

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_rag import RagModel, RagPreTrainedModel, RagSequenceForGeneration, RagTokenForGeneration

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_rag import (
                  TFRagModel,
                  TFRagPreTrainedModel,
                  TFRagSequenceForGeneration,
                  TFRagTokenForGeneration,
              )

else:
       import sys

       __UpperCamelCase       :       List[Any]						       =				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


