-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
40 lines (28 loc) · 1.17 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
37
38
39
40
import numpy as np
import pandas as pd
from flask import Flask, request, render_template
import pickle
app = Flask(__name__,template_folder='templates')
model = pickle.load(open('accident_final.pkl', 'rb'))
@app.route('/')
def home():
return render_template('finalgui.html')
@app.route('/predict', methods=['POST'])
def predict():
input_features = [float(x) for x in request.form.values()]
features_value = [np.array(input_features)]
features_name = ['Number_of_vehicles_involved',
'Number_of_casualties','Day_of_week','Age_band_of_driver',
'Area_accident_occured','Types_of_Junction','Light_conditions',
'Weather_conditions','Time_hour']
df = pd.DataFrame(features_value, columns=features_name)
output = model.predict(df)
if output[0] == 0:
res_val = " Fatal injury"
elif output[0] == 1:
res_val=" Serious Injury"
else:
res_val = " Slight Injury"
return render_template('finalgui.html', prediction='Person will most likely get a {}'.format(res_val))
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8000)