




import warnings
from contextlib import contextmanager

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




class 						__lowercase		(UpperCamelCase__							):




      """simple docstring"""





      _snake_case												=						"""Wav2Vec2FeatureExtractor"""
      _snake_case												=						"""AutoTokenizer"""

      def __init__(				self    ,				A    ,				A     )		->    List[str]:
         super().__init__(A    ,				A     )
         snake_case				:    Union[str, Any]           =	self.feature_extractor
         snake_case				:    Optional[Any]           =	False

      @classmethod
      def      UpperCAmelCase				(				cls    ,				A    ,				**A     )		->    Tuple:
         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    ,				)

            snake_case				:    str           =	WavaVecaFeatureExtractor.from_pretrained(A    ,				**A     )
            snake_case				:    Optional[int]           =	WavaVecaCTCTokenizer.from_pretrained(A    ,				**A     )

            return cls(feature_extractor=A    ,				tokenizer=A     )

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

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

      def      UpperCAmelCase				(				self    ,				*A    ,				**A     )		->    Optional[Any]:
         # For backward compatibility
         if self._in_target_context_manager:
            return self.current_processor.pad(*A    ,				**A     )

         snake_case				:    Any           =	kwargs.pop("""input_features"""    ,				A     )
         snake_case				:    Optional[Any]           =	kwargs.pop("""labels"""    ,				A     )
         if len(A     ) > 0:
            snake_case				:    Optional[Any]           =	args[0]
            snake_case				:    str           =	args[1:]

         if input_features is not None:
            snake_case				:    Dict           =	self.feature_extractor.pad(A    ,				*A    ,				**A     )
         if labels is not None:
            snake_case				:    List[str]           =	self.tokenizer.pad(A    ,				**A     )

         if labels is None:
            return input_features
         elif input_features is None:
            return labels
         else:
            snake_case				:    Union[str, Any]           =	labels["""input_ids"""]
            return input_features

      def      UpperCAmelCase				(				self    ,				*A    ,				**A     )		->    Tuple:
         return self.tokenizer.batch_decode(*A    ,				**A     )

      def      UpperCAmelCase				(				self    ,				*A    ,				**A     )		->    Optional[int]:
         return self.tokenizer.decode(*A    ,				**A     )

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











from argparse import ArgumentParser, Namespace

from ..utils import logging
from . import BaseTransformersCLICommand




def 						SCREAMING_SNAKE_CASE__ (   lowercase					)  ->       List[str]:
   return ConvertCommand(
       args.model_type						,args.tf_checkpoint						,args.pytorch_dump_output						,args.config						,args.finetuning_task_name					)


lowerCamelCase	:	Tuple				=   '\ntransformers can only be used from the commandline to convert TensorFlow models in PyTorch, In that case, it requires\nTensorFlow to be installed. Please see https://www.tensorflow.org/install/ for installation instructions.\n'




