-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
59 lines (53 loc) · 1.81 KB
/
main.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
from flask import Flask, request
import ml
import pandas as pd
import numpy as np
import json
from utils import allowed_file
app = Flask(__name__)
# data = pd.read_csv('DELL EMEA TEST DATASET.csv')
# df = pd.DataFrame(data)
# df["slow_dispatch"] = np.where(df["velocity"].astype('int64') >= 30, 1, 0)
# df = df.dropna()
# df = df.drop(["slow_dispatch", "velocity"], axis=1)
# @app.route("/")
# def test():
# data = encode.encode(df)
# preds = predict.predict(data)
# preds = np.array(preds)
# preds_flat = preds.flatten()
# x = [str(x) for x in preds_flat]
# return json.dumps(x)
@app.route("/predict", methods=["GET", "POST"])
def predict():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
return {"message": "no file selected"}
file = request.files['file']
# if user does not select file, browser also
# submit an empty part without filename
if file.filename == '':
return {"message": "no file selected"}
if file and allowed_file(file.filename):
df = pd.read_csv(file)
df["slow_dispatch"] = np.where(df["velocity"].astype('int64') >= 30, 1, 0)
df = df.dropna()
df = df.drop(["slow_dispatch", "velocity"], axis=1)
data = ml.encode(df)
preds = ml.predict(data)
preds = np.array(preds)
preds_flat = preds.flatten()
x = [str(x) for x in preds_flat]
return json.dumps(x)
return '''
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
'''
if __name__ == '__main__':
app.run(debug=True)