| |
|
|
| import gradio as gr |
| import pandas as pd |
| import pickle |
| import numpy as np |
|
|
| |
| |
| |
| with open("insurance_model.pkl", "rb") as f: |
| model = pickle.load(f) |
|
|
| |
| |
| |
| def bmi_category(bmi): |
| if bmi < 18.5: |
| return "Underweight" |
| elif bmi < 25: |
| return "Normal" |
| elif bmi < 30: |
| return "Overweight" |
| else: |
| return "Obese" |
|
|
| |
| |
| |
| def predict_charges(age, bmi, children, sex, smoker, region): |
| |
| |
| bmi_cat = bmi_category(bmi) |
| |
| |
| input_df = pd.DataFrame([[ |
| age, bmi, children, sex, smoker, region, bmi_cat |
| ]], |
| columns=["age", "bmi", "children", "sex", "smoker", "region", "bmi_category"]) |
| |
| |
| prediction = model.predict(input_df)[0] |
| |
| return f"Predicted Insurance Charges: ${prediction:,.2f}" |
|
|
| |
| |
| |
| inputs = [ |
| gr.Number(label="Age", value=30, precision=0), |
| gr.Number(label="BMI", value=25.0, precision=1), |
| gr.Number(label="Number of Children", value=0, precision=0), |
| gr.Dropdown(["male", "female"], label="Sex"), |
| gr.Dropdown(["yes", "no"], label="Smoker"), |
| gr.Dropdown(["southwest", "southeast", "northwest", "northeast"], label="Region") |
| ] |
|
|
| app = gr.Interface( |
| fn=predict_charges, |
| inputs=inputs, |
| outputs="text", |
| title="Medical Insurance Charges Predictor", |
| description="Enter patient details to predict expected medical insurance charges." |
| ) |
|
|
| if __name__ == "__main__": |
| |
| app.launch(share=True) |
|
|