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(""" """, unsafe_allow_html=True) # Streamlit app def main(): st.markdown('
Insurance Cost Prediction App
', 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"""
💰 Estimated Insurance Cost: ${predict}
""", unsafe_allow_html=True) if __name__ == "__main__": main()