Yashvj123 commited on
Commit
d3877e9
ยท
verified ยท
1 Parent(s): 5518ca2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -52
app.py CHANGED
@@ -5,72 +5,59 @@ import pickle
5
  # Load trained model
6
  model = pickle.load(open("life_expectancy_model.pkl", "rb"))
7
 
8
- # Custom CSS for styling
9
  st.markdown("""
10
  <style>
11
- body {
12
- background-color: #f5f5f5;
13
- }
14
  .stApp {
15
- background-color: #ffffff;
16
- border-radius: 15px;
17
- padding: 20px;
 
18
  }
19
- .prediction-box {
20
  background-color: #4CAF50;
21
  padding: 15px;
22
  border-radius: 10px;
23
  color: white;
24
  text-align: center;
25
- font-size: 24px;
26
  font-weight: bold;
27
  }
28
  </style>
29
  """, unsafe_allow_html=True)
30
 
31
- # App Title with Emoji
32
- st.title("๐ŸŒ Life Expectancy Prediction App")
33
- st.markdown("### ๐Ÿ“Š Predict the average life expectancy based on health and economic factors.")
34
-
35
- # Sidebar for Inputs
36
- st.sidebar.header("๐Ÿ”ข Enter Data Below")
37
- st.sidebar.markdown("Fill in the details to predict life expectancy.")
38
-
39
- # Input Fields in Sidebar
40
- year = st.sidebar.number_input("๐Ÿ“… Year", min_value=2000, max_value=2015, value=2008)
41
- status = st.sidebar.radio("๐ŸŒ Status", ["Developing", "Developed"])
42
- status = 1 if status == "Developed" else 0
43
-
44
- adult_mortality = st.sidebar.slider("โšฐ๏ธ Adult Mortality Rate", 1.0, 723.0, 144.0)
45
- infant_deaths = st.sidebar.slider("๐Ÿ‘ถ Infant Deaths", 0, 1800, 3)
46
- alcohol = st.sidebar.slider("๐Ÿท Alcohol Consumption", 0.01, 17.87, 4.55)
47
- percentage_expenditure = st.sidebar.slider("๐Ÿ’ฐ % Healthcare Expenditure", 0.0, 19479.91, 738.25)
48
- hepatitis_b = st.sidebar.slider("๐Ÿฆ  Hepatitis B Immunization (%)", 1, 99, 83)
49
- measles = st.sidebar.slider("๐Ÿค’ Measles Cases", 0, 212183, 2419)
50
- bmi = st.sidebar.slider("โš–๏ธ BMI", 1.0, 87.3, 38.3)
51
- under_five_deaths = st.sidebar.slider("โšฐ๏ธ Under-Five Deaths", 0, 2500, 4)
52
- polio = st.sidebar.slider("๐Ÿ’‰ Polio Immunization (%)", 3, 99, 82)
53
- total_expenditure = st.sidebar.slider("๐Ÿฅ Total Healthcare Expenditure (%)", 0.37, 17.6, 5.92)
54
- diphtheria = st.sidebar.slider("๐Ÿ’‰ Diphtheria Immunization (%)", 2, 99, 82)
55
- hiv_aids = st.sidebar.slider("๐Ÿฆ  HIV/AIDS Prevalence Rate", 0.1, 50.6, 1.74)
56
- gdp = st.sidebar.slider("๐Ÿ’ฐ GDP per Capita", 1.68, 119172.7, 6611.52)
57
- population = st.sidebar.slider("๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ฆ Population", 34, 1293859000, 10230850)
58
- thinness_1_19 = st.sidebar.slider("๐Ÿงโ€โ™‚๏ธ Thinness 1-19 years (%)", 0.1, 27.7, 4.83)
59
- thinness_5_9 = st.sidebar.slider("๐Ÿง Thinness 5-9 years (%)", 0.1, 28.6, 4.86)
60
- income_composition = st.sidebar.slider("๐Ÿ’ฐ Income Composition of Resources", 0.0, 0.948, 0.63)
61
- schooling = st.sidebar.slider("๐ŸŽ“ Schooling (Years)", 0.0, 20.7, 11.99)
62
-
63
- # Predict Button with Animation
64
  if st.button("๐Ÿ”ฎ Predict Life Expectancy"):