class 						__lowercase		(UpperCamelCase__							):




      """simple docstring"""





      @staticmethod
      def      UpperCAmelCase				(				A     )		->    List[str]:
         snake_case				:    Union[str, Any]           =	parser.add_parser(
             """convert"""    ,				help="""CLI tool to run convert model from original author checkpoints to Transformers PyTorch checkpoints."""    ,				)
         train_parser.add_argument("""--model_type"""    ,				type=A    ,				required=A    ,				help="""Model's type."""     )
         train_parser.add_argument(
             """--tf_checkpoint"""    ,				type=A    ,				required=A    ,				help="""TensorFlow checkpoint path or folder."""     )
         train_parser.add_argument(
             """--pytorch_dump_output"""    ,				type=A    ,				required=A    ,				help="""Path to the PyTorch saved model output."""     )
         train_parser.add_argument("""--config"""    ,				type=A    ,				default=""""""    ,				help="""Configuration file path or folder."""     )
         train_parser.add_argument(
             """--finetuning_task_name"""    ,				type=A    ,				default=A    ,				help="""Optional fine-tuning task name if the TF model was a finetuned model."""    ,				)
         train_parser.set_defaults(func=A     )

      def __init__(				self    ,				A    ,				A    ,				A    ,				A    ,				A    ,				*A    ,				)		->    List[Any]:
         snake_case				:    Any           =	logging.get_logger("""transformers-cli/converting"""     )

         self._logger.info(f"""Loading model {model_type}"""     )
         snake_case				:    int           =	model_type
         snake_case				:    Any           =	tf_checkpoint
         snake_case				:    int           =	pytorch_dump_output
         snake_case				:    List[str]           =	config
         snake_case				:    Tuple           =	finetuning_task_name

      def      UpperCAmelCase				(				self     )		->    int:
         if self._model_type == "albert":
            try:
               from ..models.albert.convert_albert_original_tf_checkpoint_to_pytorch import (
                   convert_tf_checkpoint_to_pytorch,
               )
            except ImportError:
               raise ImportError(A     )

            convert_tf_checkpoint_to_pytorch(self._tf_checkpoint    ,				self._config    ,				self._pytorch_dump_output     )
         elif self._model_type == "bert":
            try:
               from ..models.bert.convert_bert_original_tf_checkpoint_to_pytorch import (
                   convert_tf_checkpoint_to_pytorch,
               )
            except ImportError:
               raise ImportError(A     )

            convert_tf_checkpoint_to_pytorch(self._tf_checkpoint    ,				self._config    ,				self._pytorch_dump_output     )
         elif self._model_type == "funnel":
            try:
               from ..models.funnel.convert_funnel_original_tf_checkpoint_to_pytorch import (
                   convert_tf_checkpoint_to_pytorch,
               )
            except ImportError:
               raise ImportError(A     )

            convert_tf_checkpoint_to_pytorch(self._tf_checkpoint    ,				self._config    ,				self._pytorch_dump_output     )
         elif self._model_type == "t5":
            try:
               from ..models.ta.convert_ta_original_tf_checkpoint_to_pytorch import convert_tf_checkpoint_to_pytorch
            except ImportError:
               raise ImportError(A     )

            convert_tf_checkpoint_to_pytorch(self._tf_checkpoint    ,				self._config    ,				self._pytorch_dump_output     )
         elif self._model_type == "gpt":
            from ..models.openai.convert_openai_original_tf_checkpoint_to_pytorch import (
                convert_openai_checkpoint_to_pytorch,
            )

            convert_openai_checkpoint_to_pytorch(self._tf_checkpoint    ,				self._config    ,				self._pytorch_dump_output     )
         elif self._model_type == "transfo_xl":
            try:
               from ..models.transfo_xl.convert_transfo_xl_original_tf_checkpoint_to_pytorch import (
                   convert_transfo_xl_checkpoint_to_pytorch,
               )
            except ImportError:
               raise ImportError(A     )

            if "ckpt" in self._tf_checkpoint.lower():
               snake_case				:    List[Any]           =	self._tf_checkpoint
               snake_case				:    Tuple           =	""""""
            else:
               snake_case				:    Tuple           =	self._tf_checkpoint
               snake_case				:    Tuple           =	""""""
            convert_transfo_xl_checkpoint_to_pytorch(
                A    ,				self._config    ,				self._pytorch_dump_output    ,				A     )
         elif self._model_type == "gpt2":
            try:
               from ..models.gpta.convert_gpta_original_tf_checkpoint_to_pytorch import (
                   convert_gpta_checkpoint_to_pytorch,
               )
            except ImportError:
               raise ImportError(A     )

            convert_gpta_checkpoint_to_pytorch(self._tf_checkpoint    ,				self._config    ,				self._pytorch_dump_output     )
         elif self._model_type == "xlnet":
            try:
               from ..models.xlnet.convert_xlnet_original_tf_checkpoint_to_pytorch import (
                   convert_xlnet_checkpoint_to_pytorch,
               )
            except ImportError:
               raise ImportError(A     )

            convert_xlnet_checkpoint_to_pytorch(
                self._tf_checkpoint    ,				self._config    ,				self._pytorch_dump_output    ,				self._finetuning_task_name     )
         elif self._model_type == "xlm":
            from ..models.xlm.convert_xlm_original_pytorch_checkpoint_to_pytorch import (
                convert_xlm_checkpoint_to_pytorch,
            )

            convert_xlm_checkpoint_to_pytorch(self._tf_checkpoint    ,				self._pytorch_dump_output     )
         elif self._model_type == "lxmert":
            from ..models.lxmert.convert_lxmert_original_tf_checkpoint_to_pytorch import (
                convert_lxmert_checkpoint_to_pytorch,
            )

            convert_lxmert_checkpoint_to_pytorch(self._tf_checkpoint    ,				self._pytorch_dump_output     )
         elif self._model_type == "rembert":
            from ..models.rembert.convert_rembert_tf_checkpoint_to_pytorch import (
                convert_rembert_tf_checkpoint_to_pytorch,
            )

            convert_rembert_tf_checkpoint_to_pytorch(self._tf_checkpoint    ,				self._config    ,				self._pytorch_dump_output     )
         else:
            raise ValueError(
                """--model_type should be selected in the list [bert, gpt, gpt2, t5, transfo_xl, xlnet, xlm, lxmert]"""     )





