-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathapp.py
65 lines (46 loc) · 2.06 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from pycaret.regression import load_model, predict_model
import streamlit as st
import pandas as pd
import numpy as np
model = load_model('deployment_28042020')
def predict(model, input_df):
predictions_df = predict_model(estimator=model, data=input_df)
predictions = predictions_df['Label'][0]
return predictions
def run():
from PIL import Image
image = Image.open('logo.png')
image_hospital = Image.open('hospital.jpg')
st.image(image,use_column_width=False)
add_selectbox = st.sidebar.selectbox(
"How would you like to predict?",
("Online", "Batch"))
st.sidebar.info('This app is created to predict patient hospital charges')
st.sidebar.success('https://www.pycaret.org')
st.sidebar.image(image_hospital)
st.title("Insurance Charges Prediction App")
if add_selectbox == 'Online':
age = st.number_input('Age', min_value=1, max_value=100, value=25)
sex = st.selectbox('Sex', ['male', 'female'])
bmi = st.number_input('BMI', min_value=10, max_value=50, value=10)
children = st.selectbox('Children', [0,1,2,3,4,5,6,7,8,9,10])
if st.checkbox('Smoker'):
smoker = 'yes'
else:
smoker = 'no'
region = st.selectbox('Region', ['southwest', 'northwest', 'northeast', 'southeast'])
output=""
input_dict = {'age' : age, 'sex' : sex, 'bmi' : bmi, 'children' : children, 'smoker' : smoker, 'region' : region}
input_df = pd.DataFrame([input_dict])
if st.button("Predict"):
output = predict(model=model, input_df=input_df)
output = '$' + str(output)
st.success('The output is {}'.format(output))
if add_selectbox == 'Batch':
file_upload = st.file_uploader("Upload csv file for predictions", type=["csv"])
if file_upload is not None:
data = pd.read_csv(file_upload)
predictions = predict_model(estimator=model,data=data)
st.write(predictions)
if __name__ == '__main__':
run()