-
Notifications
You must be signed in to change notification settings - Fork 1
/
flask_upload_only_vn.py
51 lines (44 loc) · 1.93 KB
/
flask_upload_only_vn.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
import numpy as np
from flask import Flask, request, render_template, url_for
import argparse
import os
import sys
import numpy as np
import timeit
import scipy.io.wavfile as wav_
# from infer import restore_model, load_audio
# from g2pNp2g_simple.p2gFuntion import p2g_simple as p2g
app = Flask(__name__)
config = 'config/quartznet12x1_abc.yaml'
encoder_checkpoint = 'quartznet12x1_abc_them100h/checkpoints/JasperEncoder-STEP-289936.pt'
decoder_checkpoint = 'quartznet12x1_abc_them100h/checkpoints/JasperDecoderForCTC-STEP-289936.pt'
# neural_factory = restore_model(config, encoder_checkpoint, decoder_checkpoint)
# print('restore model checkpoint done!')
@app.route('/')
def upload_form():
return render_template('upload_templates/upload.html', audio_path = 'select file to predict!')
@app.route('/', methods=['POST'])
def get_prediction():
print('PREDICT MODE')
if request.method == 'POST':
_file = request.files['file']
if _file.filename == '':
return upload_form()
print('\n\nfile uploaded:',_file.filename)
_file.save(os.path.join('static/uploaded', _file.filename))
print('Write file success!')
start = timeit.default_timer()
# sig = load_audio(os.path.join('static/uploaded', _file.filename))
end_load = timeit.default_timer()
# greedy_hypotheses, beam_hypotheses = neural_factory.infer_signal(sig)
# #predict_grapheme = p2g(predict)
# end_predict = timeit.default_timer()
# print('Load audio time:',end_load-start)
# print('Predict time:',end_predict-end_load)
# print('greedy predict:{}'.format(greedy_hypotheses))
# print('beamLM predict:{}'.format(beam_hypotheses))
return render_template('upload_templates/upload.html', _file.filename)
if __name__ == '__main__':
#load_model() # load model at the beginning once only
app.secret_key = 'dangvansam'
app.run(host='localhost', port=5000, debug=True)