Update app.py
Browse files
app.py
CHANGED
|
@@ -5,72 +5,59 @@ import pickle
|
|
| 5 |
# Load trained model
|
| 6 |
model = pickle.load(open("life_expectancy_model.pkl", "rb"))
|
| 7 |
|
| 8 |
-
# Custom
|
| 9 |
st.markdown("""
|
| 10 |
<style>
|
| 11 |
-
body {
|
| 12 |
-
background-color: #f5f5f5;
|
| 13 |
-
}
|
| 14 |
.stApp {
|
| 15 |
-
background-color: #
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
}
|
| 19 |
-
.
|
| 20 |
background-color: #4CAF50;
|
| 21 |
padding: 15px;
|
| 22 |
border-radius: 10px;
|
| 23 |
color: white;
|
| 24 |
text-align: center;
|
| 25 |
-
font-size:
|
| 26 |
font-weight: bold;
|
| 27 |
}
|
| 28 |
</style>
|
| 29 |
""", unsafe_allow_html=True)
|
| 30 |
|
| 31 |
-
# App Title
|
| 32 |
-
st.
|
| 33 |
-
st.markdown("
|
| 34 |
-
|
| 35 |
-
#
|
| 36 |
-
st.
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
status =
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
measles = st.
|
| 50 |
-
bmi = st.
|
| 51 |
-
under_five_deaths = st.
|
| 52 |
-
polio = st.
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
population = st.sidebar.slider("๐จโ๐ฉโ๐ฆ Population", 34, 1293859000, 10230850)
|
| 58 |
-
thinness_1_19 = st.sidebar.slider("๐งโโ๏ธ Thinness 1-19 years (%)", 0.1, 27.7, 4.83)
|
| 59 |
-
thinness_5_9 = st.sidebar.slider("๐ง Thinness 5-9 years (%)", 0.1, 28.6, 4.86)
|
| 60 |
-
income_composition = st.sidebar.slider("๐ฐ Income Composition of Resources", 0.0, 0.948, 0.63)
|
| 61 |
-
schooling = st.sidebar.slider("๐ Schooling (Years)", 0.0, 20.7, 11.99)
|
| 62 |
-
|
| 63 |
-
# Predict Button with Animation
|
| 64 |
if st.button("๐ฎ Predict Life Expectancy"):
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
hepatitis_b, measles, bmi, under_five_deaths, polio, total_expenditure,
|
| 68 |
-
diphtheria, hiv_aids, gdp, population, thinness_1_19, thinness_5_9,
|
| 69 |
-
income_composition, schooling]])
|
| 70 |
-
|
| 71 |
-
prediction = model.predict(features)[0]
|
| 72 |
|
| 73 |
-
|
| 74 |
-
st.markdown(f'<div class="prediction-box">๐ Predicted Life Expectancy: <b>{prediction:.2f} years</b></div>',
|
| 75 |
-
unsafe_allow_html=True)
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
# Load trained model
|
| 6 |
model = pickle.load(open("life_expectancy_model.pkl", "rb"))
|
| 7 |
|
| 8 |
+
# Custom Styling for Clean UI
|
| 9 |
st.markdown("""
|
| 10 |
<style>
|
|
|
|
|
|
|
|
|
|
| 11 |
.stApp {
|
| 12 |
+
background-color: #f8f9fa;
|
| 13 |
+
}
|
| 14 |
+
.title-container {
|
| 15 |
+
text-align: center;
|
| 16 |
}
|
| 17 |
+
.result-box {
|
| 18 |
background-color: #4CAF50;
|
| 19 |
padding: 15px;
|
| 20 |
border-radius: 10px;
|
| 21 |
color: white;
|
| 22 |
text-align: center;
|
| 23 |
+
font-size: 22px;
|
| 24 |
font-weight: bold;
|
| 25 |
}
|
| 26 |
</style>
|
| 27 |
""", unsafe_allow_html=True)
|
| 28 |
|
| 29 |
+
# App Title
|
| 30 |
+
st.markdown("<h1 class='title-container'>๐ Life Expectancy Prediction</h1>", unsafe_allow_html=True)
|
| 31 |
+
st.markdown("#### Predict the life expectancy based on health and economic factors.")
|
| 32 |
+
|
| 33 |
+
# Two-column Layout for Better Readability
|
| 34 |
+
col1, col2 = st.columns(2)
|
| 35 |
+
|
| 36 |
+
with col1:
|
| 37 |
+
year = st.number_input("๐
Year", min_value=2000, max_value=2015, value=2008)
|
| 38 |
+
status = st.radio("๐ Status", ["Developing", "Developed"], horizontal=True)
|
| 39 |
+
status = 1 if status == "Developed" else 0
|
| 40 |
+
adult_mortality = st.number_input("โฐ๏ธ Adult Mortality Rate", min_value=1.0, max_value=723.0, value=144.0)
|
| 41 |
+
infant_deaths = st.number_input("๐ถ Infant Deaths", min_value=0, max_value=1800, value=3)
|
| 42 |
+
alcohol = st.number_input("๐ท Alcohol Consumption", min_value=0.01, max_value=17.87, value=4.55)
|
| 43 |
+
percentage_expenditure = st.number_input("๐ฐ % Healthcare Expenditure", min_value=0.0, max_value=19479.91, value=738.25)
|
| 44 |
+
hepatitis_b = st.number_input("๐ฆ Hepatitis B Immunization (%)", min_value=1, max_value=99, value=83)
|
| 45 |
+
|
| 46 |
+
with col2:
|
| 47 |
+
measles = st.number_input("๐ค Measles Cases", min_value=0, max_value=212183, value=2419)
|
| 48 |
+
bmi = st.number_input("โ๏ธ BMI", min_value=1.0, max_value=87.3, value=38.3)
|
| 49 |
+
under_five_deaths = st.number_input("โฐ๏ธ Under-Five Deaths", min_value=0, max_value=2500, value=4)
|
| 50 |
+
polio = st.number_input("๐ Polio Immunization (%)", min_value=3, max_value=99, value=82)
|
| 51 |
+
hiv_aids = st.number_input("๐ฆ HIV/AIDS Prevalence Rate", min_value=0.1, max_value=50.6, value=1.74)
|
| 52 |
+
schooling = st.number_input("๐ Schooling (Years)", min_value=0.0, max_value=20.7, value=11.99)
|
| 53 |
+
|
| 54 |
+
# Predict Button
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
if st.button("๐ฎ Predict Life Expectancy"):
|
| 56 |
+
features = np.array([[year, status, adult_mortality, infant_deaths, alcohol, percentage_expenditure,
|
| 57 |
+
hepatitis_b, measles, bmi, under_five_deaths, polio, hiv_aids, schooling]])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
prediction = model.predict(features)[0]
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
# Display Result in a Stylish Box
|
| 62 |
+
st.markdown(f'<div class="result-box">๐ Predicted Life Expectancy: <b>{prediction:.2f} years</b></div>',
|
| 63 |
+
unsafe_allow_html=True)
|