-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
39 lines (36 loc) · 1.04 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
import io
import os
import numpy as np
import pickle
import pefile
import math
import tempfile
from flask import Flask, request, render_template
from model import classify
os.chdir(os.path.dirname(os.path.abspath(__file__)))
app = Flask(__name__)
app.static_folder = 'templates'
def display_dict(dictionary):
details = []
for key, value in dictionary.items():
details.append(f"<b>{key}:</b> {value}")
return "<br>".join(details)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/classify', methods=['POST'])
def classify_file():
exe_file = request.files['exe_file']
if not exe_file.filename.endswith('.exe'):
return {
'error': 'Wrong file uploaded. Please upload a .exe file.'
}
file_contents = exe_file.read()
result, details = classify(io.BytesIO(file_contents))
return {
'prediction': result,
'details': details
}
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port, debug=True)