Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import pickle
|
| 4 |
+
|
| 5 |
+
# Load the trained model
|
| 6 |
+
with open('catboost_model.pkl', 'rb') as model_file:
|
| 7 |
+
regressor = pickle.load(model_file)
|
| 8 |
+
|
| 9 |
+
# Define the prediction function
|
| 10 |
+
def predict_insurance_cost(age, sex, bmi, children, smoker, region):
|
| 11 |
+
# Create a DataFrame from the input data
|
| 12 |
+
input_data = pd.DataFrame(
|
| 13 |
+
[[age, sex, bmi, children, smoker, region]],
|
| 14 |
+
columns=['age', 'sex', 'bmi', 'children', 'smoker', 'region']
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
# Make prediction
|
| 18 |
+
prediction = regressor.predict(input_data)
|
| 19 |
+
return f'The insurance cost is USD {prediction[0]:.2f}'
|
| 20 |
+
|
| 21 |
+
# Set up the Gradio interface
|
| 22 |
+
inputs = [
|
| 23 |
+
gr.Slider(minimum=18, maximum=100,step=1, value=31, label="Age"),
|
| 24 |
+
gr.Radio(choices=['Female', 'Male']),
|
| 25 |
+
gr.Slider(minimum=10.0, maximum=50.0, step=0.1, value=25.74, label="BMI"),
|
| 26 |
+
gr.Slider(minimum=0, maximum=10, value=0,step=1, label="Children"),
|
| 27 |
+
gr.Radio(choices=['NO', 'Yes']),
|
| 28 |
+
gr.Dropdown(choices=['Southwest', 'Southeast', 'Northwest', 'Northeast'], label="Region (Southwest, Southeast, Northwest, Northeast)")
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
output = gr.Textbox(label="Predicted Insurance Cost")
|
| 32 |
+
|
| 33 |
+
# Create the Gradio interface
|
| 34 |
+
gr.Interface(fn=predict_insurance_cost, inputs=inputs, outputs=output, title="Medical Insurance Cost Predictor", description="Predict the insurance cost based on various parameters.").launch()
|