65
- with st.spinner("๐Ÿ” Analyzing data... Please wait!"):
66
- features = np.array([[year, status, adult_mortality, infant_deaths, alcohol, percentage_expenditure,
67
- hepatitis_b, measles, bmi, under_five_deaths, polio, total_expenditure,
68
- diphtheria, hiv_aids, gdp, population, thinness_1_19, thinness_5_9,
69
- income_composition, schooling]])
70
-
71
- prediction = model.predict(features)[0]
72
 
73
- # Displaying Results in a Styled Box
74
- st.markdown(f'<div class="prediction-box">๐Ÿ“Œ Predicted Life Expectancy: <b>{prediction:.2f} years</b></div>',
75
- unsafe_allow_html=True)
76
 
 
 
 
 
5
  # Load trained model
6
  model = pickle.load(open("life_expectancy_model.pkl", "rb"))
7
 
8
+ # Custom Styling for Clean UI
9
  st.markdown("""
10
  <style>
 
 
 
11
  .stApp {
12
+ background-color: #f8f9fa;
13
+ }
14
+ .title-container {
15
+ text-align: center;
16
  }
17
+ .result-box {
18
  background-color: #4CAF50;
19
  padding: 15px;
20
  border-radius: 10px;
21
  color: white;
22
  text-align: center;
23
+ font-size: 22px;
24
  font-weight: bold;
25
  }
26
  </style>
27
  """, unsafe_allow_html=True)
28
 
29
+ # App Title
30
+ st.markdown("<h1 class='title-container'>๐ŸŒ Life Expectancy Prediction</h1>", unsafe_allow_html=True)
31
+ st.markdown("#### Predict the life expectancy based on health and economic factors.")
32
+
33
+ # Two-column Layout for Better Readability
34
+ col1, col2 = st.columns(2)
35
+
36
+ with col1:
37
+ year = st.number_input("๐Ÿ“… Year", min_value=2000, max_value=2015, value=2008)
38
+ status = st.radio("๐ŸŒ Status", ["Developing", "Developed"], horizontal=True)
39
+ status = 1 if status == "Developed" else 0
40
+ adult_mortality = st.number_input("โšฐ๏ธ Adult Mortality Rate", min_value=1.0, max_value=723.0, value=144.0)
41
+ infant_deaths = st.number_input("๐Ÿ‘ถ Infant Deaths", min_value=0, max_value=1800, value=3)
42
+ alcohol = st.number_input("๐Ÿท Alcohol Consumption", min_value=0.01, max_value=17.87, value=4.55)
43
+ percentage_expenditure = st.number_input("๐Ÿ’ฐ % Healthcare Expenditure", min_value=0.0, max_value=19479.91, value=738.25)
44
+ hepatitis_b = st.number_input("๐Ÿฆ  Hepatitis B Immunization (%)", min_value=1, max_value=99, value=83)
45
+
46
+ with col2:
47
+ measles = st.number_input("๐Ÿค’ Measles Cases", min_value=0, max_value=212183, value=2419)
48
+ bmi = st.number_input("โš–๏ธ BMI", min_value=1.0, max_value=87.3, value=38.3)
49
+ under_five_deaths = st.number_input("โšฐ๏ธ Under-Five Deaths", min_value=0, max_value=2500, value=4)
50
+ polio = st.number_input("๐Ÿ’‰ Polio Immunization (%)", min_value=3, 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
+ schooling = st.number_input("๐ŸŽ“ Schooling (Years)", min_value=0.0, max_value=20.7, value=11.99)
53
+
54
+ # Predict Button
 
 
 
 
 
 
 
55
  if st.button("๐Ÿ”ฎ Predict Life Expectancy"):
56
+ features = np.array([[year, status, adult_mortality, infant_deaths, alcohol, percentage_expenditure,
57
+ hepatitis_b, measles, bmi, under_five_deaths, polio, hiv_aids, schooling]])
 
 
 
 
 
58
 
59
+ prediction = model.predict(features)[0]
 
 
60
 
61
+ # Display Result in a Stylish Box
62
+ st.markdown(f'<div class="result-box">๐Ÿ“Œ Predicted Life Expectancy: <b>{prediction:.2f} years</b></div>',
63
+ unsafe_allow_html=True)