Update app.py
Browse files
app.py
CHANGED
|
@@ -10,87 +10,233 @@ st.set_page_config(
|
|
| 10 |
layout="centered",
|
| 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 |
|
|
|
|
| 10 |
layout="centered",
|
| 11 |
)
|
| 12 |
|
| 13 |
+
# Define session state for navigation
|
| 14 |
+
if 'page' not in st.session_state:
|
| 15 |
+
st.session_state.page = "home"
|
| 16 |
+
|
| 17 |
+
def set_page(page):
|
| 18 |
+
st.session_state.page = page
|
| 19 |
+
|
| 20 |
+
st.sidebar.title("Navigation")
|
| 21 |
+
st.sidebar.button("Model Report", on_click=set_page, args=("report",))
|
| 22 |
+
st.sidebar.button("Hands-on Model", on_click=set_page, args=("model",))
|
| 23 |
+
|
| 24 |
+
if st.session_state.page == "home":
|
| 25 |
+
st.markdown("""
|
| 26 |
+
<style>
|
| 27 |
+
.stApp {
|
| 28 |
+
background-color: #E3F2FD; /* Soft blue background */
|
| 29 |
+
}
|
| 30 |
+
.title {
|
| 31 |
+
text-align: center;
|
| 32 |
+
font-size: 32px;
|
| 33 |
+
font-weight: bold;
|
| 34 |
+
color: #2C3E50;
|
| 35 |
+
}
|
| 36 |
+
.stButton > button {
|
| 37 |
+
width: 100%;
|
| 38 |
+
background-color: #1E88E5;
|
| 39 |
+
color: white;
|
| 40 |
+
font-size: 16px;
|
| 41 |
+
border-radius: 6px;
|
| 42 |
+
}
|
| 43 |
+
.result-box {
|
| 44 |
+
text-align: center;
|
| 45 |
+
font-size: 22px;
|
| 46 |
+
font-weight: bold;
|
| 47 |
+
color: white;
|
| 48 |
+
padding: 15px;
|
| 49 |
+
border-radius: 8px;
|
| 50 |
+
margin-top: 20px;
|
| 51 |
+
background-color: #388E3C; /* Green */
|
| 52 |
+
}
|
| 53 |
+
.section-title {
|
| 54 |
+
font-size: 20px;
|
| 55 |
+
font-weight: bold;
|
| 56 |
+
color: #1E88E5;
|
| 57 |
+
margin-top: 20px;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
""", unsafe_allow_html=True)
|
| 61 |
+
|
| 62 |
+
st.markdown("<h1 class='title'>Life Expectancy Prediction</h1>", unsafe_allow_html=True)
|
| 63 |
+
|
| 64 |
+
st.subheader("Select a Step:")
|
| 65 |
+
if st.button("Problem Statement"):
|
| 66 |
+
set_page("problem")
|
| 67 |
+
if st.button("Simple EDA"):
|
| 68 |
+
set_page("eda")
|
| 69 |
+
if st.button("Visualizations"):
|
| 70 |
+
set_page("visuals")
|
| 71 |
+
if st.button("Model Building"):
|
| 72 |
+
set_page("model_building")
|
| 73 |
+
if st.button("Final Model"):
|
| 74 |
+
set_page("final_model")
|
| 75 |
+
|
| 76 |
+
elif st.session_state.page == "model":
|
| 77 |
+
st.subheader("Hands-on Model")
|
| 78 |
+
col1, col2 = st.columns(2)
|
| 79 |
+
|
| 80 |
+
with col1:
|
| 81 |
+
year = st.slider("Year", 2000, 2015, 2008)
|
| 82 |
+
status = st.radio("Status", ["Developing", "Developed"], horizontal=True)
|
| 83 |
+
status = 1 if status == "Developed" else 0
|
| 84 |
+
adult_mortality = st.slider("Adult Mortality Rate", 1, 723, 144)
|
| 85 |
+
infant_deaths = st.slider("Infant Deaths", 0, 1800, 3)
|
| 86 |
+
alcohol = st.slider("Alcohol Consumption", 0.01, 17.87, 4.55)
|
| 87 |
+
percentage_expenditure = st.slider("Percentage Expenditure", 0.0, 19479.91, 738.25)
|
| 88 |
+
hepatitis_b = st.slider("Hepatitis B Immunization (%)", 1, 99, 83)
|
| 89 |
+
measles = st.slider("Measles Cases", 0, 212183, 2419)
|
| 90 |
+
bmi = st.slider("BMI", 1.0, 87.3, 38.3)
|
| 91 |
+
polio = st.slider("Polio Immunization (%)", 3, 99, 82)
|
| 92 |
+
|
| 93 |
+
with col2:
|
| 94 |
+
under_five_deaths = st.slider("Under-Five Deaths", 0, 2500, 4)
|
| 95 |
+
total_expenditure = st.slider("Total Healthcare Expenditure (%)", 0.37, 17.6, 5.92)
|
| 96 |
+
diphtheria = st.slider("Diphtheria Immunization (%)", 2, 99, 82)
|
| 97 |
+
hiv_aids = st.slider("HIV/AIDS Prevalence Rate", 0.1, 50.6, 1.74)
|
| 98 |
+
gdp = st.slider("GDP per Capita", 1.68, 119172.7, 6611.52)
|
| 99 |
+
population = st.slider("Population", 34, 1293859000, 10230850)
|
| 100 |
+
thinness_1_19 = st.slider("Thinness 1-19 years (%)", 0.1, 27.7, 4.83)
|
| 101 |
+
thinness_5_9 = st.slider("Thinness 5-9 years (%)", 0.1, 28.6, 4.86)
|
| 102 |
+
income_composition = st.slider("Income Composition of Resources", 0.0, 0.948, 0.63)
|
| 103 |
+
schooling = st.slider("Schooling (Years)", 0.0, 20.7, 11.99)
|
| 104 |
+
|
| 105 |
+
if st.button("Predict Life Expectancy"):
|
| 106 |
+
features = np.array([[year, status, adult_mortality, infant_deaths, alcohol, percentage_expenditure,
|
| 107 |
+
hepatitis_b, measles, bmi, under_five_deaths, polio, total_expenditure,
|
| 108 |
+
diphtheria, hiv_aids, gdp, population, thinness_1_19, thinness_5_9,
|
| 109 |
+
income_composition, schooling]])
|
| 110 |
+
prediction = model.predict(features)[0]
|
| 111 |
+
|
| 112 |
+
st.markdown(
|
| 113 |
+
f"""
|
| 114 |
+
<div class="result-box">
|
| 115 |
+
Predicted Life Expectancy: <b>{prediction:.2f} years</b>
|
| 116 |
+
</div>
|
| 117 |
+
""",
|
| 118 |
+
unsafe_allow_html=True,
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
elif st.session_state.page == "report":
|
| 122 |
+
st.subheader("Model Report")
|
| 123 |
+
st.write("Detailed model performance metrics will be shown here.")
|
| 124 |
+
|
| 125 |
+
elif st.session_state.page == "problem":
|
| 126 |
+
st.subheader("Problem Statement")
|
| 127 |
+
st.write("Details about the problem statement will go here.")
|
| 128 |
+
|
| 129 |
+
elif st.session_state.page == "eda":
|
| 130 |
+
st.subheader("Simple EDA")
|
| 131 |
+
st.write("Exploratory Data Analysis details will be here.")
|
| 132 |
+
|
| 133 |
+
elif st.session_state.page == "visuals":
|
| 134 |
+
st.subheader("Visualizations")
|
| 135 |
+
st.write("Graphs and charts will be displayed here.")
|
| 136 |
+
|
| 137 |
+
elif st.session_state.page == "model_building":
|
| 138 |
+
st.subheader("Model Building")
|
| 139 |
+
st.write("Steps for building the model will be described here.")
|
| 140 |
+
|
| 141 |
+
elif st.session_state.page == "final_model":
|
| 142 |
+
st.subheader("Final Model")
|
| 143 |
+
st.write("Details about the final model will be displayed here.")
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
# import streamlit as st
|
| 148 |
+
# import numpy as np
|
| 149 |
+
# import pickle
|
| 150 |
+
|
| 151 |
+
# model = pickle.load(open("life_expectancy_model.pkl", "rb"))
|
| 152 |
+
|
| 153 |
+
# st.set_page_config(
|
| 154 |
+
# page_title="Life Expectancy Prediction",
|
| 155 |
+
# page_icon="📊",
|
| 156 |
+
# layout="centered",
|
| 157 |
+
# )
|
| 158 |
+
|
| 159 |
+
# st.markdown("""
|
| 160 |
+
# <style>
|
| 161 |
+
# .stApp {
|
| 162 |
+
# background-color: #E3F2FD; /* Soft blue background */
|
| 163 |
+
# }
|
| 164 |
+
# .title {
|
| 165 |
+
# text-align: center;
|
| 166 |
+
# font-size: 32px;
|
| 167 |
+
# font-weight: bold;
|
| 168 |
+
# color: #2C3E50;
|
| 169 |
+
# }
|
| 170 |
+
# .stButton > button {
|
| 171 |
+
# width: 100%;
|
| 172 |
+
# background-color: #1E88E5;
|
| 173 |
+
# color: white;
|
| 174 |
+
# font-size: 16px;
|
| 175 |
+
# border-radius: 6px;
|
| 176 |
+
# }
|
| 177 |
+
# .result-box {
|
| 178 |
+
# text-align: center;
|
| 179 |
+
# font-size: 22px;
|
| 180 |
+
# font-weight: bold;
|
| 181 |
+
# color: white;
|
| 182 |
+
# padding: 15px;
|
| 183 |
+
# border-radius: 8px;
|
| 184 |
+
# margin-top: 20px;
|
| 185 |
+
# background-color: #388E3C; /* Green */
|
| 186 |
+
# }
|
| 187 |
+
# .section-title {
|
| 188 |
+
# font-size: 20px;
|
| 189 |
+
# font-weight: bold;
|
| 190 |
+
# color: #1E88E5;
|
| 191 |
+
# margin-top: 20px;
|
| 192 |
+
# }
|
| 193 |
+
# </style>
|
| 194 |
+
# """, unsafe_allow_html=True)
|
| 195 |
+
|
| 196 |
+
# st.markdown("<h1 class='title'>Life Expectancy Prediction</h1>", unsafe_allow_html=True)
|
| 197 |
+
|
| 198 |
+
# col1, col2 = st.columns(2)
|
| 199 |
+
|
| 200 |
+
# with col1:
|
| 201 |
+
# year = st.slider("Year", 2000, 2015, 2008)
|
| 202 |
+
# status = st.radio("Status", ["Developing", "Developed"], horizontal=True)
|
| 203 |
+
# status = 1 if status == "Developed" else 0
|
| 204 |
+
# adult_mortality = st.slider("Adult Mortality Rate", 1, 723, 144)
|
| 205 |
+
# infant_deaths = st.slider("Infant Deaths", 0, 1800, 3)
|
| 206 |
+
# alcohol = st.slider("Alcohol Consumption", 0.01, 17.87, 4.55)
|
| 207 |
+
# percentage_expenditure = st.slider("Percentage Expenditure", 0.0, 19479.91, 738.25)
|
| 208 |
+
# hepatitis_b = st.slider("Hepatitis B Immunization (%)", 1, 99, 83)
|
| 209 |
+
# measles = st.slider("Measles Cases", 0, 212183, 2419)
|
| 210 |
+
# bmi = st.slider("BMI", 1.0, 87.3, 38.3)
|
| 211 |
+
# polio = st.slider("Polio Immunization (%)", 3, 99, 82)
|
| 212 |
+
|
| 213 |
+
# with col2:
|
| 214 |
+
# under_five_deaths = st.slider("Under-Five Deaths", 0, 2500, 4)
|
| 215 |
+
# total_expenditure = st.slider("Total Healthcare Expenditure (%)", 0.37, 17.6, 5.92)
|
| 216 |
+
# diphtheria = st.slider("Diphtheria Immunization (%)", 2, 99, 82)
|
| 217 |
+
# hiv_aids = st.slider("HIV/AIDS Prevalence Rate", 0.1, 50.6, 1.74)
|
| 218 |
+
# gdp = st.slider("GDP per Capita", 1.68, 119172.7, 6611.52)
|
| 219 |
+
# population = st.slider("Population", 34, 1293859000, 10230850)
|
| 220 |
+
# thinness_1_19 = st.slider("Thinness 1-19 years (%)", 0.1, 27.7, 4.83)
|
| 221 |
+
# thinness_5_9 = st.slider("Thinness 5-9 years (%)", 0.1, 28.6, 4.86)
|
| 222 |
+
# income_composition = st.slider("Income Composition of Resources", 0.0, 0.948, 0.63)
|
| 223 |
+
# schooling = st.slider("Schooling (Years)", 0.0, 20.7, 11.99)
|
| 224 |
+
|
| 225 |
+
# if st.button("Predict Life Expectancy"):
|
| 226 |
+
# features = np.array([[year, status, adult_mortality, infant_deaths, alcohol, percentage_expenditure,
|
| 227 |
+
# hepatitis_b, measles, bmi, under_five_deaths, polio, total_expenditure,
|
| 228 |
+
# diphtheria, hiv_aids, gdp, population, thinness_1_19, thinness_5_9,
|
| 229 |
+
# income_composition, schooling]])
|
| 230 |
|
| 231 |
+
# prediction = model.predict(features)[0]
|
| 232 |
+
|
| 233 |
+
# st.markdown(
|
| 234 |
+
# f"""
|
| 235 |
+
# <div class="result-box">
|
| 236 |
+
# Predicted Life Expectancy: <b>{prediction:.2f} years</b>
|
| 237 |
+
# </div>
|
| 238 |
+
# """,
|
| 239 |
+
# unsafe_allow_html=True,
|
| 240 |
+
# )
|
| 241 |
|
| 242 |
|