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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -34
app.py CHANGED
@@ -5,40 +5,72 @@ import pickle
5
  # Load trained model
6
  model = pickle.load(open("life_expectancy_model.pkl", "rb"))
7
 
8
- # Streamlit UI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  st.title("๐ŸŒ Life Expectancy Prediction App")
 
10
 
11
- st.markdown("Enter the values below to predict the Life Expectancy.")
12
-
13
- # Input Fields with Proper Ranges
14
- year = st.number_input("Year", min_value=2000, max_value=2015, value=2008)
15
- status = st.selectbox("Status (0: Developing, 1: Developed)", [0, 1])
16
- adult_mortality = st.number_input("Adult Mortality Rate", min_value=1.0, max_value=723.0, value=144.0)
17
- infant_deaths = st.number_input("Infant Deaths", min_value=0, max_value=1800, value=3)
18
- alcohol = st.number_input("Alcohol Consumption", min_value=0.01, max_value=17.87, value=4.55)
19
- percentage_expenditure = st.number_input("Percentage Expenditure", min_value=0.0, max_value=19479.91, value=738.25)
20
- hepatitis_b = st.number_input("Hepatitis B Immunization (%)", min_value=1, max_value=99, value=83)
21
- measles = st.number_input("Measles Cases", min_value=0, max_value=212183, value=2419)
22
- bmi = st.number_input("BMI", min_value=1.0, max_value=87.3, value=38.3)
23
- under_five_deaths = st.number_input("Under-Five Deaths", min_value=0, max_value=2500, value=4)
24
- polio = st.number_input("Polio Immunization (%)", min_value=3, max_value=99, value=82)
25
- total_expenditure = st.number_input("Total Healthcare Expenditure (%)", min_value=0.37, max_value=17.6, value=5.92)
26
- diphtheria = st.number_input("Diphtheria Immunization (%)", min_value=2, max_value=99, value=82)
27
- hiv_aids = st.number_input("HIV/AIDS Prevalence Rate", min_value=0.1, max_value=50.6, value=1.74)
28
- gdp = st.number_input("GDP per Capita", min_value=1.68, max_value=119172.7, value=6611.52)
29
- population = st.number_input("Population", min_value=34, max_value=1293859000, value=10230850)
30
- thinness_1_19 = st.number_input("Thinness 1-19 years (%)", min_value=0.1, max_value=27.7, value=4.83)
31
- thinness_5_9 = st.number_input("Thinness 5-9 years (%)", min_value=0.1, max_value=28.6, value=4.86)
32
- income_composition = st.number_input("Income Composition of Resources", min_value=0.0, max_value=0.948, value=0.63)
33
- schooling = st.number_input("Schooling (Years)", min_value=0.0, max_value=20.7, value=11.99)
34
-
35
- # Predict button
36
- if st.button("Predict Life Expectancy"):
37
- features = np.array([[year, status, adult_mortality, infant_deaths, alcohol, percentage_expenditure,
38
- hepatitis_b, measles, bmi, under_five_deaths, polio, total_expenditure,
39
- diphtheria, hiv_aids, gdp, population, thinness_1_19, thinness_5_9,
40
- income_composition, schooling]])
41
-
42
- prediction = model.predict(features)[0]
 
 
 
 
 
43
 
44
- st.success(f"๐Ÿ“Œ **Predicted Life Expectancy: {prediction:.2f} years**")
 
 
 
 
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
+