-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
47 lines (35 loc) · 1004 Bytes
/
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
#app.py
#structure of code.
'''
>>Load pickled model
>>Name flask app
>>create a route that recieves JSON inputs,
used the trained model to make a prediction,
and returns that prediction in a JSON format,
which can be accessed through API endpoint.
'''
#app using flask
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():
data = request.get_json(force = True)
print('data',data)
#convert data into dataframe
data.update((x,[y]) for x, y in data.items())
data_df = pd.DataFrame.from_dict(data)
print('data_df',data_df)
#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)