-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
50 lines (37 loc) · 1.12 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
#!flask/bin/python
from flask import Flask
from flask import request
from sklearn.externals import joblib
import signals, suggestions
import os
clf = joblib.load('model2.pkl')
app = Flask(__name__)
@app.route('/')
def index():
# LOAD FILE
sample_test = signals.Sample.load_from_file("./test_z.txt")
# RESHAPE
lin = sample_test.get_linearized(reshape=True)
# PREDICT
number = clf.predict(lin)
# CONVERT WITH ASCII
char = chr(ord('a') + number[0])
print char
return char
# /get-file?filename=abc.txt
@app.route('/get-file')
def query_example():
filename = request.args.get('filename') #if key doesn't exist, returns None
# LOAD FILE
sample_test = signals.Sample.load_from_file("/Users/apple/nodejs/meo-hub-docker/node-red/data/training/"+filename)
# RESHAPE
lin = sample_test.get_linearized(reshape=True)
# PREDICT
number = clf.predict(lin)
# CONVERT WITH ASCII
char = chr(ord('a') + number[0])
print char
os.remove("/Users/apple/nodejs/meo-hub-docker/node-red/data/training/"+filename)
return char
if __name__ == '__main__':
app.run(debug=True)