Yashvj123 commited on
Commit
7e74074
·
verified ·
1 Parent(s): d15ec34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -31
app.py CHANGED
@@ -2,15 +2,19 @@ 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.markdown("""
8
  <style>
9
- .stApp {
10
- background-color: #f8f9fa;
11
- }
12
  .title-container {
13
  text-align: center;
 
 
 
 
 
14
  }
15
  .result-box {
16
  background-color: #4CAF50;
@@ -22,41 +26,45 @@ st.markdown("""
22
  font-weight: bold;
23
  margin-top: 20px;
24
  }
 
 
 
 
 
 
25
  </style>
26
  """, unsafe_allow_html=True)
27
 
 
28
  st.markdown("<h1 class='title-container'>Life Expectancy Prediction</h1>", unsafe_allow_html=True)
29
- st.markdown("### Enter the required details to get the predicted life expectancy.")
30
-
31
- # Two-column Layout
32
- col1, col2 = st.columns(2)
33
-
34
- with col1:
35
- year = st.number_input("Year", min_value=2000, max_value=2015, value=2008)
36
- status = st.radio("Status", ["Developing", "Developed"], horizontal=True)
37
- status = 1 if status == "Developed" else 0
38
- adult_mortality = st.number_input("Adult Mortality Rate", min_value=1.0, max_value=723.0, value=144.0)
39
- infant_deaths = st.number_input("Infant Deaths", min_value=0, max_value=1800, value=3)
40
- alcohol = st.number_input("Alcohol Consumption", min_value=0.01, max_value=17.87, value=4.55)
41
- percentage_expenditure = st.number_input("Percentage Expenditure", min_value=0.0, max_value=19479.91, value=738.25)
42
- hepatitis_b = st.number_input("Hepatitis B Immunization (%)", min_value=1, max_value=99, value=83)
43
- measles = st.number_input("Measles Cases", min_value=0, max_value=212183, value=2419)
44
- bmi = st.number_input("BMI", min_value=1.0, max_value=87.3, value=38.3)
45
 
46
- with col2:
47
- under_five_deaths = st.number_input("Under-Five Deaths", min_value=0, max_value=2500, value=4)
48
- polio = st.number_input("Polio Immunization (%)", min_value=3, max_value=99, value=82)
49
- total_expenditure = st.number_input("Total Healthcare Expenditure (%)", min_value=0.37, max_value=17.6, value=5.92)
50
- diphtheria = st.number_input("Diphtheria Immunization (%)", min_value=2, max_value=99, value=82)
51
- hiv_aids = st.number_input("HIV/AIDS Prevalence Rate", min_value=0.1, max_value=50.6, value=1.74)
52
- gdp = st.number_input("GDP per Capita", min_value=1.68, max_value=119172.7, value=6611.52)
53
- population = st.number_input("Population", min_value=34, max_value=1293859000, value=10230850)
54
- thinness_1_19 = st.number_input("Thinness 1-19 years (%)", min_value=0.1, max_value=27.7, value=4.83)
55
- thinness_5_9 = st.number_input("Thinness 5-9 years (%)", min_value=0.1, max_value=28.6, value=4.86)
56
- income_composition = st.number_input("Income Composition of Resources", min_value=0.0, max_value=0.948, value=0.63)
57
- schooling = st.number_input("Schooling (Years)", min_value=0.0, max_value=20.7, value=11.99)
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
 
60
  if st.button("Predict Life Expectancy"):
61
  features = np.array([[year, status, adult_mortality, infant_deaths, alcohol, percentage_expenditure,
62
  hepatitis_b, measles, bmi, under_five_deaths, polio, total_expenditure,
@@ -65,5 +73,6 @@ if st.button("Predict Life Expectancy"):
65
 
66
  prediction = model.predict(features)[0]
67
 
 
68
  st.markdown(f'<div class="result-box">Predicted Life Expectancy: <b>{prediction:.2f} years</b></div>',
69
  unsafe_allow_html=True)
 
2
  import numpy as np
3
  import pickle
4
 
5
+ # Load trained model
6
  model = pickle.load(open("life_expectancy_model.pkl", "rb"))
7
 
8
+ # Apply CSS for Better UI
9
  st.markdown("""
