-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
81 lines (50 loc) · 1.9 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
73
74
75
76
77
78
79
80
#!/usr/bin/env python
# coding: utf-8
# In[1]:
from flask import Flask, render_template, request
import joblib
from datetime import date
# In[2]:
model = joblib.load('model.pkl')
model
# In[3]:
app = Flask(__name__)
# In[4]:
year = date.today().year
year
# In[5]:
@app.route("/")
def home():
return render_template('home.html',current_year=year)
# In[6]:
@app.route("/predict", methods=["GET","POST"])
def predict():
if request.method == "POST":
ph = request.form['ph'] #Range: (0.00,14.00)
hardness = request.form['hardness'] #Range: (117.12,276.39)
solids = request.form['solids'] #Range: (320.94,44831.86)
chloramines = request.form['chloramines'] #Range: (3.14,11.09)
sulfate = request.form['sulfate'] #Range: (267.15,400.32)
conductivity = request.form['conductivity'] #Range: (191.64,655.87)
organic_carbon = request.form['organic_carbon'] #Range: (5.32,23.29)
trihalomethanes = request.form['trihalomethanes'] #Range: (26.61,106.69)
turbidity = request.form['turbidity'] #Range: (1.84,6.09)
predictions = model.predict([[
ph,
hardness,
solids,
chloramines,
sulfate,
conductivity,
organic_carbon,
trihalomethanes,
turbidity
]])
output = int(predictions[0])
if output == 1:
return render_template('home.html',current_year=year,prediction_text="The water with given details is pure and potable enough to drink and meets the federal standards for domestic consumption.")
else:
return render_template('home.html',current_year=year,prediction_text="The water with specified details is impure, contaminated and non-potable. It may not be suitable for domestic consumption.")
# In[ ]:
if __name__ == "__main__":
app.run(port=8080)