-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
32 lines (23 loc) · 649 Bytes
/
Copy pathapp.py
File metadata and controls
32 lines (23 loc) · 649 Bytes
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
import pandas as pd
from flask import Flask, jsonify, request
import pickle
# load model
model = pickle.load(open('model.pkl','rb'))
# app
app = Flask(__name__)
# routes
@app.route('/', methods=['POST'])
def predict():
# get data
data = request.get_json(force=True)
# convert data into dataframe
data.update((x, [y]) for x, y in data.items())
data_df = pd.DataFrame.from_dict(data)
# predictions
result = model.predict(data_df)
# send back to browser
output = {'results': int(result[0])}
# return data
return jsonify(results=output)
if __name__ == '__main__':
app.run(port = 5000, debug=True)