-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflask_server.py
46 lines (40 loc) · 1.48 KB
/
flask_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
import os
import requests
from flask import Flask, escape, request, render_template, jsonify, make_response, session
#from utils import cvtToWavMono16, split
import random
from infer_file import get_model
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
infer = get_model()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/upload', methods=['POST','GET'])
def upload():
if request.method == 'POST':
file = request.files['file']
filename = file.filename
print(filename)
if os.path.splitext(filename)[1][1:].strip() not in ['mp3','wav','flac']:
return render_template('index.html', filename='{} file not support. select mp3, wav or flac!'.format(filename))
file_path = 'static/upload/' + filename
file.save(file_path)
print('saved file: {}'.format(file_path))
res = make_response(jsonify({"file_path": file_path, "message": "Saved: {} to server".format(filename)}))
return res
return render_template('index.html')
@app.route('/predict/<file_path>')
def predict(file_path):
print(file_path)
file_path = file_path.replace('=','/')
out_file_path = infer(file_path)
print('predict done!!')
res = make_response(jsonify({"out_file_path":out_file_path, "message": "Predict susscess!"}))
return res
if __name__ == "__main__":
app.debug = True
app.secret_key = 'dangvansam'
#app.run(host='192.168.1.254', port='9002')
app.run(port='8080')