File size: 2,972 Bytes
0fd34c4
 
 
 
 
 
 
 
 
a061891
0fd34c4
 
a061891
0fd34c4
 
 
 
 
 
 
a061891
0fd34c4
d429b2d
a061891
0fd34c4
07fcc22
0fd34c4
a061891
 
0fd34c4
 
a061891
 
 
 
 
d429b2d
0fd34c4
d429b2d
 
 
 
 
 
 
 
 
 
0fd34c4
a061891
d429b2d
88bb0b5
d429b2d
 
cb7ba55
 
 
a061891
cb7ba55
 
 
 
 
 
 
 
a061891
cb7ba55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import streamlit as st
import joblib
import pandas as pd
import numpy as np

# Load Model 
model = joblib.load('Rf_model.joblib')
encoder = joblib.load('encoder_d.joblib')

# Custom CSS for styling
st.markdown("""
    <style>
        /* Title Styling */
        .main-title {
            background-color: #007BFF;
            padding: 10px;
            border-radius: 8px;
            color: white;
            text-align: center;
            font-size: 28px;
            margin-bottom: 30px;
        }

        /* App Background */
        .stApp {
            background-image: url('https://m.foolcdn.com/media/dubs/images/Getty_-_insurance_life_car_home_family_protect.width-880.jpg');
            background-size: cover;
            background-repeat: no-repeat;
            background-attachment: fixed;
        }

        /* Input Fields */
        .stNumberInput input, .stSelectbox div[data-baseweb="select"] {
            background-color: #f0f9ff !important;
            padding: 10px;
            border-radius: 8px;
        }

        /* Predict Button */
        div.stButton > button {
            background-color: #28a745;
            color: white;
            font-size: 18px;
            width: 50%;
            margin: auto;
            display: block;
            border-radius: 8px;
        }

        /* Output Result */
        .result-box {
            background-color: lightpink;
            border-left: 6px solid #28a745;
            padding: 15px;
            font-size: 20px;
            border-radius: 10px;
            text-align: center;
            margin-top: 30px;
        }
    </style>
""", unsafe_allow_html=True)

# Streamlit app
def main():
    st.markdown('<div class="main-title">Insurance Cost Prediction App</div>', unsafe_allow_html=True)

    # Inputs arranged in 3 columns (2 rows layout)
    col1, col2, col3 = st.columns(3)
    with col1:
        age = st.number_input("Age", min_value=18, max_value=100, value=30)
        bmi = st.number_input("BMI", min_value=10.0, max_value=50.0, value=25.0)

    with col2:
        sex = st.selectbox("Sex", encoder["sex"].classes_)
        sex = encoder['sex'].transform([sex])[0]
        children = st.number_input("Children", min_value=0, max_value=10, value=0)

    with col3:
        smoker = st.selectbox("Smoker", encoder['smoker'].classes_)
        smoker = encoder['smoker'].transform([smoker])[0]
        region = st.selectbox("Region", encoder['region'].classes_)
        region = encoder['region'].transform([region])[0]

    # Predict button
    if st.button("Predict Insurance Cost"):
        values = [age, sex, bmi, children, smoker, region]
        predict = round(model.predict([values])[0], 2)

        st.markdown(f"""
            <div class='result-box'>
                💰 <strong>Estimated Insurance Cost:</strong> <span style='color: #28a745;'>${predict}</span>
            </div>
        """, unsafe_allow_html=True)

if __name__ == "__main__":
    main()