-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
66 lines (52 loc) · 1.93 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import flask
from flask import *
from training import *
from models.VGG import *
if __name__ == "__main__":
app = flask.Flask(__name__)
app.debug = True
model = vgg13_bn()
optimizer = torch.optim.Adam(model.parameters(), lr=5e-5)
"""
best2.pth
VGG11 MEL_SPECTROGRAM 128 FILTERS
best_model_melspec.pth 效果很好啊!!!
"""
checkpointer = torch.load('best_model_melspec.pth',map_location='cpu')
model.load_state_dict(checkpointer['state_dict'])
@app.route('/', methods=['POST', 'GET'])
def home():
print("open home")
return send_from_directory('.','index.html')
@app.route('/static/upload.php', methods=['POST', 'GET'])
def upload():
print("running")
if request.method == 'POST':
f = request.files['audio_data']
save_to = "upload/{}".format(f.filename)
f.save(save_to)
#index = infer(model,save_to)
return redirect(url_for('upload'))
return render_template('index.html')
@app.route('/save-record', methods=['POST','GET'])
def save_record():
print("save_record")
file = flask.request.files['file']
app.logger.debug(file.filename)
label = ["数字","语音","语言","识别","中国","总工",
"北京"
,"背景"
,"上海"
,"商行"
,"复旦"
,"饭店"
,"Speech"
,"Speaker",
"Signal","Process","Print","Open","Close",
"Project"]
os.makedirs("upload", exist_ok=True)
save_to = "upload/{}".format(file.filename)
file.save(save_to)
print(label[infer(model, save_to)])
return label[infer(model, save_to)]
app.run(host="localhost", port=8999)