adityaprakash17
commited on
Commit
·
b57ff37
1
Parent(s):
f164f46
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#importing the libraries
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import seaborn as sns
|
6 |
+
df = pd.read_csv('insurance.csv')
|
7 |
+
#changing categorical variables to numerical
|
8 |
+
df['sex'] = df['sex'].map({'male':0,'female':1})
|
9 |
+
df['smoker'] = df['smoker'].map({'yes':1,'no':0})
|
10 |
+
df['region'] = df['region'].map({'southwest':0,'southeast':1,'northwest':2,'northeast':3})
|
11 |
+
|
12 |
+
#Train Test Split
|
13 |
+
from sklearn.model_selection import train_test_split
|
14 |
+
x_train, x_test, y_train, y_test = train_test_split(df.drop('charges',axis=1), df['charges'], test_size=0.2, random_state=42)
|
15 |
+
|
16 |
+
#decision tree regressor
|
17 |
+
from sklearn.tree import DecisionTreeRegressor
|
18 |
+
dtree = DecisionTreeRegressor()
|
19 |
+
#model training
|
20 |
+
dtree.fit(x_train,y_train)
|
21 |
+
#model accuracy
|
22 |
+
# dtree.score(x_train,y_train)
|
23 |
+
|
24 |
+
def func(a, b, c, d, e, f):
|
25 |
+
|
26 |
+
|
27 |
+
x_test = [[a, b, c, d, e, f]]
|
28 |
+
result = dtree.predict(x_test)[0]
|
29 |
+
rounded_result = round(result, 2)
|
30 |
+
str="Your Medical Expenses could be: ₹"
|
31 |
+
str1="Thankyou🤗 for using our Model"
|
32 |
+
return f"{str}{rounded_result}\n\n{str1}"
|
33 |
+
|
34 |
+
import gradio as gr
|
35 |
+
|
36 |
+
demo = gr.Interface(
|
37 |
+
fn= func,
|
38 |
+
inputs=[
|
39 |
+
gr.Textbox(label="Enter Your Age", placeholder="Enter Your Age", elem_id="gender",type='text'),
|
40 |
+
gr.Textbox(label="Enter Your Gender", placeholder="Enter 0 for Male and 1 for Female", elem_id="gender",type='text'),
|
41 |
+
gr.Textbox(label="Enter Your BMI Index", placeholder="Enter BMI Index Value", elem_id="gender",type='text'),
|
42 |
+
gr.Textbox(label="Number of Children Covered by Health Insurance", placeholder="Enter Number of Children", elem_id="gender",type='text'),
|
43 |
+
gr.Textbox(label="Are You a Smoker?", placeholder="Enter 0 for NO and 1 for YES",elem_id="gender",type='text'),
|
44 |
+
gr.Textbox(label="Enter Your Region", placeholder="Enter value between 0-3", elem_id="gender",type='text'),
|
45 |
+
],
|
46 |
+
outputs='text',
|
47 |
+
theme=gr.themes.Soft(),
|
48 |
+
title="<h1 id=title-first> Welcome to HEALTHSURE <br> <span id=title-second>Predict Your Medical Cost Expenses here using a ML Model</span> </h1>",
|
49 |
+
description="<p id=desc>◾ Please Enter the Data in following way(Important)<br>◾ Gender: <span id=desc-info> Male=0 Female=1 </span><br> ◾ Smoker:<span id=desc-info> NO=0 YES=1 </span><br>◾ Region:<span id=desc-info> Southwest=0 Southeast=1 Northwest=2 Northeast=3 </span> <br><br>**Some Examples are given at bottom You can try them by clicking on it.<br>**Enter only Numeric Value",
|
50 |
+
css="""
|
51 |
+
.gradio-container {background-color: #eefdec}"
|
52 |
+
#gender { background-color : teal !important; }
|
53 |
+
#gender textarea {background-color: #ecf7fd; font-size : 15px; color : black;
|
54 |
+
font-weight : bold; !important;}
|
55 |
+
|
56 |
+
#desc {font-weight : bold; color : black !important;}
|
57 |
+
#desc-info{font-weight:normal;}
|
58 |
+
h1 {text-align : center; font-size: 40px !important;}
|
59 |
+
#title-first {color:black; !important;}
|
60 |
+
#title-second {color:green; font-size: 17px !important;}
|
61 |
+
#a-tag { color : white !important;}
|
62 |
+
|
63 |
+
#a-tag:hover {text-decoration : none !important;}
|
64 |
+
|
65 |
+
""",
|
66 |
+
|
67 |
+
examples=[[54, 0, 33.63, 1, 0, 2],[18, 1, 40.26, 0, 0, 1],[54, 1, 23, 3, 0, 0],[45, 0, 20.35, 3, 0, 1]]
|
68 |
+
|
69 |
+
)
|
70 |
+
|
71 |
+
|
72 |
+
demo.launch(inline=False)
|