-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
91 lines (81 loc) · 3.05 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
81
82
83
84
85
86
87
88
89
90
91
from flask import Flask, render_template, redirect, jsonify, request, url_for
import pickle
import sklearn
import datetime as dt
date_details = dt.datetime.now()
day = date_details.weekday()
import smtplib
app = Flask(__name__)
model = pickle.load(open('model.pkl', 'rb'))
# labels
crop_list=["apple","banana","blackgram","chickpea","coconut","coffee",
"cotton","grapes","jute","kidneybeans","mango","mothbeans","mungbean",
"muskmelon","orange","papaya","pigeonpeas","pomegranate","rice",
"watermelon"]
days = ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY",
"FRIDAY", "SATURDAY", "SUNDAY"]
@app.route("/")
def home():
global day, days
return render_template("index.html",time=days[day])
@app.route("/Recommand_crop.html",methods=['POST','GET'])
def Recommand_crop():
global model,crop_list
b=1
crop=""
nitrogen=""
phosphorus=""
potassium=""
temperature=""
humidity=""
ph=""
rainfall=""
predict=[]
if request.method=='POST':
nitrogen = float(request.form['nitrogen'])
phosphorus = float(request.form['phosphorus'])
potassium = float(request.form['potassium'])
temperature = float(request.form['temperature'])
humidity = float(request.form['humidity'])
ph = float(request.form['ph'])
rainfall = float(request.form['rainfall'])
predict = model.predict([[nitrogen,phosphorus,potassium,temperature,humidity,ph,rainfall]])
a=str(predict)
for _ in a:
if _ == "1":
crop=crop_list[b-9]
else:
b+=1
else:
pass
# for _ in predict:
return render_template("Recommand_crop.html",nitrovalue=crop,nitrogen=nitrogen,
phosphorus=phosphorus,potassium=potassium,temperature=temperature,humidity=humidity,
ph=ph,rainfall=rainfall)
@app.route("/contact_us.html",methods=['POST','GET'])
def contact_us():
# my_email = "type your own mail id"
# password = "get your own app password"
recipient= ["ranitsarkar71@gmail.com"]
if request.method=="POST":
name = request.form['name']
recipient2 = (request.form['email']).lower()
message1 = request.form['message']
recipient.append(recipient2)
for mail in recipient:
with smtplib.SMTP("smtp.gmail.com", 587) as connection:
connection.starttls()
connection.login(user=my_email, password=password)
# message to be sent
SUBJECT = f"Thanks for your feedback {name}"
TEXT = message1
message = 'subject: {}\n\n{}'.format(SUBJECT, TEXT)
connection.sendmail(
from_addr=my_email,
to_addrs=mail,
msg=message)
else:
pass
return render_template("contact_us.html")
if __name__ == "__main__":
app.run(host='127.0.0.1',port=5000,debug=True)