-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathserver.py
49 lines (34 loc) · 1.1 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
import sys
import traceback
from flask import Flask, request, send_from_directory, render_template
sys.path.append('python')
from style_predict import autotag, load_model
app = Flask(__name__)
model, params = load_model('model')
@app.route('/assets/<path:path>')
def serve_assets(path):
return send_from_directory('assets', path)
@app.route('/favicon.ico')
def favicon():
return send_from_directory('assets', 'favicon.ico')
@app.after_request
def add_no_cache(response):
if request.endpoint != "static":
response.headers["Cache-Control"] = "no-cache"
response.headers["Pragma"] = "no-cache"
return response
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html')
@app.route('/style', methods=["GET", "POST"])
def style():
try:
txt = request.form["txt"]
return autotag(txt, model, params)
except Exception as e:
return "<h2>"+str(e)+"</h2>" + traceback.format_exc().replace('\n', '<br>')
@app.route('/')
def root():
return render_template('index.html')
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True)