-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
74 lines (56 loc) · 1.85 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from flask import Flask, request, render_template
import pickle
import numpy as np
app = Flask(__name__)
# Load the model
model = pickle.load(open('model.pkl', 'rb'))
# Home routes
@app.route('/')
@app.route('/home')
def home():
return render_template('homepage.html')
@app.route('/error')
def error():
return render_template('error.html')
@app.route('/aboutproject')
def aboutproject():
return render_template('aboutproject.html')
@app.route('/review')
def review():
return render_template('review.html')
@app.route('/sourcecode')
def sourcecode():
return render_template('sourcecode.html')
@app.route('/creator')
def creator():
return render_template('creator.html')
@app.route('/location')
def location():
return render_template('location.html')
@app.route('/prediction', methods=['POST'])
def prediction():
try:
data1 = int(float(request.form['a'])) # Parameter 1 (Latitude)
data2 = int(float(request.form['b'])) # Parameter 2 (Longitude)
data3 = int(float(request.form['c'])) # Parameter 3 (Depth)
except ValueError:
return render_template('error.html', message="Invalid input")
arr = np.array([[data1, data2, data3]])
output = model.predict(arr)[0] # Predicted magnitude
output_str = str(np.round(output, 2))
print(f"Predicted Risk Score: {output}")
prediction_categories = {
(float('-inf'), 4): 'No',
(4, 6): 'Low',
(6, 8): 'Moderate',
(8, 9): 'High',
(9, float('inf')): 'Very High'
}
risk_score = None
for (lower, upper), label in prediction_categories.items():
if lower <= output < upper:
risk_score = label
break
return render_template('prediction_results.html', magnitude=output_str, risk_score=risk_score)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)