Lokiiparihar commited on
Commit
b650599
·
1 Parent(s): 56095af

Upload app code and model

Browse files
Files changed (4) hide show
  1. Dockerfile +11 -0
  2. app.py +38 -0
  3. model_xgboost.pkl +3 -0
  4. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ FROM python:3.10-slim
3
+
4
+ WORKDIR /app
5
+
6
+ COPY requirements.txt .
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import numpy as np
4
+ import joblib
5
+
6
+ # Load your trained model
7
+ model = joblib.load("model_xgboost.pkl")
8
+
9
+ def predict(age, sex, bmi, children, smoker, region):
10
+ sex = 1 if sex == "male" else 0
11
+ smoker_bin = 1 if smoker == "yes" else 0
12
+
13
+ region_northwest = 1 if region == "northwest" else 0
14
+ region_southeast = 1 if region == "southeast" else 0
15
+ region_southwest = 1 if region == "southwest" else 0
16
+
17
+ bmi_smoker = bmi * smoker_bin
18
+ obese = 1 if bmi >= 30 else 0
19
+
20
+ input_vector = np.array([[age, sex, bmi, children, smoker_bin,
21
+ region_northwest, region_southeast, region_southwest,
22
+ bmi_smoker, obese]])
23
+
24
+ prediction = model.predict(input_vector)[0]
25
+ return f"${prediction:,.2f}"
26
+
27
+ inputs = [
28
+ gr.Slider(18, 65, value=35, label="Age"),
29
+ gr.Radio(["male", "female"], label="Sex"),
30
+ gr.Slider(15.0, 55.0, step=0.1, value=30.0, label="BMI"),
31
+ gr.Slider(0, 5, step=1, value=1, label="Number of Children"),
32
+ gr.Radio(["yes", "no"], label="Smoker"),
33
+ gr.Dropdown(["northwest", "southeast", "southwest", "northeast"], label="Region"),
34
+ ]
35
+
36
+ output = gr.Textbox(label="Predicted Insurance Charges")
37
+
38
+ gr.Interface(fn=predict, inputs=inputs, outputs=output, title="Medical Insurance Cost Predictor").launch()
model_xgboost.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:02aee364eaec3c9ffbf797aed71d75166c5479ac5446276cbda18f7177ba2942
3
+ size 119262
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ xgboost
3
+ numpy
4
+ joblib