-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
50 lines (39 loc) · 1.55 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
"""
Disease Prediction Web Application
This Flask-based web application allows users to input symptoms and receive a predicted disease.
"""
import base64
from flask import Flask, request, render_template
from src.data.disease_info import DiseaseInfo
from src.models.dp_model import DiseasePredictModel
import src.visuals.piechart as pie
app = Flask(__name__)
di = DiseaseInfo()
dpm = DiseasePredictModel()
@app.route("/")
def index_page():
"""Renders the homepage with a list of symptoms."""
if dpm.symptoms is None:
return render_template('500.html'), 500
return render_template('index.html', symp_names=dpm.symptoms)
@app.route("/predict", methods=['GET'])
def predict():
"""Handles disease prediction based on user symptoms."""
user_symp = request.args.get('symptoms', 'unknown').split(',')
pred_probs = dpm.predict_proba(user_symp)
if pred_probs is None or dpm.diseases is None:
return render_template('500.html'), 500
labels, probs = pie.filter_proba(dpm.diseases, pred_probs, 0.05)
pred_disease = labels[max(range(len(probs)), key=lambda i: probs[i])]
pie_image = pie.disease_piechart(labels, probs)
return render_template(
'result.html',
d_name = pred_disease,
d_summary = di.short_summary(pred_disease),
d_image_url = di.image_link(pred_disease),
d_precautions = di.precautions(pred_disease),
d_doctor_info = di.doctor_info(pred_disease),
piechart_data = base64.b64encode(pie_image.read()).decode()
)
if __name__ == "__main__":
app.run(debug=True)