Spaces:
Sleeping
Sleeping
Download src/streamlit_app.py from Ceee91/IntegProg_PerfTask: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/Ceee91/IntegProg_PerfTask/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/Ceee91/IntegProg_PerfTask/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/Ceee91/IntegProg_PerfTask/resolve/main/src/streamlit_app.py
1.15 kB
| import streamlit as st | |
| import joblib | |
| import numpy as np | |
| # Load the saved model and scaler | |
| model = joblib.load("src/medical_model.pkl") | |
| scaler = joblib.load("src/scaler.pkl") | |
| st.title("Medical Insurance Cost Predictor") | |
| st.write("Enter your details to estimate insurance charges.") | |
| # User Inputs | |
| age = st.number_input("Age", min_value=18, max_value=100, value=25) | |
| bmi = st.number_input("BMI", min_value=10.0, max_value=60.0, value=22.0) | |
| children = st.slider("Number of Children", 0, 5, 0) | |
| smoker = st.selectbox("Do you smoke?", ["Yes", "No"]) | |
| sex = st.selectbox("Gender", ["Male", "Female"]) | |
| # Map inputs to match the model's training format | |
| smoker_val = 1 if smoker == "Yes" else 0 | |
| sex_val = 1 if sex == "Male" else 0 | |
| # (Note: For simplicity, we assume region 'Southwest' as default here) | |
| # For full accuracy, you'd add region radio buttons matching your get_dummies columns. | |
| features = np.array([[age, sex_val, bmi, children, smoker_val, 0, 0, 0]]) | |
| features_scaled = scaler.transform(features) | |
| if st.button("Predict Charges"): | |
| prediction = model.predict(features_scaled) | |
| st.success(f"Estimated Insurance Cost: ${prediction[0]:,.2f}") |