-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebapi.py
More file actions
48 lines (36 loc) · 1.2 KB
/
webapi.py
File metadata and controls
48 lines (36 loc) · 1.2 KB
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
from flask import Flask, request
from sklearn.externals import joblib
app = Flask(__name__)
ALLOW_EXTENSION = set(['csv'])
def upload(text_file_contents):
return text_file_contents.replace("=", ",")
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOW_EXTENSION
@app.route('/')
def form():
return """
<html>
<body>
<h1>Upload Virus Behavior</h1>
<form action="/upload" method="post" enctype="multipart/form-data">
<input type="file" name="data_file" />
<input type="submit" />
</form>
</body>
</html>
"""
@app.route('/upload', methods=["POST"])
def upload_view():
f = request.files['data_file']
if f.filename == '':
return "File not selected"
if f and allowed_file(f.filename):
# You can import full path pkl if error.
clf = joblib.load('./model/rf.pkl')
vectorizer = joblib.load('./model/vt.pkl')
sw = vectorizer.transform(f)
result = clf.predict(sw)
return "Result: %s" % result
if __name__ == "__main__":
app.run(host='0.0.0.0', port=1188, debug=True)