예제 #1
0
def api_init_model_ready(project_id):  # noqa: F401
    """Check if trained model is available
    """

    error_path = get_project_path(project_id) / "error.json"
    if error_path.exists():
        print("error on training")
        with open(error_path, "r") as f:
            error_message = json.load(f)
        return jsonify(error_message), 400

    if get_proba_path(project_id).exists():
        logging.info("Model trained - go to review screen")

        # read the file with project info
        with open(get_project_file_path(project_id), "r") as fp:
            project_info = json.load(fp)

        project_info["projectInitReady"] = True

        # update the file with project info
        with open(get_project_file_path(project_id), "w") as fp:
            json.dump(project_info, fp)

        response = jsonify({'status': 1})
    else:
        response = jsonify({'status': 0})

    response.headers.add('Access-Control-Allow-Origin', '*')
    return response
예제 #2
0
def api_init_model_ready(project_id):  # noqa: F401
    """Check if trained model is available
    """

    error_path = get_project_path(project_id) / "error.json"
    if error_path.exists():
        logging.error("error on training")
        with open(error_path, "r") as f:
            error_message = json.load(f)
        return jsonify(message=error_message), 400

    try:

        if get_proba_path(project_id).exists():

            # read the file with project info
            with open(get_project_file_path(project_id), "r") as fp:
                project_info = json.load(fp)

            project_info["projectInitReady"] = True

            # update the file with project info
            with open(get_project_file_path(project_id), "w") as fp:
                json.dump(project_info, fp)

            response = jsonify({'status': 1})
        else:
            response = jsonify({'status': 0})

    except Exception as err:
        logging.error(err)
        return jsonify(message="Failed to initiate the project."), 500

    response.headers.add('Access-Control-Allow-Origin', '*')
    return response
예제 #3
0
파일: io.py 프로젝트: mao-wang/asreview
def read_proba(project_id):
    proba_fp = get_proba_path(project_id)
    try:
        with open(proba_fp, "r") as f:
            proba = json.load(f)
        proba = [float(x) for x in proba]
    except FileNotFoundError:
        proba = None
    return proba
예제 #4
0
def api_init_model_ready(project_id):  # noqa: F401
    """Check if trained model is available
    """

    if get_proba_path(project_id).exists():
        logging.info("Model trained - go to review screen")
        response = jsonify({'status': 1})
    else:
        response = jsonify({'status': 0})

    response.headers.add('Access-Control-Allow-Origin', '*')
    return response
예제 #5
0
파일: io.py 프로젝트: valmelnikov/asreview
def write_proba(project_id, proba):

    # get the proba file path location
    proba_fp = get_proba_path(project_id)

    # validate object
    if not isinstance(proba, pd.DataFrame):
        raise ValueError("Expect pandas.DataFrame with proba values.")

    if proba.index.name != "record_id":
        raise ValueError("Expect index with name 'record_id'.")

    # write the file to a csv file
    proba.to_csv(proba_fp)
예제 #6
0
파일: io.py 프로젝트: valmelnikov/asreview
def read_proba(project_id):

    proba_fp = get_proba_path(project_id)
    try:
        return pd.read_csv(proba_fp, index_col="record_id")
    except FileNotFoundError:

        # try to read the legacy file
        try:
            return read_proba_legacy(project_id)
        except FileNotFoundError:
            # no proba.csv or proba.json found.
            pass

    return None
예제 #7
0
파일: io.py 프로젝트: mao-wang/asreview
def write_proba(project_id, proba):
    proba_fp = get_proba_path(project_id)
    with open(proba_fp, "w") as f:
        json.dump(proba, f)