def main(argv=None): args, extra_argv = parse_args(argv) engine = Engine(args.engine) wdir = engine.get_tempdir('training') log_file = engine.get_logfile('training', ensure=True, append=True) if engine.exists(): if not args.resume and not args.force_delete: confirm_or_die(args.engine) node = EngineNode(engine) node.stop() if not args.resume: if os.path.isdir(engine.path): shutil.rmtree(engine.path) os.makedirs(engine.path) shutil.rmtree(wdir, ignore_errors=True) os.makedirs(wdir) if os.path.isfile(log_file): os.remove(log_file) activity = CreateActivity(engine, args, extra_argv, wdir=wdir, log_file=log_file, delete_on_exit=not args.debug) activity.run()
def main_stop(argv=None): args = parse_args_stop(argv) engine = Engine(args.engine) ensure_engine_exists(engine) node = EngineNode(engine) ensure_node_running(node) try: print('Halting engine "%s"...' % engine.name, end='', flush=True) node.stop(force=args.forced) print('OK', flush=True) except Exception: print('FAIL', flush=True) raise
def main_status(argv=None): args = parse_args_status(argv) if args.engine is None: engines = Engine.list() else: engine = Engine(args.engine) ensure_engine_exists(engine) engines = [engine] if len(engines) == 0: print('No engine found.') for engine in engines: node = EngineNode(engine) node_running = node.running node_state = node.state rest_api_s = ('running - %s/translate' % node_state.api_port) \ if node_running else 'stopped' cluster_s = ('running - port %d' % node_state.cluster_port) \ if node_running else 'stopped' binlog_s = ('running - %s:%d' % (node_state.binlog_host, node_state.binlog_port)) \ if node_running else 'stopped' database_s = ('running - %s:%d' % (node_state.database_host, node_state.database_port)) \ if node_running else 'stopped' print('[Engine: "%s"]' % engine.name) print(' REST API: %s' % rest_api_s) print(' Cluster: %s' % cluster_s) print(' Binary log: %s' % binlog_s) print(' Database: %s' % database_s)
def main(argv=None): args = parse_args(argv) engine = Engine(args.engine) node = EngineNode(engine) ensure_node_running(node) ensure_node_has_api(node) mmt = ModernMTTranslate(node, args.source_lang, args.target_lang, context_string=args.context, context_file=args.context_file, context_vector=args.context_vector, split_lines=args.split_lines) if args.text is not None: print(mmt.translate_text(args.text.strip())) else: if args.is_xliff: translator = XLIFFTranslator(mmt) elif args.batch: translator = BatchTranslator(mmt) else: translator = InteractiveTranslator(mmt) try: translator.run(sys.stdin, sys.stdout, threads=args.threads) except KeyboardInterrupt: pass # exit
def _load_node(engine_name): engine = Engine(engine_name) ensure_engine_exists(engine) node = EngineNode(engine) ensure_node_running(node) ensure_node_has_api(node) return node
def main_start(argv=None): args = parse_args_start(argv) engine = Engine(args.engine) ensure_engine_exists(engine) node = EngineNode(engine) ensure_node_not_running(node) success = False try: # start the ClusterNode print('Starting engine "%s"...' % engine.name, end='', flush=True) node.start(api_port=args.api_port, cluster_port=args.cluster_port, binlog_port=args.binlog_port, db_port=args.db_port, leader=args.leader, verbosity=args.verbosity, remote_debug=args.remote_debug, log_file=args.log_file) node.wait('JOINED') print('OK', flush=True) print('Loading models...', end='', flush=True) node.wait('RUNNING') print('OK', flush=True) # the node has started print('\nEngine "%s" started successfully\n' % engine.name) if node.api is not None: print( 'You can try the API with:\n' '\tcurl "%s/translate?q=world&source=en&target=it&context=computer"' ' | python -mjson.tool\n' % node.api.base_path) success = True except Exception: print('FAIL', flush=True) raise finally: if not success: node.stop()
def main(argv=None): args = parse_args(argv) engine = Engine(args.engine) ensure_engine_exists(engine) node = EngineNode(engine) ensure_node_running(node) ensure_node_has_api(node) wdir = engine.get_tempdir('evaluate') shutil.rmtree(wdir, ignore_errors=True) os.makedirs(wdir) activity = EvaluateActivity(node, args, wdir=wdir, delete_on_exit=not args.debug) activity.run()
def main(argv=None): args = parse_args(argv) if args.echo: engine = EchoTranslate(args.source_lang, args.target_lang) elif args.api_key is not None: engine = ModernMTEnterpriseTranslate( args.source_lang, args.target_lang, args.api_key, context_vector=args.context_vector) else: # local ModernMT engine node = EngineNode(Engine(args.engine)) ensure_node_running(node) ensure_node_has_api(node) engine = ModernMTTranslate(node, args.source_lang, args.target_lang, context_string=args.context, context_file=args.context_file, context_vector=args.context_vector, split_lines=args.split_lines) if args.text is not None: print(engine.translate_text(args.text.strip())) else: if args.is_xliff: translator = XLIFFTranslator(engine) elif args.batch: translator = BatchTranslator(engine) else: translator = InteractiveTranslator(engine) try: translator.run(sys.stdin, sys.stdout, threads=args.threads, suppress_errors=args.quiet) except KeyboardInterrupt: pass # exit
def __init__(self, engine_name): self.engine = Engine(engine_name) self.api = EngineNode.RestApi(port=8045) self._mmt_script = os.path.join(mmt.MMT_HOME_DIR, 'mmt')