Update app.py
Browse files
app.py
CHANGED
|
@@ -2,28 +2,55 @@ import streamlit as st
|
|
| 2 |
import numpy as np
|
| 3 |
import pickle
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
model = pickle.load(open("life_expectancy_model.pkl", "rb"))
|
| 7 |
|
| 8 |
-
# Set
|
| 9 |
st.set_page_config(
|
| 10 |
page_title="Life Expectancy Prediction",
|
| 11 |
page_icon="π",
|
| 12 |
layout="centered",
|
| 13 |
)
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
if "current_page" not in st.session_state:
|
| 28 |
st.session_state.current_page = "Model Report"
|
| 29 |
|
|
@@ -33,20 +60,47 @@ def switch_page(page):
|
|
| 33 |
|
| 34 |
# Sidebar Navigation
|
| 35 |
st.sidebar.title("Navigation")
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
-
#
|
| 41 |
if st.session_state.current_page == "Model Report":
|
| 42 |
-
st.
|
| 43 |
-
st.write("
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
elif st.session_state.current_page == "Hands-on Model":
|
| 47 |
-
st.title("
|
| 48 |
-
st.write("
|
| 49 |
-
|
| 50 |
col1, col2 = st.columns(2)
|
| 51 |
with col1:
|
| 52 |
year = st.slider("Year", 2000, 2015, 2008)
|
|
@@ -60,7 +114,7 @@ elif st.session_state.current_page == "Hands-on Model":
|
|
| 60 |
measles = st.slider("Measles Cases", 0, 212183, 2419)
|
| 61 |
bmi = st.slider("BMI", 1.0, 87.3, 38.3)
|
| 62 |
polio = st.slider("Polio Immunization (%)", 3, 99, 82)
|
| 63 |
-
|
| 64 |
with col2:
|
| 65 |
under_five_deaths = st.slider("Under-Five Deaths", 0, 2500, 4)
|
| 66 |
total_expenditure = st.slider("Total Healthcare Expenditure (%)", 0.37, 17.6, 5.92)
|
|
@@ -81,34 +135,20 @@ elif st.session_state.current_page == "Hands-on Model":
|
|
| 81 |
|
| 82 |
prediction = model.predict(features)[0]
|
| 83 |
|
| 84 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
|
| 87 |
-
st.title("π Problem Statement")
|
| 88 |
-
st.write("Define the problem related to life expectancy prediction.")
|
| 89 |
-
|
| 90 |
-
elif st.session_state.current_page == "Simple EDA":
|
| 91 |
-
st.title("π Simple EDA")
|
| 92 |
-
st.write("Explore the dataset with some basic exploratory data analysis.")
|
| 93 |
-
|
| 94 |
-
elif st.session_state.current_page == "Visualizations":
|
| 95 |
-
st.title("π Visualizations")
|
| 96 |
-
st.write("Check the visualizations that help understand the data better.")
|
| 97 |
-
|
| 98 |
-
elif st.session_state.current_page == "Model Building":
|
| 99 |
-
st.title("π Model Building")
|
| 100 |
-
st.write("Details on how the model was built and trained.")
|
| 101 |
-
|
| 102 |
-
elif st.session_state.current_page == "Final Model":
|
| 103 |
-
st.title("β
Final Model")
|
| 104 |
-
st.write("Showcase the final selected model and its performance.")
|
| 105 |
-
|
| 106 |
-
# Go Back Button
|
| 107 |
-
if st.session_state.current_page != "Model Report":
|
| 108 |
-
if st.button("π Go Back to Home"):
|
| 109 |
switch_page("Model Report")
|
| 110 |
|
| 111 |
|
|
|
|
| 112 |
# import streamlit as st
|
| 113 |
# import numpy as np
|
| 114 |
# import pickle
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import pickle
|
| 4 |
|
| 5 |
+
# Load Model
|
| 6 |
model = pickle.load(open("life_expectancy_model.pkl", "rb"))
|
| 7 |
|
| 8 |
+
# Set Page Config
|
| 9 |
st.set_page_config(
|
| 10 |
page_title="Life Expectancy Prediction",
|
| 11 |
page_icon="π",
|
| 12 |
layout="centered",
|
| 13 |
)
|
| 14 |
|
| 15 |
+
# Styling
|
| 16 |
+
st.markdown("""
|
| 17 |
+
<style>
|
| 18 |
+
.stApp {
|
| 19 |
+
background-color: #E3F2FD; /* Light Blue Background */
|
| 20 |
+
}
|
| 21 |
+
.title {
|
| 22 |
+
text-align: center;
|
| 23 |
+
font-size: 32px;
|
| 24 |
+
font-weight: bold;
|
| 25 |
+
color: #2C3E50;
|
| 26 |
+
}
|
| 27 |
+
.stButton > button {
|
| 28 |
+
width: 100%;
|
| 29 |
+
background-color: #1E88E5;
|
| 30 |
+
color: white;
|
| 31 |
+
font-size: 16px;
|
| 32 |
+
border-radius: 6px;
|
| 33 |
+
}
|
| 34 |
+
.result-box {
|
| 35 |
+
text-align: center;
|
| 36 |
+
font-size: 22px;
|
| 37 |
+
font-weight: bold;
|
| 38 |
+
color: white;
|
| 39 |
+
padding: 15px;
|
| 40 |
+
border-radius: 8px;
|
| 41 |
+
margin-top: 20px;
|
| 42 |
+
background-color: #388E3C; /* Green */
|
| 43 |
+
}
|
| 44 |
+
.section-title {
|
| 45 |
+
font-size: 20px;
|
| 46 |
+
font-weight: bold;
|
| 47 |
+
color: #1E88E5;
|
| 48 |
+
margin-top: 20px;
|
| 49 |
+
}
|
| 50 |
+
</style>
|
| 51 |
+
""", unsafe_allow_html=True)
|
| 52 |
+
|
| 53 |
+
# Navigation State
|
| 54 |
if "current_page" not in st.session_state:
|
| 55 |
st.session_state.current_page = "Model Report"
|
| 56 |
|
|
|
|
| 60 |
|
| 61 |
# Sidebar Navigation
|
| 62 |
st.sidebar.title("Navigation")
|
| 63 |
+
if st.sidebar.button("π Model Report"):
|
| 64 |
+
switch_page("Model Report")
|
| 65 |
+
if st.sidebar.button("π Hands-on Model"):
|
| 66 |
+
switch_page("Hands-on Model")
|
| 67 |
|
| 68 |
+
# Model Report Page
|
| 69 |
if st.session_state.current_page == "Model Report":
|
| 70 |
+
st.markdown("<h1 class='title'>π Model Report</h1>", unsafe_allow_html=True)
|
| 71 |
+
st.write("Explore different phases of the Life Expectancy project.")
|
| 72 |
+
|
| 73 |
+
if st.button("π Problem Statement"):
|
| 74 |
+
switch_page("Problem Statement")
|
| 75 |
+
if st.button("π₯ Data Collection"):
|
| 76 |
+
switch_page("Data Collection")
|
| 77 |
+
if st.button("π Simple EDA"):
|
| 78 |
+
switch_page("Simple EDA")
|
| 79 |
+
if st.button("π Data Pre-processing"):
|
| 80 |
+
switch_page("Data Pre-processing")
|
| 81 |
+
if st.button("π EDA"):
|
| 82 |
+
switch_page("EDA")
|
| 83 |
+
if st.button("β Model Building"):
|
| 84 |
+
switch_page("Model Building")
|
| 85 |
+
if st.button("β
Final Model"):
|
| 86 |
+
switch_page("Final Model")
|
| 87 |
+
|
| 88 |
+
# Individual Sections
|
| 89 |
+
elif st.session_state.current_page in [
|
| 90 |
+
"Problem Statement", "Data Collection", "Simple EDA",
|
| 91 |
+
"Data Pre-processing", "EDA", "Model Building", "Final Model"
|
| 92 |
+
]:
|
| 93 |
+
st.title(st.session_state.current_page)
|
| 94 |
+
st.write(f"Details about {st.session_state.current_page}...") # Add actual content here
|
| 95 |
+
|
| 96 |
+
if st.button("π Back to Model Report"):
|
| 97 |
+
switch_page("Model Report")
|
| 98 |
+
|
| 99 |
+
# Hands-on Model Page
|
| 100 |
elif st.session_state.current_page == "Hands-on Model":
|
| 101 |
+
st.title("π Hands-on Model")
|
| 102 |
+
st.write("Provide inputs to predict Life Expectancy.")
|
| 103 |
+
|
| 104 |
col1, col2 = st.columns(2)
|
| 105 |
with col1:
|
| 106 |
year = st.slider("Year", 2000, 2015, 2008)
|
|
|
|
| 114 |
measles = st.slider("Measles Cases", 0, 212183, 2419)
|
| 115 |
bmi = st.slider("BMI", 1.0, 87.3, 38.3)
|
| 116 |
polio = st.slider("Polio Immunization (%)", 3, 99, 82)
|
| 117 |
+
|
| 118 |
with col2:
|
| 119 |
under_five_deaths = st.slider("Under-Five Deaths", 0, 2500, 4)
|
| 120 |
total_expenditure = st.slider("Total Healthcare Expenditure (%)", 0.37, 17.6, 5.92)
|
|
|
|
| 135 |
|
| 136 |
prediction = model.predict(features)[0]
|
| 137 |
|
| 138 |
+
st.markdown(
|
| 139 |
+
f"""
|
| 140 |
+
<div class="result-box">
|
| 141 |
+
Predicted Life Expectancy: <b>{prediction:.2f} years</b>
|
| 142 |
+
</div>
|
| 143 |
+
""",
|
| 144 |
+
unsafe_allow_html=True,
|
| 145 |
+
)
|
| 146 |
|
| 147 |
+
if st.button("π Back to Model Report"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
switch_page("Model Report")
|
| 149 |
|
| 150 |
|
| 151 |
+
|
| 152 |
# import streamlit as st
|
| 153 |
# import numpy as np
|
| 154 |
# import pickle
|