test / app.py
hyjn's picture
Update app.py
e040c91
# Medical Cost charges Predictor
import pandas as pd
import gradio as gr
import pickle
# Load the model file
with open('medical_cost_model.pkl', 'rb') as f:
model = pickle.load(f)
# The predicion workhorse
def predict(*args):
data = pd.DataFrame({
'sex': [args[0]],
'smoker': [args[1]],
'region': [args[2]],
'age': [args[3]],
'bmi': [args[4]],
'children': [args[5]]
})
return '<strong>charges: ' + str(model.predict(data)[0]) + '</strong>'
# User Interface
number = gr.components.Number
radio = gr.components.Radio
dropdown = gr.components.Dropdown
with gr.Blocks() as service:
gr.Markdown(value='<h4>Medical Cost charges Predictor</h4>Powered by <b>Magic canAI</b>')
# User inputs
sex = radio(['female', 'male'], value="female", label="sex")
smoker = radio(['no', 'yes'], value="no", label="smoker")
region = dropdown(['northeast', 'northwest', 'southeast', 'southwest'], value="northeast", label="region")
age = number(value=39, label="age")
bmi = number(value=30.5118, label="bmi")
children = number(value=1, label="children")
# The output
output = gr.Markdown(label="Prediction")
# Command controls
check_btn = gr.components.Button("Predict")
check_btn.click(fn=predict, inputs=[sex, smoker, region, age, bmi, children], outputs=output)
# Launch the app
service.launch(debug=True)
###