


from typing import TYPE_CHECKING

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


lowerCamelCase__							:						List[Any]							     =   {
    """configuration_rag""": ["""RagConfig"""],
    """retrieval_rag""": ["""RagRetriever"""],
    """tokenization_rag""": ["""RagTokenizer"""],
}

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

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCamelCase__							:						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

   lowerCamelCase__							:						int							     =   _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin





class     lowerCamelCase      (       __lowerCamelCase					):
	UpperCamelCase_  :					Optional[Any]    		=	'MCTCTFeatureExtractor'
	UpperCamelCase_  :					List[Any]    		=	'AutoTokenizer'







	def __init__(     self      :Tuple   ,     lowercase      :List[str]   ,     lowercase      :Dict			)		->      Tuple:







				"""simple docstring"""






				super().__init__(lowercase   ,     lowercase			)
				SCREAMING_SNAKE_CASE     						= self.feature_extractor
				SCREAMING_SNAKE_CASE     						= False







	def __call__(     self      :Union[str, Any]   ,     *lowercase      :Union[str, Any]   ,     **lowercase      :str			)		->      int:







				"""simple docstring"""






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

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

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







	def  snake_case__     (     self      :Dict   ,     *lowercase      :Union[str, Any]   ,     **lowercase      :List[str]			)		->      Union[str, Any]:







				"""simple docstring"""






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







	def  snake_case__     (     self      :List[Any]   ,     *lowercase      :List[Any]   ,     **lowercase      :List[str]			)		->      int:







				"""simple docstring"""






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

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

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

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







	def  snake_case__     (     self      :Dict   ,     *lowercase      :List[str]   ,     **lowercase      :Union[str, Any]			)		->      List[Any]:







				"""simple docstring"""






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







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