





import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


__lowercase	: str       =False
try:
     __lowercase	: Optional[int]       =_is_package_available("""google.colab""")
except ModuleNotFoundError:
     pass

@input.register
class   A							:



      def __init__(						self:    List[Any]		,	_lowerCAmelCase:    str = None		,	_lowerCAmelCase:    list = []							)    ->     Optional[Any]:
         '''simple docstring'''

         UpperCAmelCase_           =0
         UpperCAmelCase_           =choices
         UpperCAmelCase_           =prompt
         if sys.platform == "win32":
            UpperCAmelCase_           ="*"
         else:
            UpperCAmelCase_           ="➔ "



      def 						lowerCAmelCase__     (						self:    List[Any]		,	_lowerCAmelCase:    Dict		,	_lowerCAmelCase:    str = ""							)    ->     int:
         '''simple docstring'''

         if sys.platform != "win32":
            writeColor(self.choices[index]		,	32		,	_lowerCAmelCase							)
         else:
            forceWrite(self.choices[index]		,	_lowerCAmelCase							)



      def 						lowerCAmelCase__     (						self:    int		,	_lowerCAmelCase:    int							)    ->     Optional[Any]:
         '''simple docstring'''

         if index == self.position:
            forceWrite(F' {self.arrow_char} '							)
            self.write_choice(_lowerCAmelCase							)
         else:
            forceWrite(F'    {self.choices[index]}'							)
         reset_cursor()



      def 						lowerCAmelCase__     (						self:    List[Any]		,	_lowerCAmelCase:    Direction		,	_lowerCAmelCase:    int = 1							)    ->     Dict:
         '''simple docstring'''

         UpperCAmelCase_           =self.position
         if direction == Direction.DOWN:
            if self.position + 1 >= len(self.choices							):
               return
            self.position += num_spaces
         else:
            if self.position - 1 < 0:
               return
            self.position -= num_spaces
         clear_line()
         self.print_choice(_lowerCAmelCase							)
         move_cursor(_lowerCAmelCase		,	direction.name							)
         self.print_choice(self.position							)



      @input.mark(KEYMAP["up"]							)
      def 						lowerCAmelCase__     (						self:    Optional[Any]							)    ->     List[Any]:
         '''simple docstring'''

         self.move_direction(Direction.UP							)



      @input.mark(KEYMAP["down"]							)
      def 						lowerCAmelCase__     (						self:    List[Any]							)    ->     Optional[int]:
         '''simple docstring'''

         self.move_direction(Direction.DOWN							)



      @input.mark(KEYMAP["newline"]							)
      def 						lowerCAmelCase__     (						self:    Dict							)    ->     Any:
         '''simple docstring'''

         move_cursor(len(self.choices							) - self.position		,	"DOWN"							)
         return self.position



      @input.mark(KEYMAP["interrupt"]							)
      def 						lowerCAmelCase__     (						self:    Tuple							)    ->     Optional[Any]:
         '''simple docstring'''

         move_cursor(len(self.choices							) - self.position		,	"DOWN"							)
         raise KeyboardInterrupt



      @input.mark_multiple(*[KEYMAP[str(_lowerCAmelCase							)] for number in range(10							)]							)
      def 						lowerCAmelCase__     (						self:    Optional[int]							)    ->     Tuple:
         '''simple docstring'''

         UpperCAmelCase_           =int(chr(self.current_selection							)							)
         UpperCAmelCase_           =index - self.position
         if index == self.position:
            return
         if index < len(self.choices							):
            if self.position > index:
               self.move_direction(Direction.UP		,	-movement							)
            elif self.position < index:
               self.move_direction(Direction.DOWN		,	_lowerCAmelCase							)
            else:
               return
         else:
            return






      def 						lowerCAmelCase__     (						self:    int		,	_lowerCAmelCase:    int = 0							)    ->     Dict:
         '''simple docstring'''

         if self.prompt:
            linebreak()
            forceWrite(self.prompt		,	"\n"							)
            if in_colab:
               forceWrite("Please input a choice index (starting from 0), and press enter"		,	"\n"							)
            else:
               forceWrite("Please select a choice using the arrow or number keys, and selecting with enter"		,	"\n"							)
         UpperCAmelCase_           =default_choice
         for i in range(len(self.choices							)							):
            self.print_choice(_lowerCAmelCase							)
            forceWrite("\n"							)
         move_cursor(len(self.choices							) - self.position		,	"UP"							)
         with cursor.hide():
            while True:
               if in_colab:
                  try:
                     UpperCAmelCase_           =int(builtins.input()							)
                  except ValueError:
                     UpperCAmelCase_           =default_choice
               else:
                  UpperCAmelCase_           =self.handle_input()
               if choice is not None:
                  reset_cursor()
                  for _ in range(len(self.choices							) + 1							):
                     move_cursor(1		,	"UP"							)
                     clear_line()
                  self.write_choice(_lowerCAmelCase		,	"\n"							)
                  return choice









'''simple docstring'''



import argparse

from transformers import TaConfig, TaForConditionalGeneration, load_tf_weights_in_ta
from transformers.utils import logging


logging.set_verbosity_info()
def        UpperCAmelCase (    A	:					Optional[Any]       ,		A	:					Optional[int]       ,		A	:					int					):
							# Initialise PyTorch model
							SCREAMING_SNAKE_CASE       :   str         =      TaConfig.from_json_file(A					)
							print(F"""Building PyTorch model from configuration: {config}"""					)
							SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      TaForConditionalGeneration(A					)

							# Load weights from tf checkpoint
							load_tf_weights_in_ta(A       ,		A       ,		A					)

							# Save pytorch-model
							print(F"""Save PyTorch model to {pytorch_dump_path}"""					)
							model.save_pretrained(A					)


if __name__ == "__main__":
							lowerCAmelCase_  :							Union[str, Any]             =    argparse.ArgumentParser()
							# Required parameters
							parser.add_argument(
							    '--tf_checkpoint_path', default=None, type=str, required=True, help='Path to the TensorFlow checkpoint path.'
							)
							parser.add_argument(
							    '--config_file',
							    default=None,
							    type=str,
							    required=True,
							    help=(
							        'The config json file corresponding to the pre-trained T5 model. \nThis specifies the model architecture.'
							    ),
							)
							parser.add_argument(
							    '--pytorch_dump_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
							)
							lowerCAmelCase_  :							Tuple             =    parser.parse_args()
							convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path)




