Update app.py
Browse files
app.py
CHANGED
|
@@ -2,10 +2,8 @@ import streamlit as st
|
|
| 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 |
-
# Custom Styling for Clean UI
|
| 9 |
st.markdown("""
|
| 10 |
<style>
|
| 11 |
.stApp {
|
|
@@ -22,42 +20,50 @@ st.markdown("""
|
|
| 22 |
text-align: center;
|
| 23 |
font-size: 22px;
|
| 24 |
font-weight: bold;
|
|
|
|
| 25 |
}
|
| 26 |
</style>
|
| 27 |
""", unsafe_allow_html=True)
|
| 28 |
|
| 29 |
-
|
| 30 |
-
st.markdown("
|
| 31 |
-
st.markdown("#### Predict the life expectancy based on health and economic factors.")
|
| 32 |
|
| 33 |
-
# Two-column Layout
|
| 34 |
col1, col2 = st.columns(2)
|
| 35 |
|
| 36 |
with col1:
|
| 37 |
-
year = st.number_input("
|
| 38 |
-
status = st.radio("
|
| 39 |
status = 1 if status == "Developed" else 0
|
| 40 |
-
adult_mortality = st.number_input("
|
| 41 |
-
infant_deaths = st.number_input("
|
| 42 |
-
alcohol = st.number_input("
|
| 43 |
-
percentage_expenditure = st.number_input("
|
| 44 |
-
hepatitis_b = st.number_input("
|
|
|
|
|
|
|
| 45 |
|
| 46 |
with col2:
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
hiv_aids = st.number_input("
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
features = np.array([[year, status, adult_mortality, infant_deaths, alcohol, percentage_expenditure,
|
| 57 |
-
hepatitis_b, measles, bmi, under_five_deaths, polio,
|
|
|
|
|
|
|
| 58 |
|
| 59 |
prediction = model.predict(features)[0]
|
| 60 |
|
| 61 |
-
|
| 62 |
-
st.markdown(f'<div class="result-box">๐ Predicted Life Expectancy: <b>{prediction:.2f} years</b></div>',
|
| 63 |
unsafe_allow_html=True)
|
|
|
|
| 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 {
|
|
|
|
| 20 |
text-align: center;
|
| 21 |
font-size: 22px;
|
| 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,
|
| 63 |
+
diphtheria, hiv_aids, gdp, population, thinness_1_19, thinness_5_9,
|
| 64 |
+
income_composition, schooling]])
|
| 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)
|