Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#38 from jacquesqiao/server-static-files
Browse files Browse the repository at this point in the history
Server with frontend files
  • Loading branch information
jacquesqiao authored Nov 24, 2017
2 parents 76f715e + 31684da commit 3349605
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
# VisualDL
# VisualDL


### How to use
#### Step 1: build and install Python package
```shell
python setup.py bdist_wheel
cd dist
pip install visualdl-0.0.1-py2-none-any.whl
```

#### Step 2: build frontend
```shell
cd visualdl/frontend
npm install
npm run build
```

### Step 3: run
```
python bin/visual_dl.py --port=8888
```
26 changes: 19 additions & 7 deletions bin/visual_dl.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
""" entry point of visual_dl
"""
import json
import os
import sys
from optparse import OptionParser

from flask import Flask
from flask import request
from flask import Flask, redirect
from flask import send_from_directory

from visualdl.log import logger

app = Flask(__name__)
app = Flask(__name__, static_url_path="")


def option_parser():
Expand Down Expand Up @@ -44,12 +46,22 @@ def gen_result(status, msg):
return result


@app.route('/')
server_path = os.path.abspath(os.path.dirname(sys.argv[0]))
static_file_path = "../visualdl/frontend/dist/"


@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(os.path.join(server_path, static_file_path), filename)


@app.route("/")
def index():
"""
return redirect('/static/index.html', code=302)

:return:
"""

@app.route('/hello')
def hello():
result = gen_result(0, "Hello, this is VisualDL!")
return json.dumps(result)

Expand Down

0 comments on commit 3349605

Please sign in to comment.