-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
36 lines (27 loc) · 1.06 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
from flask import Flask, request, render_template
import pandas as pd
import pickle
app = Flask(__name__)
file = open("./gradient_boosting_regressor_model.pkl", 'rb')
model = pickle.load(file)
data = pd.read_csv('./clean_data.csv')
data.head()
@app.route('/')
def index():
sex = sorted(data['sex'].unique())
smoker = sorted(data['smoker'].unique())
region = sorted(data['region'].unique())
return render_template('index.html', sex= sex, smoker= smoker, region= region)
@app.route('/predict', methods=['POST'])
def predict():
age = int(request.form.get('age'))
sex = request.form.get('sex')
bmi = float(request.form.get('bmi'))
children = int(request.form.get('children'))
smoker = request.form.get('smoker')
region = request.form.get('region')
prediction = model.predict(pd.DataFrame([[age, sex, bmi, children, smoker, region]],
columns=['age', 'sex', 'bmi', 'children', 'smoker', 'region']))
return str(prediction[0])
if __name__=="__main__":
app.run(debug=True)