




'''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 UpperCAmelCase							(		__UpperCAmelCase							):
    _A :			List[str]						   =       "Wav2Vec2FeatureExtractor"
    _A :			List[Any]						   =       "AutoTokenizer"



    def __init__(  self     ,			__A     ,			__A					):
     super().__init__(_lowerCamelCase     ,			_lowerCamelCase					)
     __UpperCAmelCase					=   self.feature_extractor
     __UpperCAmelCase					=   False



    @classmethod
    def 					__lowerCamelCase						(  cls     ,			__A     ,			**__A					):
     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					=   WavaVecaFeatureExtractor.from_pretrained(_lowerCamelCase     ,			**_lowerCamelCase					)
      __UpperCAmelCase					=   WavaVecaCTCTokenizer.from_pretrained(_lowerCamelCase     ,			**_lowerCamelCase					)

      return cls(feature_extractor=_lowerCamelCase     ,			tokenizer=_lowerCamelCase					)



    def __call__(  self     ,			*__A     ,			**__A					):
     # For backward compatibility
     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					=   kwargs.pop('raw_speech'					)
     else:
      __UpperCAmelCase					=   kwargs.pop('audio'     ,			_lowerCamelCase					)
     __UpperCAmelCase					=   kwargs.pop('sampling_rate'     ,			_lowerCamelCase					)
     __UpperCAmelCase					=   kwargs.pop('text'     ,			_lowerCamelCase					)
     if len(_lowerCamelCase					) > 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(_lowerCamelCase     ,			*_lowerCamelCase     ,			sampling_rate=_lowerCamelCase     ,			**_lowerCamelCase					)
     if text is not None:
      __UpperCAmelCase					=   self.tokenizer(_lowerCamelCase     ,			**_lowerCamelCase					)

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



    def 					__lowerCamelCase						(  self     ,			*__A     ,			**__A					):
     # For backward compatibility
     if self._in_target_context_manager:
      return self.current_processor.pad(*_lowerCamelCase     ,			**_lowerCamelCase					)

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

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

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



    def 					__lowerCamelCase						(  self     ,			*__A     ,			**__A					):
     return self.tokenizer.batch_decode(*_lowerCamelCase     ,			**_lowerCamelCase					)



    def 					__lowerCamelCase						(  self     ,			*__A     ,			**__A					):
     return self.tokenizer.decode(*_lowerCamelCase     ,			**_lowerCamelCase					)




    @contextmanager
    def 					__lowerCamelCase						(  self					):
     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












'''simple docstring'''




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_A:					List[str]							=				{
    """configuration_luke""": ["""LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP""", """LukeConfig"""],
    """tokenization_luke""": ["""LukeTokenizer"""],
}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _A:					Union[str, Any]							=				[
        """LUKE_PRETRAINED_MODEL_ARCHIVE_LIST""",
        """LukeForEntityClassification""",
        """LukeForEntityPairClassification""",
        """LukeForEntitySpanClassification""",
        """LukeForMultipleChoice""",
        """LukeForQuestionAnswering""",
        """LukeForSequenceClassification""",
        """LukeForTokenClassification""",
        """LukeForMaskedLM""",
        """LukeModel""",
        """LukePreTrainedModel""",
    ]


if TYPE_CHECKING:
    from .configuration_luke import LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP, LukeConfig
    from .tokenization_luke import LukeTokenizer

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_luke import (
            LUKE_PRETRAINED_MODEL_ARCHIVE_LIST,
            LukeForEntityClassification,
            LukeForEntityPairClassification,
            LukeForEntitySpanClassification,
            LukeForMaskedLM,
            LukeForMultipleChoice,
            LukeForQuestionAnswering,
            LukeForSequenceClassification,
            LukeForTokenClassification,
            LukeModel,
            LukePreTrainedModel,
        )

else:
    import sys

    _A:					str							=				_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)





