
"""simple docstring"""


import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin







class 				lowerCAmelCase_				(      _lowercase    ):



      '''simple docstring'''


      _lowerCamelCase:    str      =    '''MCTCTFeatureExtractor'''
      _lowerCamelCase:    Any      =    '''AutoTokenizer'''


      def __init__( self     :      Tuple  ,A_     :      List[str]  ,A_     :      List[str]      )     ->   Dict:
       super().__init__(A__  ,A__      )
       A						   =   self.feature_extractor
       A						   =   False


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

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


      def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]  ,*A_     :      Dict  ,**A_     :      str      )     ->   List[str]:
       return self.tokenizer.batch_decode(*A__  ,**A__      )


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

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

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

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


      def 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]  ,*A_     :      str  ,**A_     :      List[str]      )     ->   List[str]:
       return self.tokenizer.decode(*A__  ,**A__      )




      @contextmanager
      def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]      )     ->   List[Any]:
       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						   =   True
       A						   =   self.tokenizer
       yield
       A						   =   self.feature_extractor
       A						   =   False

"""simple docstring"""


from argparse import ArgumentParser

from . import BaseTransformersCLICommand






def       _snake_case				(		snake_case__   :     Optional[int]     ):
	return DownloadCommand(args.model	,      args.cache_dir	,      args.force	,      args.trust_remote_code     )







class 				lowerCAmelCase_				(      _lowercase    ):



						'''simple docstring'''


						@staticmethod
						def 						_SCREAMING_SNAKE_CASE      ( A_     :      ArgumentParser      )     ->   Any:
							A						   =   parser.add_parser('download'      )
							download_parser.add_argument(
							    '--cache-dir'  ,type=A_  ,default=A_  ,help='Path to location to store the models'      )
							download_parser.add_argument(
							    '--force'  ,action='store_true'  ,help='Force the model to be download even if already in cache-dir'      )
							download_parser.add_argument(
							    '--trust-remote-code'  ,action='store_true'  ,help='Whether or not to allow for custom models defined on the Hub in their own modeling files. Use only if you\'ve reviewed the code as it will execute on your local machine'  ,)
							download_parser.add_argument('model'  ,type=A_  ,help='Name of the model to download'      )
							download_parser.set_defaults(func=A_      )


						def __init__( self     :      Dict  ,A_     :      str  ,A_     :      str  ,A_     :      bool  ,A_     :      bool      )     ->   Union[str, Any]:
							A						   =   model
							A						   =   cache
							A						   =   force
							A						   =   trust_remote_code




						def 						_SCREAMING_SNAKE_CASE      ( self     :      Dict      )     ->   Optional[int]:
							from ..models.auto import AutoModel, AutoTokenizer

							AutoModel.from_pretrained(
							    self._model  ,cache_dir=self._cache  ,force_download=self._force  ,trust_remote_code=self._trust_remote_code      )
							AutoTokenizer.from_pretrained(
							    self._model  ,cache_dir=self._cache  ,force_download=self._force  ,trust_remote_code=self._trust_remote_code      )