kanneboinakumar's picture
Update app.py
07fcc22 verified
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()