Yashvj123 commited on
Commit
c10f08f
Β·
verified Β·
1 Parent(s): 904478a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -98
app.py CHANGED
@@ -2,81 +2,52 @@ import streamlit as st
2
  import numpy as np
3
  import pickle
4
 
 
5
  model = pickle.load(open("life_expectancy_model.pkl", "rb"))
6
 
 
7
  st.set_page_config(
8
  page_title="Life Expectancy Prediction",
9
  page_icon="πŸ“Š",
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)
@@ -89,7 +60,7 @@ elif st.session_state.page == "model":
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)
@@ -107,41 +78,35 @@ elif st.session_state.page == "model":
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
 
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
+
30
+ # Function to switch pages
31
+ def switch_page(page):
32
+ st.session_state.current_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)
53
  status = st.radio("Status", ["Developing", "Developed"], horizontal=True)
 
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)
 
78
  hepatitis_b, measles, bmi, under_five_deaths, polio, total_expenditure,
79
  diphtheria, hiv_aids, gdp, population, thinness_1_19, thinness_5_9,
80
  income_composition, schooling]])
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