XPMaster's picture
Update app.py
1152ce8
raw
history blame contribute delete
No virus
1.56 kB
import gradio as gr
import pickle
import sklearn
import pandas as pd
regions = ['southwest', 'southeast', 'northwest', 'northeast']
def predict(age,sex,bmi,children,smoker,region):
loaded_model = pickle.load(open("insurance_predict.pkl", 'rb'))
p = loaded_model.predict(pd.DataFrame(data={'age':[int(age)],'sex':[sex],'bmi':[int(bmi)],'children':[int(children)],'smoker':[smoker],'region':[region]}))
sp = str(p).split(".")
p = sp[0][1:]+'.'+sp[1][:2]
return gr.Textbox.update("{0}$πŸ’΅".format(p))
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown("# πŸ“„ Premium insurance price prediction\nPredict how much a client should be charged for getting medical insurance at your company 🏒")
with gr.Box():
with gr.Row():
sex = gr.Dropdown(['male','female'],label='Sex',value='male',interactive=True)
smoker = gr.Dropdown(['no','yes'],label='Is smoker?',value='no',interactive=True)
age = gr.Slider(minimum=18,maximum=100,value=18,label='age',interactive=True,step=1)
children = gr.Slider(minimum=0,maximum=10,value=0,label='No. of children',interactive=True,step=1)
with gr.Row():
bmi = gr.Slider(minimum=15,maximum=100,value=18,label='BMI',interactive=True,step=1)
region = gr.Dropdown(regions,label='From which region?',value='southwest',interactive=True)
with gr.Row():
temp = gr.Textbox("...",label='Price prediction πŸ“ˆ',interactive=False)
btn = gr.Button(value="Predict")
btn.click(predict, inputs=[age,sex,bmi,children,smoker,region], outputs=temp)
demo.launch()