-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
31 lines (26 loc) · 1010 Bytes
/
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
import os
import joblib
classifier = joblib.load(r'smartirrigation.pkl')
# importing Flask and other modules
from flask import Flask, request, render_template
import numpy as np
# Flask constructor
app = Flask(__name__)
# A decorator used to tell the application
# which URL is associated function
@app.route('/', methods = ["GET", "POST"])
def green_hacks():
if request.method == "POST":
m_c = request.form.get("m_c")
temp = request.form.get("temp")
p = classifier.predict(np.array([m_c, temp]).reshape(-2,2))
if p == 0:
output = "No need for the pump to be on."
return render_template('index.html', output=output)
elif p == 1:
output = "Switch on your pump immediately."
return render_template('index.html', output=output)
return render_template('index.html')
if __name__=='__main__':
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)