adityaprakash17's picture
Update app.py
e14c248
#importing the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv('insurance.csv')
#changing categorical variables to numerical
df['sex'] = df['sex'].map({'male':0,'female':1})
df['smoker'] = df['smoker'].map({'yes':1,'no':0})
df['region'] = df['region'].map({'southwest':0,'southeast':1,'northwest':2,'northeast':3})
#Train Test Split
from sklearn.model_selection import train_test_split
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)
#decision tree regressor
#from sklearn.tree import DecisionTreeRegressor
#dtree = DecisionTreeRegressor()
#model training
#dtree.fit(x_train,y_train)
from sklearn.ensemble import RandomForestRegressor
rf = RandomForestRegressor()
#model training
rf.fit(x_train.values,y_train.values)
def func(a, b, c, d, e, f):
x_test = [[a, b, c, d, e, f]]
result = rf.predict(x_test)[0]
rounded_result = round(result, 2)
str="Your Medical Expenses could be: ₹"
str1="Thankyou🤗 for using our Model"
return f"{str}{rounded_result}\n\n{str1}"
import gradio as gr
demo = gr.Interface(
fn= func,
inputs=[
gr.Textbox(label="Enter Your Age", placeholder="Enter Your Age", elem_id="gender",type='text'),
gr.Textbox(label="Enter Your Gender", placeholder="Enter 0 for Male and 1 for Female", elem_id="gender",type='text'),
gr.Textbox(label="Enter Your BMI Index", placeholder="Enter BMI Index Value", elem_id="gender",type='text'),
gr.Textbox(label="Number of Children Covered by Health Insurance", placeholder="Enter Number of Children", elem_id="gender",type='text'),
gr.Textbox(label="Are You a Smoker?", placeholder="Enter 0 for NO and 1 for YES",elem_id="gender",type='text'),
gr.Textbox(label="Enter Your Region", placeholder="Enter value between 0-3", elem_id="gender",type='text'),
],
outputs='text',
theme=gr.themes.Soft(),
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>",
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",
css="""
.gradio-container {background-color: #eefdec}"
#gender { background-color : teal !important; }
#gender textarea {background-color: #ecf7fd; font-size : 15px; color : black;
font-weight : bold; !important;}
#desc {font-weight : bold; color : black !important;}
#desc-info{font-weight:normal;}
h1 {text-align : center; font-size: 40px !important;}
#title-first {color:black; !important;}
#title-second {color:green; font-size: 17px !important;}
#a-tag { color : white !important;}
#a-tag:hover {text-decoration : none !important;}
""",
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]]
)
demo.launch(inline=False)