-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
55 lines (45 loc) · 1.74 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
from doctest import debug
from flask import Flask, request, jsonify, render_template
from flask_bootstrap import Bootstrap
app = Flask(__name__)
bootstrap = Bootstrap(app)
# Rule-based condition prediction function
def predict_condition(symptoms):
fever = symptoms.get("Fever", "No")
cough = symptoms.get("Cough", "No")
runny_nose = symptoms.get("Runny_Nose", "No")
sore_throat = symptoms.get("Sore_Throat", "No")
headache = symptoms.get("Headache", "No")
fatigue = symptoms.get("Fatigue", "No")
# Apply rules
if fever == "Yes" and fatigue == "Yes" and cough == "Yes":
return "Flu"
elif runny_nose == "Yes" and sore_throat == "Yes" and cough == "No":
return "Cold"
elif all(symptom == "No" for symptom in [fever, cough, runny_nose, sore_throat, headache, fatigue]):
return "Healthy"
else:
return "Unknown"
# Route for form input
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "POST":
symptoms = {
"Fever": request.form.get("fever"),
"Cough": request.form.get("cough"),
"Runny_Nose": request.form.get("runny_nose"),
"Sore_Throat": request.form.get("sore_throat"),
"Headache": request.form.get("headache"),
"Fatigue": request.form.get("fatigue"),
}
condition = predict_condition(symptoms)
return render_template("result.html", symptoms=symptoms, condition=condition)
return render_template("index.html")
# API route for JSON input
@app.route("/api/predict", methods=["POST"])
def api_predict():
data = request.json
condition = predict_condition(data)
return jsonify({"condition": condition})
if __name__ == "__main__":
app.run(debug=True)