Yashvj123 commited on
Commit
94cc85e
Β·
verified Β·
1 Parent(s): c10f08f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -50
app.py CHANGED
@@ -2,28 +2,55 @@ import streamlit as st
2
  import numpy as np
3
  import pickle
4
 
5
- # Load the 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
- # Define pages
16
- PAGES = {
17
- "Model Report": "model_report",
18
- "Hands-on Model": "hands_on_model",
19
- "Problem Statement": "problem_statement",
20
- "Simple EDA": "simple_eda",
21
- "Visualizations": "visualizations",
22
- "Model Building": "model_building",
23
- "Final Model": "final_model"
24
- }
25
-
26
- # Session state for navigation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- for page_name in PAGES:
37
- if st.sidebar.button(page_name):
38
- switch_page(page_name)
 
39
 
40
- # Main Page Display
41
  if st.session_state.current_page == "Model Report":
42
- st.title("πŸ“Š Model Report")
43
- st.write("Welcome to the Life Expectancy Prediction App!")
44
- st.write("Navigate using the buttons on the sidebar.")
45
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  elif st.session_state.current_page == "Hands-on Model":
47
- st.title("πŸ” Hands-on Model")
48
- st.write("Interact with the model by providing input features.")
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.success(f"Predicted Life Expectancy: {prediction:.2f} years")
 
 
 
 
 
 
 
85
 
86
- elif st.session_state.current_page == "Problem Statement":
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