-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.py
41 lines (30 loc) · 907 Bytes
/
handler.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
import os
import pandas as pd
from flask import Flask, jsonify, request
import pickle
from dataprep import TP2EAC
# load model
model = pickle.load(open('model/modelo.pkl','rb'))
# app
app = Flask(__name__)
# routes
@app.route('/predict', methods=['POST'])
def predict():
# get data
data = request.get_json(force=True)
# converte data into dataframe
query_df = pd.DataFrame(data)
query = pd.get_dummies(query_df)
# instanciar o pre-processamento dos dados
pipeline = TP2EAC()
df_data = pipeline.data_preparation(query)
# predictions
result = model.predict(df_data)
df_data['prediction'] = result
# send back to browser
output = {'results': int(result[0])}
# return data
return df_data.to_json( orient = 'records')
if __name__ == '__main__':
port = os.environ.get('PORT', 5000)
app.run(host='0.0.0.0',port = port, debug=True)