-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.py
More file actions
400 lines (321 loc) · 11.1 KB
/
Copy pathUI.py
File metadata and controls
400 lines (321 loc) · 11.1 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
import streamlit as st
import requests
import base64
# PAGE CONFIG
st.set_page_config(
page_title="Insurance Premium Prediction",
page_icon="💰",
layout="centered"
)
# API URL
API_URL = "https://insurance-premium-prediction-api-serving.onrender.com/predict"
# BACKGROUND + CUSTOM CSS
def add_bg(image_file):
with open(image_file, "rb") as f:
encoded = base64.b64encode(f.read()).decode()
st.markdown(
f"""
<style>
/* Hide Streamlit Header */
header[data-testid="stHeader"] {{
background: transparent;
}}
/* Hide Menu */
#MainMenu {{
visibility: hidden;
}}
footer {{
visibility: hidden;
}}
/* Background */
.stApp {{
background-image:
linear-gradient(
rgba(0,0,0,0.45),
rgba(0,0,0,0.45)
),
url("data:image/png;base64,{encoded}");
background-size: 100% auto;
background-position: top center;
background-repeat: no-repeat;
background-attachment: scroll;
}}
/* Remove Streamlit Top Padding */
.block-container {{
padding-top: 0rem !important;
}}
/* Main Form Container */
.main .block-container {{
margin-top: 220px;
background: rgba(0,0,0,0.30);
backdrop-filter: blur(12px);
padding: 2rem;
border-radius: 20px;
border: 1px solid rgba(255,255,255,0.15);
}}
/* Title */
h1 {{
color: white !important;
text-align: center;
font-size: 3rem !important;
font-weight: 800 !important;
text-shadow:
2px 2px 10px rgba(0,0,0,0.8);
}}
/* Paragraph */
p {{
color: white !important;
text-align: center;
}}
/* Labels */
label {{
color: white !important;
font-size: 16px !important;
font-weight: 600 !important;
}}
/* Number Input */
.stNumberInput input {{
background: rgba(15,15,25,0.90) !important;
color: white !important;
border-radius: 12px !important;
}}
/* Selectbox */
.stSelectbox div[data-baseweb="select"] {{
background: rgba(15,15,25,0.90) !important;
color: white !important;
border-radius: 12px !important;
}}
/* Button */
.stButton button {{
width: 100%;
height: 55px;
border: none;
border-radius: 12px;
font-size: 18px;
font-weight: bold;
color: white;
background: linear-gradient(
135deg,
#2563eb,
#06b6d4
);
}}
.stButton button:hover {{
transform: scale(1.02);
transition: 0.3s;
}}
/* Warning */
div[data-baseweb="notification"] {{
border-radius: 12px !important;
}}
/* Success */
.stSuccess {{
border-radius: 12px !important;
}}
/* Scrollbar */
::-webkit-scrollbar {{
width: 8px;
}}
::-webkit-scrollbar-thumb {{
background: #2563eb;
border-radius: 10px;
}}
</style>
""",
unsafe_allow_html=True
)
add_bg("background_image.png")
# HEADER
st.markdown(
"""
<h1>🏥 Insurance Premium Prediction</h1>
""",
unsafe_allow_html=True
)
st.markdown(
"""
<p style='text-align:center;
font-size:18px;
color:white;
margin-bottom:20px;'>
Predict insurance premium categories using Machine Learning and Risk Analysis.
</p>
""",
unsafe_allow_html=True
)
st.warning(
"This application uses an AI model to predict insurance premium categories. "
"Please provide accurate information for the most reliable results."
)
# INPUTS
age = st.number_input(
"Age",
min_value=18,
max_value=100,
value=30
)
income_lpa = st.number_input(
"Income (LPA)",
min_value=0.0,
value=5.0
)
occupation = st.selectbox(
"Occupation",
[
'Factory Worker', 'Businessman', 'Sales Manager', 'Banker',
'Marketing Manager', 'Insurance Agent', 'HR Manager',
'Pharmacist', 'Teacher', 'Software Engineer', 'Consultant',
'Driver', 'Shop Owner', 'Nurse', 'Accountant',
'Government Employee', 'Architect', 'Engineer',
'Real Estate Agent', 'Civil Servant', 'Plumber',
'Retail Manager', 'Chef', 'Electrician',
'Carpenter', 'Doctor', 'Lab Technician',
'Data Analyst', 'Lawyer', 'Content Writer'
]
)
smoker = st.selectbox(
"Smoker",
[0, 1]
)
city = st.selectbox(
"City",
[
'Agra', 'Allahabad', 'Srinagar', 'Meerut', 'Varanasi',
'Hyderabad', 'Ahmedabad', 'Chennai', 'Amritsar',
'Vadodara', 'Lucknow', 'Bhopal', 'Mumbai',
'Ludhiana', 'Rajkot', 'Surat', 'Ghaziabad',
'Ranchi', 'Pune', 'Kanpur', 'Nagpur',
'Faridabad', 'Bangalore', 'Jaipur', 'Kolkata',
'Nashik', 'Patna', 'Indore', 'Delhi',
'Visakhapatnam'
]
)
weight = st.number_input(
"Weight (kg)",
min_value=30.0,
max_value=200.0,
value=70.0
)
height = st.number_input(
"Height (m)",
min_value=1.0,
max_value=2.5,
value=1.75
)
# PREDICTION
if st.button("Predict Insurance Premium Category"):
with st.spinner("Analyzing customer profile..."):
try:
response = requests.post(
API_URL,
json={
"age": age,
"weight": weight,
"height": height,
"income_lpa": income_lpa,
"smoker": smoker,
"city": city,
"occupation": occupation
}
)
if response.status_code == 200:
prediction = response.json().get(
"predicted_insurance_premium_category"
)
else:
st.error(
"Unable to get prediction from API."
)
# PREDICTION RESULT
# =========================
if prediction == "Low":
st.success("✅ Low Premium Category")
st.image("images/low.png", use_container_width=True)
elif prediction == "Medium":
st.warning("⚠️ Medium Premium Category")
st.image("images/medium.png", use_container_width=True)
elif prediction == "High":
st.error("🚨 High Premium Category")
st.image("images/high.png", use_container_width=True)
# =========================
# GENERATE RECOMMENDATIONS
# =========================
bmi = weight / (height ** 2)
tips = []
# Smoking
if smoker == 1:
tips.append("🚭 Consider quitting smoking to significantly reduce health risks and insurance costs.")
else:
tips.append("✅ Great! Being a non-smoker lowers your overall health risk.")
# BMI Analysis
if bmi < 18.5:
tips.append("🥗 Consider a balanced diet and nutrient-rich meals to reach a healthy BMI.")
elif bmi <= 24.9:
tips.append("💪 Your BMI is within the healthy range. Keep maintaining your lifestyle.")
elif bmi <= 29.9:
tips.append("🏃 Regular exercise and healthy eating can help improve your BMI.")
else:
tips.append("⚠️ Obesity increases health risks. Consider consulting a healthcare professional.")
# Age Analysis
if age < 30:
tips.append("🌱 Building healthy habits now can significantly reduce future health risks.")
elif age < 50:
tips.append("🩺 Schedule annual preventive health checkups.")
else:
tips.append("🩺 Regular health screenings and preventive care are highly recommended.")
# Income Analysis
if income_lpa < 10:
tips.append("💰 Build an emergency healthcare fund for unexpected medical expenses.")
elif income_lpa < 25:
tips.append("📈 Consider increasing your insurance coverage as your income grows.")
else:
tips.append("🛡️ Comprehensive insurance plans may provide better long-term protection.")
# Weight Analysis
if weight > 90:
tips.append("⚖️ Maintaining a healthy weight can lower future health risks.")
# Occupation Analysis
sedentary_jobs = [
"Software Engineer",
"Data Analyst",
"Accountant",
"Content Writer",
"Banker"
]
if occupation in sedentary_jobs:
tips.append("🪑 Take regular breaks, stretch often, and stay physically active.")
# Premium Category Recommendations
if prediction == "Low":
tips.extend([
"🎉 Your profile indicates lower insurance risk.",
"💵 Consider investing premium savings into long-term financial goals.",
"🏃 Continue maintaining a healthy lifestyle.",
"🩺 Keep up with regular health checkups."
])
elif prediction == "Medium":
tips.extend([
"⚖️ Small lifestyle improvements may help reduce future premiums.",
"🏃 Aim for at least 150 minutes of exercise per week.",
"🥗 Focus on balanced nutrition and weight management.",
"📋 Review your insurance coverage annually."
])
elif prediction == "High":
tips.extend([
"🚨 Focus on preventive healthcare and routine medical checkups.",
"❤️ Prioritize fitness, nutrition, and risk-factor management.",
"🛡️ Consider comprehensive health insurance coverage.",
"📉 Lifestyle improvements may help reduce future insurance costs.",
"👨⚕️ Consult healthcare professionals for personalized guidance."
])
# =========================
# DISPLAY RECOMMENDATIONS
# =========================
st.markdown("---")
st.subheader("💡 Personalized Recommendations")
for i, tip in enumerate(tips, start=1):
st.info(f"{i}. {tip}")
except Exception as e:
st.error(f"Connection Error: {e}")
st.markdown(
"<div style='text-align:center; color:#d1d5db; font-size:14px; margin-top:30px;'>© 2025 OMI-KALIX | Insurance Premium Prediction API & Serving System</div>",
unsafe_allow_html=True
)