Yashvj123 commited on
Commit
24617e8
·
verified ·
1 Parent(s): 28e33ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +116 -15
app.py CHANGED
@@ -2,41 +2,59 @@ import streamlit as st
2
  import numpy as np
3
  import pickle
4
 
5
-
6
  model = pickle.load(open("life_expectancy_model.pkl", "rb"))
7
 
 
 
 
 
 
 
 
 
8
  st.markdown("""
9
  <style>
10
- .title-container {
 
 
 
11
  text-align: center;
12
- font-size: 36px;
13
  font-weight: bold;
14
- background: -webkit-linear-gradient(45deg, #ff7e5f, #feb47b);
15
- -webkit-background-clip: text;
16
- -webkit-text-fill-color: transparent;
17
  }
18
- .result-box {
19
- background-color: #4CAF50;
20
- padding: 15px;
21
- border-radius: 10px;
22
  color: white;
 
 
 
 
23
  text-align: center;
24
  font-size: 22px;
25
  font-weight: bold;
 
 
 
26
  margin-top: 20px;
 
27
  }
28
  .sidebar-title {
29
  font-size: 22px;
30
  font-weight: bold;
31
- color: #ff7e5f;
32
  text-align: center;
33
  }
34
  </style>
35
  """, unsafe_allow_html=True)
36
 
37
- st.markdown("<h1 class='title-container'>Life Expectancy Prediction</h1>", unsafe_allow_html=True)
38
- st.markdown("### Enter the required details in the sidebar to get the predicted life expectancy.")
 
39
 
 
40
  st.sidebar.markdown("<h2 class='sidebar-title'>Input Features</h2>", unsafe_allow_html=True)
41
 
42
  year = st.sidebar.slider("Year", 2000, 2015, 2008)
@@ -61,6 +79,7 @@ thinness_5_9 = st.sidebar.slider("Thinness 5-9 years (%)", 0.1, 28.6, 4.86)
61
  income_composition = st.sidebar.slider("Income Composition of Resources", 0.0, 0.948, 0.63)
62
  schooling = st.sidebar.slider("Schooling (Years)", 0.0, 20.7, 11.99)
63
 
 
64
  if st.button("Predict Life Expectancy"):
