-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
55 lines (48 loc) · 1.78 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from flask import Flask, render_template, request
import pickle
import pandas as pd
app = Flask(__name__)
# Load the trained model
with open(r'D:\Python\severity_prediction\WebApp\xgboost_model.pkl', 'rb') as file:
model = pickle.load(file)
# Render the index page
@app.route('/')
def index():
@@ -16,41 +11,11 @@ def index():
# Handle the form submission
@app.route('/predict', methods=['POST'])
def predict():
# Get the input values from the form
distance = request.form['distance']
street = request.form['street']
city = request.form['city']
country = request.form['country']
state = request.form['state']
temperature = request.form['temperature']
wind_chill = request.form['wind_chill']
visibility = request.form['visibility']
wind_direction = request.form['wind_direction']
weather_condition = request.form['weather_condition']
traffic_signal = request.form['traffic_signal']
sunrise_sunset = request.form['sunrise_sunset']
# Create a DataFrame with the input values
input_data = pd.DataFrame({
'distance': [distance],
'street': [street],
'city': [city],
'country': [country],
'state': [state],
'temperature': [temperature],
'wind_chill': [wind_chill],
'visibility': [visibility],
'wind_direction': [wind_direction],
'weather_condition': [weather_condition],
'traffic_signal': [traffic_signal],
'sunrise_sunset': [sunrise_sunset]
})
# Use the trained model to make a prediction
prediction = model.predict(input_data)[0]
# Render the result page with the prediction
return render_template('result.html', prediction=prediction)
if __name__ == '__main__':
app.run(debug=True)