-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
215 lines (164 loc) · 5.6 KB
/
app.py
File metadata and controls
215 lines (164 loc) · 5.6 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import streamlit as st
import pandas as pd
import numpy as np
from src.predict import predict
from streamlit_lottie import st_lottie
import requests
# ---------------- CONFIG ---------------- #
st.set_page_config(
page_title="AI Health Predictor",
page_icon="🩺",
layout="wide"
)
# ---------------- LOAD ANIMATION ---------------- #
def load_lottie(url):
r = requests.get(url)
return r.json()
lottie_health = load_lottie("https://assets2.lottiefiles.com/packages/lf20_5njp3vgg.json")
lottie_result = load_lottie("https://assets1.lottiefiles.com/packages/lf20_jbrw3hcz.json")
# ---------------- CUSTOM CSS ---------------- #
st.markdown("""
<style>
.main {
background-color: #f5f7fb;
}
/* Header */
.header {
font-size: 45px;
font-weight: bold;
color: white
;
}
/* Card */
.card {
background: white;
padding: 5px;
border-radius: 10px;
box-shadow: 0px 6px 15px rgba(0,0,0,0.08);
margin-bottom: 5px;
}
/* Button */
.stButton>button {
background: linear-gradient(90deg, #4facfe, #00f2fe);
color: white;
border-radius: 10px;
height: 3em;
width: 100%;
font-size: 18px;
}
/* Result Colors */
.high { color: #dc2626; font-size: 24px; font-weight: bold; }
.low { color: #16a34a; font-size: 24px; font-weight: bold; }
.mod { color: #f59e0b; font-size: 24px; font-weight: bold; }
</style>
""", unsafe_allow_html=True)
# ---------------- SIDEBAR ---------------- #
with st.sidebar:
st.image("assets/logo.jpg", width=120)
st.title("AI Health System")
st.write("Predict risk & get smart advice")
st.markdown("---")
st.info("Enter patient details and click Predict")
# ---------------- HERO SECTION ---------------- #
col1, col2 = st.columns([2,1])
with col1:
st.markdown('<div class="header">🩺 AI Health Risk Predictor</div>', unsafe_allow_html=True)
st.write("AI system for early health risk detection and intelligent recommendations")
with col2:
st_lottie(lottie_health, height=200)
st.markdown("---")
# ---------------- INPUT SECTION ---------------- #
st.markdown('<div class="card">', unsafe_allow_html=True)
st.subheader("📋 Patient Details")
col1, col2 = st.columns(2)
with col1:
age = st.number_input("Age", min_value=1, max_value=100, step=1)
gender = st.radio("Gender", ["Male", "Female"])
spo2 = st.number_input("SpO2 (%)", min_value=80.0, max_value=100.0, step=0.1)
with col2:
pulse = st.number_input("Pulse Rate", min_value=40, max_value=150, step=1)
temp = st.number_input("Body Temperature (°F)", min_value=95.0, max_value=105.0, step=0.1)
st.markdown('</div>', unsafe_allow_html=True)
# ---------------- SYMPTOMS ---------------- #
st.markdown('<div class="card">', unsafe_allow_html=True)
st.subheader("🧠 Symptoms")
col1, col2, col3 = st.columns(3)
with col1:
fever = st.checkbox("Fever")
cough = st.checkbox("Cough")
with col2:
fatigue = st.checkbox("Fatigue")
breath = st.checkbox("Breathlessness")
with col3:
headache = st.checkbox("Headache")
bodypain = st.checkbox("Body Pain")
st.markdown('</div>', unsafe_allow_html=True)
# Convert inputs
gender = 1 if gender == "Male" else 0
fever = int(fever)
cough = int(cough)
fatigue = int(fatigue)
breath = int(breath)
headache = int(headache)
bodypain = int(bodypain)
# ---------------- ADVICE SYSTEM ---------------- #
def get_advice(risk, spo2, pulse, temp, fever, cough, fatigue, breath, headache, bodypain):
advice = []
if risk == 0:
advice.append("🚨 High Risk: Seek immediate medical attention.")
elif risk == 1:
advice.append("✅ Low Risk: You are stable.")
else:
advice.append("⚠️ Moderate Risk: Consult a doctor soon.")
if spo2 < 94:
advice.append("🫁 Low oxygen level detected.")
if pulse > 100:
advice.append("❤️ High pulse rate detected.")
if temp > 100.4:
advice.append("🌡️ Fever detected.")
if fever:
advice.append("🤒 Take proper rest.")
if cough:
advice.append("😷 Avoid cold exposure.")
if fatigue:
advice.append("😴 Get enough sleep.")
if breath:
advice.append("⚠️ Breathing issue — consult doctor.")
if headache:
advice.append("🤕 Reduce screen time.")
if bodypain:
advice.append("💪 Take rest and light stretching.")
return advice
# ---------------- PREDICTION ---------------- #
st.markdown('<div class="card">', unsafe_allow_html=True)
if st.button("🔍 Predict Health Risk"):
with st.spinner("Analyzing health data..."):
data = pd.DataFrame([{
"Age": age,
"Gender": gender,
"SpO2": spo2,
"PulseRate": pulse,
"BodyTemp_F": temp,
"Fever": fever,
"Cough": cough,
"Fatigue": fatigue,
"Breathlessness": breath,
"Headache": headache,
"BodyPain": bodypain
}])
result = predict(data)
st.subheader("🧾 Prediction Result")
col1, col2 = st.columns([2,1])
with col1:
if result == 0:
st.markdown('<p class="high">🚨 HIGH RISK</p>', unsafe_allow_html=True)
elif result == 1:
st.markdown('<p class="low">✅ LOW RISK</p>', unsafe_allow_html=True)
else:
st.markdown('<p class="mod">⚠️ MODERATE RISK</p>', unsafe_allow_html=True)
st.markdown("### 💡Advice")
for item in get_advice(result, spo2, pulse, temp, fever, cough, fatigue, breath, headache, bodypain):
st.write("•", item)
with col2:
st_lottie(lottie_result, height=200)
st.markdown('</div>', unsafe_allow_html=True)