65
  features = np.array([[year, status, adult_mortality, infant_deaths, alcohol, percentage_expenditure,
66
  hepatitis_b, measles, bmi, under_five_deaths, polio, total_expenditure,
@@ -69,5 +88,87 @@ if st.button("Predict Life Expectancy"):
69
 
70
  prediction = model.predict(features)[0]
71
 
72
- st.markdown(f'<div class="result-box">Predicted Life Expectancy: <b>{prediction:.2f} years</b></div>',
73
- unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Page Configuration
9
+ st.set_page_config(
10
+ page_title="Life Expectancy Prediction",
11
+ page_icon="📊",
12
+ layout="centered",
13
+ )
14
+
15
+ # Custom Styling
16
  st.markdown("""
17
  <style>
18
+ .stApp {
19
+ background-color: #E3F2FD; /* Soft 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
  .sidebar-title {
45
  font-size: 22px;
46
  font-weight: bold;
47
+ color: #1E88E5;
48
  text-align: center;
49
  }
50
  </style>
51
  """, unsafe_allow_html=True)
52
 
53
+ # Title
54
+ st.markdown("<h1 class='title'>Life Expectancy Prediction</h1>", unsafe_allow_html=True)
55
+ st.write("This tool predicts life expectancy based on various health and economic factors.")
56
 
57
+ # Sidebar Inputs
58
  st.sidebar.markdown("<h2 class='sidebar-title'>Input Features</h2>", unsafe_allow_html=True)
59
 
60
  year = st.sidebar.slider("Year", 2000, 2015, 2008)
 
79
  income_composition = st.sidebar.slider("Income Composition of Resources", 0.0, 0.948, 0.63)
80
  schooling = st.sidebar.slider("Schooling (Years)", 0.0, 20.7, 11.99)
81
 
82
+ # Prediction
83
  if st.button("Predict Life Expectancy"):
84
  features = np.array([[year, status, adult_mortality, infant_deaths, alcohol, percentage_expenditure,
85
  hepatitis_b, measles, bmi, under_five_deaths, polio, total_expenditure,
 
88
 
89
  prediction = model.predict(features)[0]
90
 
91
+ st.markdown(
92
+ f"""
93
+ <div class="result-box">
94
+ Predicted Life Expectancy: <b>{prediction:.2f} years</b>
95
+ </div>
96
+ """,
97
+ unsafe_allow_html=True,
98
+ )
99
+
100
+
101
+
102
+ # import streamlit as st
103
+ # import numpy as np
104
+ # import pickle
105
+
106
+
107
+ # model = pickle.load(open("life_expectancy_model.pkl", "rb"))
108
+
109
+ # st.markdown("""
110
+ # <style>
111
+ # .title-container {
112
+ # text-align: center;
113
+ # font-size: 36px;
114
+ # font-weight: bold;
115
+ # background: -webkit-linear-gradient(45deg, #ff7e5f, #feb47b);
116
+ # -webkit-background-clip: text;
117
+ # -webkit-text-fill-color: transparent;
118
+ # }
119
+ # .result-box {
120
+ # background-color: #4CAF50;
121
+ # padding: 15px;
122
+ # border-radius: 10px;
123
+ # color: white;
124
+ # text-align: center;
125
+ # font-size: 22px;
126
+ # font-weight: bold;
127
+ # margin-top: 20px;
128
+ # }
129
+ # .sidebar-title {
130
+ # font-size: 22px;
131
+ # font-weight: bold;
132
+ # color: #ff7e5f;
133
+ # text-align: center;
134
+ # }
135
+ # </style>
136
+ # """, unsafe_allow_html=True)
137
+
138
+ # st.markdown("<h1 class='title-container'>Life Expectancy Prediction</h1>", unsafe_allow_html=True)
139
+ # st.markdown("### Enter the required details in the sidebar to get the predicted life expectancy.")
140
+
141
+ # st.sidebar.markdown("<h2 class='sidebar-title'>Input Features</h2>", unsafe_allow_html=True)
142
+
143
+ # year = st.sidebar.slider("Year", 2000, 2015, 2008)
144
+ # status = st.sidebar.radio("Status", ["Developing", "Developed"], horizontal=True)
145
+ # status = 1 if status == "Developed" else 0
146
+ # adult_mortality = st.sidebar.slider("Adult Mortality Rate", 1, 723, 144)
147
+ # infant_deaths = st.sidebar.slider("Infant Deaths", 0, 1800, 3)
148
+ # alcohol = st.sidebar.slider("Alcohol Consumption", 0.01, 17.87, 4.55)
149
+ # percentage_expenditure = st.sidebar.slider("Percentage Expenditure", 0.0, 19479.91, 738.25)
150
+ # hepatitis_b = st.sidebar.slider("Hepatitis B Immunization (%)", 1, 99, 83)
151
+ # measles = st.sidebar.slider("Measles Cases", 0, 212183, 2419)
152
+ # bmi = st.sidebar.slider("BMI", 1.0, 87.3, 38.3)
153
+ # under_five_deaths = st.sidebar.slider("Under-Five Deaths", 0, 2500, 4)
154
+ # polio = st.sidebar.slider("Polio Immunization (%)", 3, 99, 82)
155
+ # total_expenditure = st.sidebar.slider("Total Healthcare Expenditure (%)", 0.37, 17.6, 5.92)
156
+ # diphtheria = st.sidebar.slider("Diphtheria Immunization (%)", 2, 99, 82)
157
+ # hiv_aids = st.sidebar.slider("HIV/AIDS Prevalence Rate", 0.1, 50.6, 1.74)
158
+ # gdp = st.sidebar.slider("GDP per Capita", 1.68, 119172.7, 6611.52)
159
+ # population = st.sidebar.slider("Population", 34, 1293859000, 10230850)
160
+ # thinness_1_19 = st.sidebar.slider("Thinness 1-19 years (%)", 0.1, 27.7, 4.83)
161
+ # thinness_5_9 = st.sidebar.slider("Thinness 5-9 years (%)", 0.1, 28.6, 4.86)
162
+ # income_composition = st.sidebar.slider("Income Composition of Resources", 0.0, 0.948, 0.63)
163
+ # schooling = st.sidebar.slider("Schooling (Years)", 0.0, 20.7, 11.99)
164
+
165
+ # if st.button("Predict Life Expectancy"):
166
+ # features = np.array([[year, status, adult_mortality, infant_deaths, alcohol, percentage_expenditure,
167
+ # hepatitis_b, measles, bmi, under_five_deaths, polio, total_expenditure,
168
+ # diphtheria, hiv_aids, gdp, population, thinness_1_19, thinness_5_9,
169
+ # income_composition, schooling]])
170
+
171
+ # prediction = model.predict(features)[0]
172
+
173
+ # st.markdown(f'<div class="result-box">Predicted Life Expectancy: <b>{prediction:.2f} years</b></div>',
174
+ # unsafe_allow_html=True)