visual_dl.py 1.4 KB
Newer Older
Q
qiaolongfei 已提交
1 2 3
""" entry point of visual_dl
"""
import json
Q
qiaolongfei 已提交
4
import os
Q
qiaolongfei 已提交
5
from optparse import OptionParser
Q
qiaolongfei 已提交
6
from flask import send_from_directory
Q
qiaolongfei 已提交
7 8 9 10

from flask import Flask
from flask import request

Q
qiaolongfei 已提交
11
from visualdl.log import logger
Q
qiaolongfei 已提交
12

Q
qiaolongfei 已提交
13 14

app = Flask(__name__, static_url_path="")
Q
qiaolongfei 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49


def option_parser():
    """

    :return:
    """
    parser = OptionParser(usage="usage: visual_dl visual_dl.py "\
                          "-p port [options]")
    parser.add_option(
        "-p",
        "--port",
        default=8040,
        action="store",
        dest="port",
        help="rest api service port")
    return parser.parse_args()


# return data
# status, msg, data
def gen_result(status, msg):
    """

    :param status:
    :param msg:
    :return:
    """
    result = dict()
    result['status'] = status
    result['msg'] = msg
    result['data'] = {}
    return result

@app.route('/')
Q
qiaolongfei 已提交
50 51 52 53 54 55 56 57 58
def root():
    return app.send_static_file('index.html')

@app.route('/js/<path:filename>')
def serve_static(filename):
    root_dir = os.path.dirname(os.getcwd())
    return send_from_directory(os.path.join('.', 'dist'), filename)

@app.route('/hello')
Q
qiaolongfei 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71
def index():
    """

    :return:
    """
    result = gen_result(0, "Hello, this is VisualDL!")
    return json.dumps(result)


if __name__ == '__main__':
    options, args = option_parser()
    logger.info(" port=" + str(options.port))
    app.run(debug=False, host="0.0.0.0", port=options.port)