-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
161 lines (139 loc) · 5.07 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
from flask import Flask,render_template,redirect, request, session, flash
from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail
import os
from bs4 import BeautifulSoup
import requests
import wikipedia
username="your mail id"
password="Your mail password"
app=Flask(__name__)
app.config.update(
MAIL_SERVER='smtp.gmail.com',
MAIL_PORT='465',
MAIL_USE_SSL=True,
MAIL_USERNAME=username,
MAIL_PASSWORD=password
)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:@localhost/covid_data'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
mail=Mail(app)
class Covid_people(db.Model):
# id, name, email, phone, percent
pid = db.Column(db.Integer, primary_key=True)
name=db.Column(db.String(80), unique=False, nullable=False)
email=db.Column(db.String(100), unique=False, nullable=False)
phone=db.Column(db.String(50), unique=False, nullable=False)
percent=db.Column(db.String(12), unique=False, nullable=False)
def get_data(URL):
req=requests.get(URL)
return req.text
import pickle
file=open('model.pkl','rb')
classifier=pickle.load(file)
file.close()
@app.route('/', methods=["GET","POST"])
def infer():
if request.method=="POST":
Dict1=request.form
sex=int(Dict1["sex"])
pneumonia=int(Dict1["pneumonia"])
age=int(Dict1["age"])
diabetes=int(Dict1["diabetes"])
COPD=int(Dict1["COPD"])
asthma=int(Dict1["asthma"])
inmsupr=int(Dict1["inmsupr"])
hyper=int(Dict1["hyper"])
breadth=int(Dict1["breadth"])
cardio=int(Dict1["cardio"])
obesity=int(Dict1["obesity"])
kidney=int(Dict1["kidney"])
smoke=int(Dict1["smoke"])
contact=int(Dict1["contact"])
fever=int(Dict1["fever"])
inp_f=[sex,pneumonia,age,diabetes,COPD,asthma,inmsupr,hyper,breadth,cardio,obesity,kidney,smoke,contact,fever]
inp_prob=classifier.predict_proba([inp_f])[0][1]
name=Dict1["P_name"]
email=Dict1["email"]
phn=Dict1["phn"]
percent=inp_prob*100
ip=round(percent)
entry_data=Covid_people(name=name, email=email, phone=phn, percent=percent)
db.session.add(entry_data)
db.session.commit()
mail.send_message(f"New result arrive for {name}",sender=email, recipients=[username],
body=f"The covid probability of the patient is {ip} \n Name:\t{name}\n Phone number:\t{phn}\n EMAIL ID:\t{email}\n fever:\t{fever}\n age:\t{age}")
if ip>=60:
mail.send_message("Thanking for using our COVID predictor", sender=username, recipients=[email],
body= f"Thank you for using our Covid predictor. You have a High rate of covid. Please contact with nearest hospital As Soon As Possible. Your chance is {ip}%")
elif ip<60:
mail.send_message("Thanking for using our COVID predictor", sender=username, recipients=[email],
body= f"Thank you for using our Covid predictor. You are quite safe.But please test at the nearest hospital to be safe. Your chance is {ip}%")
return render_template('result.html',infected=round(inp_prob*100))
return render_template('index.html')
#return "Hello" + str(inp_prob)
@app.route('/about')
def about():
mydata=get_data('https://www.worldometers.info/coronavirus/#countries')
soup=BeautifulSoup(mydata,'html.parser')
list1=[]
for i in range(0,6):
x=soup.find_all('tbody')[0].find_all('tr')[i]
string1=""
string1+=x.get_text()
new_data=string1.split("\n")
while("" in new_data) :
new_data.remove("")
list1.append(new_data)
results=wikipedia.summary("Coronavirus",sentences=10)
return render_template('about.html',rows=list1,main=results)
@app.route('/admin')
def admin():
if not session.get('logged_in'):
return render_template('admin.html')
return render_template('admin.html')
@app.route('/login', methods=["GET","POST"])
def login():
#session['logged_in'] = False
#session.pop('logged_in',None)
if request.method=="POST":
session.pop('logged_in',None)
if request.form['pass'] == 'password' and request.form['name'] == 'admin':
session['logged_in'] = True
#dict2={"name":"admin","pass":"password"}
admin=request.form['name']
return render_template('login.html')
flash('Wrong Username or password!')
return render_template('admin.html')
elif('logged_in' in session and session['logged_in']==True):
return render_template('login.html')
else:
flash('Wrong Username or password!')
return admin()
@app.route('/')
def logout():
session['logged_in'] = False
return infer()
@app.route('/show')
def show():
rows=Covid_people.query.all()
return render_template('show.html',rows=rows)
@app.route('/contact')
def contact():
return render_template('contact.html')
@app.route('/what')
def what():
return render_template('what.html')
@app.route("/delete/<string:pid>",methods=["GET","POST"])
def delete(pid):
if ('logged_in' in session and session['logged_in']==True):
row=Covid_people.query.filter_by(pid=pid).first()
db.session.delete(row)
db.session.commit()
rows=Covid_people.query.all()
return render_template('show.html',rows=rows)
if __name__ == '__main__':
app.secret_key = os.urandom(12)
app.debug=True
app.run()