10
  <style>
 
 
 
11
  .title-container {
12
  text-align: center;
13
+ font-size: 36px;
14
+ font-weight: bold;
15
+ background: -webkit-linear-gradient(45deg, #ff7e5f, #feb47b);
16
+ -webkit-background-clip: text;
17
+ -webkit-text-fill-color: transparent;
18
  }
19
  .result-box {
20
  background-color: #4CAF50;
 
26
  font-weight: bold;
27
  margin-top: 20px;
28
  }
29
+ .sidebar-title {
30
+ font-size: 22px;
31
+ font-weight: bold;
32
+ color: #ff7e5f;
33
+ text-align: center;
34
+ }
35
  </style>
36
  """, unsafe_allow_html=True)
37
 
38
+ # Attractive Title
39
  st.markdown("<h1 class='title-container'>Life Expectancy Prediction</h1>", unsafe_allow_html=True)
40
+ st.markdown("### Enter the required details in the sidebar to get the predicted life expectancy.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
+ # Sidebar Inputs
43
+ st.sidebar.markdown("<h2 class='sidebar-title'>Input Features</h2>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
44
 
45
+ year = st.sidebar.slider("Year", 2000, 2015, 2008)
46
+ status = st.sidebar.radio("Status", ["Developing", "Developed"], horizontal=True)
47
+ status = 1 if status == "Developed" else 0
48
+ adult_mortality = st.sidebar.slider("Adult Mortality Rate", 1, 723, 144)
49
+ infant_deaths = st.sidebar.slider("Infant Deaths", 0, 1800, 3)
50
+ alcohol = st.sidebar.slider("Alcohol Consumption", 0.01, 17.87, 4.55)
51
+ percentage_expenditure = st.sidebar.slider("Percentage Expenditure", 0.0, 19479.91, 738.25)
52
+ hepatitis_b = st.sidebar.slider("Hepatitis B Immunization (%)", 1, 99, 83)
53
+ measles = st.sidebar.slider("Measles Cases", 0, 212183, 2419)
54
+ bmi = st.sidebar.slider("BMI", 1.0, 87.3, 38.3)
55
+ under_five_deaths = st.sidebar.slider("Under-Five Deaths", 0, 2500, 4)
56
+ polio = st.sidebar.slider("Polio Immunization (%)", 3, 99, 82)
57
+ total_expenditure = st.sidebar.slider("Total Healthcare Expenditure (%)", 0.37, 17.6, 5.92)
58
+ diphtheria = st.sidebar.slider("Diphtheria Immunization (%)", 2, 99, 82)
59
+ hiv_aids = st.sidebar.slider("HIV/AIDS Prevalence Rate", 0.1, 50.6, 1.74)
60
+ gdp = st.sidebar.slider("GDP per Capita", 1.68, 119172.7, 6611.52)
61
+ population = st.sidebar.slider("Population", 34, 1293859000, 10230850)
62
+ thinness_1_19 = st.sidebar.slider("Thinness 1-19 years (%)", 0.1, 27.7, 4.83)
63
+ thinness_5_9 = st.sidebar.slider("Thinness 5-9 years (%)", 0.1, 28.6, 4.86)
64
+ income_composition = st.sidebar.slider("Income Composition of Resources", 0.0, 0.948, 0.63)
65
+ schooling = st.sidebar.slider("Schooling (Years)", 0.0, 20.7, 11.99)
66
 
67
+ # Predict Button
68
  if st.button("Predict Life Expectancy"):
69
  features = np.array([[year, status, adult_mortality, infant_deaths, alcohol, percentage_expenditure,
70
  hepatitis_b, measles, bmi, under_five_deaths, polio, total_expenditure,
 
73
 
74
  prediction = model.predict(features)[0]
75
 
76
+ # Display Result in a Stylish Box
77
  st.markdown(f'<div class="result-box">Predicted Life Expectancy: <b>{prediction:.2f} years</b></div>',
78
  unsafe_allow_html=True)