def generate_main(data_dir, extra_flags=None): generate_parser = options.get_generation_parser() generate_args = options.parse_args_and_arch( generate_parser, [ data_dir, '--path', os.path.join(data_dir, 'checkpoint_last.pt'), '--beam', '3', '--batch-size', '64', '--max-len-b', '5', '--gen-subset', 'valid', '--no-progress-bar', '--print-alignment', ] + (extra_flags or []), ) # evaluate model in batch mode generate.main(generate_args) # evaluate model interactively generate_args.buffer_size = 0 generate_args.max_sentences = None orig_stdin = sys.stdin sys.stdin = StringIO('h e l l o\n') interactive.main(generate_args) sys.stdin = orig_stdin
def generate_main(data_dir, extra_flags=None): generate_parser = options.get_generation_parser() generate_args = options.parse_args_and_arch( generate_parser, [ data_dir, '--path', os.path.join(data_dir, 'checkpoint_last.pt'), '--beam', '3', '--batch-size', '64', '--max-len-b', '5', '--gen-subset', 'valid', '--no-progress-bar', '--print-alignment', ] + (extra_flags or []), ) # evaluate model in batch mode generate.main(generate_args) # evaluate model interactively generate_args.buffer_size = 0 generate_args.input = '-' generate_args.max_sentences = None orig_stdin = sys.stdin sys.stdin = StringIO('h e l l o\n') interactive.main(generate_args) sys.stdin = orig_stdin
def generate_main(data_dir, extra_flags=None): if extra_flags is None: extra_flags = [ "--print-alignment", ] generate_parser = options.get_generation_parser() generate_args = options.parse_args_and_arch( generate_parser, [ data_dir, "--path", os.path.join(data_dir, "checkpoint_last.pt"), "--beam", "3", "--batch-size", "64", "--max-len-b", "5", "--gen-subset", "valid", "--no-progress-bar", ] + (extra_flags or []), ) # evaluate model in batch mode generate.main(generate_args) # evaluate model interactively generate_args.buffer_size = 0 generate_args.input = "-" generate_args.max_sentences = None orig_stdin = sys.stdin sys.stdin = StringIO("h e l l o\n") interactive.main(generate_args) sys.stdin = orig_stdin
def runCommand(self, str): sys.stdout = io.StringIO() sys.stdin = io.StringIO(str + '\n') interactive.main() allstr = sys.stdout.getvalue() prompt = interactive.prompt length = len(prompt) assert len(allstr) >= length * 2 assert allstr.startswith(self.prompt) assert allstr.endswith(self.prompt) return allstr[length:-length]
def generate(self, data_dir): generate_parser = options.get_generation_parser() generate_args = generate_parser.parse_args([ data_dir, '--path', os.path.join(data_dir, 'checkpoint_best.pt'), '--beam', '5', '--batch-size', '32', '--gen-subset', 'valid', '--no-progress-bar', ]) # evaluate model in batch mode generate.main(generate_args) # evaluate model interactively orig_stdin = sys.stdin sys.stdin = StringIO('h e l l o\n') interactive.main(generate_args) sys.stdin = orig_stdin
def raw_run(args): from interactive import main return main(['<fundy-test>'] + args)
def main(): parser = argparse.ArgumentParser() parser.add_argument('-i', '--interactive', help="launch an interactive session in pygame", action="store_true") parser.add_argument( "-x", help="number of pixels in x of the picture (-1 : default)", type=int, default=-1) parser.add_argument( "-y", help="number of pixels in y of the picture (-1 : default)", type=int, default=-1) parser.add_argument( "-n", help="number of iteration to determine if the series is divergent", type=int, default=400) parser.add_argument('--no-color', help="Picture in black and white only", action="store_true") parser.add_argument("-s", "--show", help="Show the computed image", action="store_true") parser.add_argument( "-f", "--files", help="name of the files where you want to store the picture", action="append", default=[]) args = parser.parse_args() if not args.interactive: if args.x == -1: args.x = 1000 if args.y == -1: args.y = 1000 if not args.files and not args.show: parser.error( "If you're not in interactive mode, you don't want to see the picture, and you don't save it to a file, why are you running this program ?" ) image = make_img((args.x, args.y), args.n, no_color=args.no_color) for file in args.files: image.save(file) if args.show: image.show() else: if args.x == -1: args.x = 500 if args.y == -1: args.y = 500 import interactive interactive.main(args.x, args.y, args.n, args.no_color)
import interactive print 'Hello world!' interactive.main()
def testChengePrompt(self): sys.stdin = io.StringIO() prompt_str = '(test) ' interactive.prompt = prompt_str interactive.main() self.assertEqual(sys.stdout.getvalue(), prompt_str)