Beispiel #1
0
def train_launch():
    id = request.form.get('engine_id')
    if user_utils.is_normal(): return url_for('index')

    task_id, monitor_task_id = Trainer.launch(id, user_utils.is_admin())

    return url_for('train.train_console', id=id)
Beispiel #2
0
def inspect_compare_text():
    line = request.form.get('line')
    engines = request.form.getlist('engines[]')
    translators.set_admin(user_utils.is_admin())
    translation_task_id = translators.get_compare(user_utils.get_uid(), line, engines)

    return translation_task_id
Beispiel #3
0
def inspect_details():
    line = request.form.get('line')
    engine_id = request.form.get('engine_id')
    engines = request.form.getlist('engines[]')
    translators.set_admin(user_utils.is_admin())
    translation_task_id = translators.get_inspect(user_utils.get_uid(), engine_id, line, engines)

    return translation_task_id
Beispiel #4
0
def translate_text():
    engine_id = request.form.get('engine_id')
    lines = request.form.getlist('text[]')
    detached = True
    translators.set_admin(user_utils.is_admin())
    translation_task_id = translators.text(user_utils.get_uid(), engine_id, lines)

    return jsonify({ "result": 200, "task_id": translation_task_id })
Beispiel #5
0
def as_tmx():
    engine_id = request.form.get('engine_id')
    chain_engine_id = request.form.get('chain_engine_id')
    chain_engine_id = chain_engine_id if chain_engine_id and chain_engine_id != "false" else None
    text = request.form.getlist('text[]')

    translators.set_admin(user_utils.is_admin())
    translation_task_id = translators.generate_tmx(user_utils.get_uid(), engine_id, chain_engine_id, text)
    return jsonify({ "result": 200, "task_id": translation_task_id })
Beispiel #6
0
def upload_file():
    engine_id = request.form.get('engine_id')
    user_file = request.files.get('user_file')
    as_tmx = request.form.get('as_tmx') == 'true'
    tmx_mode = request.form.get('tmx_mode')
    
    key = utils.normname(user_utils.get_uid(), user_file.filename)
    this_upload = user_utils.get_user_folder(key)

    try:
        os.mkdir(this_upload)
    except:
        shutil.rmtree(this_upload)
        os.mkdir(this_upload)
    
    user_file_path = os.path.join(this_upload, secure_filename(user_file.filename))
    user_file.save(user_file_path)

    translators.set_admin(user_utils.is_admin())
    translation_task_id = translators.translate_file(user_utils.get_uid(), engine_id, user_file_path, as_tmx, tmx_mode)

    return jsonify({ "result": 200, "task_id": translation_task_id })
Beispiel #7
0
def train_resume(engine_id):
    engine = Engine.query.filter_by(id=engine_id).first()

    if current_user.id == engine.engine_users[0].user.id or current_user.admin:
        new_model_path = os.path.join(
            engine.path, 'model-{}'.format(utils.randomfilename(length=8)))
        while os.path.exists(new_model_path):
            new_model_path = os.path.join(
                engine.path, 'model-{}'.format(utils.randomfilename(length=8)))

        config_file_path = os.path.join(engine.path, 'config.yaml')

        config = None
        with open(config_file_path, 'r') as config_file:
            config = yaml.load(config_file, Loader=yaml.FullLoader)
            current_model = config["training"]["model_dir"]
            config["training"]["model_dir"] = new_model_path

            current_model_ckpt = os.path.join(current_model, 'best.ckpt')
            if os.path.exists(current_model_ckpt):
                config["training"]["load_model"] = current_model_ckpt

        with open(config_file_path, 'w') as config_file:
            yaml.dump(config, config_file)

        engine.model_path = new_model_path
        engine.launched = datetime.datetime.utcnow().replace(tzinfo=None)
        engine.finished = None
        db.session.commit()

        task_id, _ = Trainer.launch(engine_id, user_utils.is_admin())

        i = 0
        while engine.has_stopped() and i < 100:
            db.session.refresh(engine)
            i += 1

        return redirect(url_for('train.train_console', id=engine_id))