-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
47 lines (30 loc) · 1.01 KB
/
app.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
from flask import Flask, render_template, request, send_from_directory
import os
from helper_funcs import *
[fname, scaler] = create_and_save()
model = load(fname)
app = Flask(__name__)
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
@app.route("/")
def index():
return render_template("index.html")
@app.route("/upload", methods=['POST'])
def upload():
target = os.path.join(APP_ROOT, 'audio/')
print(target)
if not os.path.isdir(target):
os.mkdir(target)
file = request.files['file']
filename = file.filename
destination = "/".join([target, filename])
file.save(destination)
outname = predict(destination, model, scaler)
return render_template("complete.html", output=outname.upper())
@app.route('/upload/<filename>')
def prev_img(filename):
return send_from_directory('audio', filename)
@app.route('/res/<filename>')
def res_img(filename):
return send_from_directory('results', filename)
if __name__ == "__main__":
app.run(port=4555, debug=True)