Spaces:
Runtime error
Runtime error
mport streamlit as st | |
import pandas as pd | |
import joblib | |
# Load the pre-trained model | |
# Define the input widgets | |
age = st.slider('Age', 18, 99, 25) | |
gender = st.selectbox('Gender', ['Male', 'Female']) | |
smoker = st.selectbox('Smoker', ['Yes', 'No']) | |
region = st.selectbox('Region', ['Northeast', 'Northwest', 'Southeast', 'Southwest']) | |
bmi = st.number_input('BMI', min_value=10.0, max_value=50.0, step=0.1) | |
# Define a function to make the prediction | |
def predict(age, gender, smoker, region, bmi): | |
data = pd.DataFrame({'age': [age], | |
'sex': [gender], | |
'smoker': [smoker], | |
'region': [region], | |
'bmi': [bmi]}) | |
prediction = model.predict(data)[0] | |
return prediction | |
# Call the predict function and display the result | |
if st.button('Predict'): | |
result = predict(age, gender, smoker, region, bmi) | |
st.write('The predicted insurance cost is $', round(result, 2)) |