-
Notifications
You must be signed in to change notification settings - Fork 0
/
QbE_System.py
84 lines (64 loc) · 2.67 KB
/
QbE_System.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import inspect
import os
import numpy as np
from flask import Flask
from flask import flash
from flask import json
from flask import redirect
from flask import render_template
from flask import request
from flask import send_from_directory
from flask import url_for
from werkzeug.utils import secure_filename
from feature_extractor.run import FeatureExtractor
from src import model_bnf
app = Flask(__name__)
UPLOAD_FOLDER = '/home/gangeshwark/PycharmProjects/QbE_System/uploads'
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'wav', 'mp3'])
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
small = 1
@app.route('/')
def hello_world():
if small:
return render_template('audio5js.html', audio_path='static/my4Hellow.wav')
else:
return render_template('audio5js.html', audio_path='static/110101_000444_channel3.wav')
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/api/v1/start_search', methods=['GET', 'POST'])
def upload_audio():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
# flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(path)
query_features_path = FeatureExtractor.bnf(path)
if small:
print small
corpus_features_path = os.path.abspath('../corpus_features/bnf_database/raw_bnfea_fbank_pitch.1.scp')
else:
print small
corpus_features_path = os.path.abspath(
'../corpus_features/bnfNdAdaptedMling_feats_database_selfRec/raw_bnfea_database_fbank_pitch.1.scp')
print corpus_features_path, query_features_path
os.chdir(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
AQS = model_bnf.AQSearch(query_features_path, corpus_features_path)
matrix, top_k = AQS.search()
print type(top_k)
return json.dumps({"top_k": top_k, "matrix": matrix.tolist()})
@app.route('/static/<path:path>')
def send(path):
return send_from_directory('client', path)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)