-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo1app.py
52 lines (37 loc) · 1.85 KB
/
demo1app.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
from pycaret.regression import load_model, predict_model
import streamlit as st
import pandas as pd
import numpy as np
model = load_model('insurance-pipeline-aws', platform = 'aws', authentication= {'bucket' : 'pycaret-test'})
def predict(model, input_df):
predictions_df = predict_model(estimator=model, data=input_df)
predictions = predictions_df['Label'][0]
return predictions
def run():
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.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])
smoker = 'yes' if st.checkbox('Smoker') else 'no'
region = st.selectbox('Region', ['southwest', 'northwest', 'northeast', 'southeast'])
output=""
input_df = pd.DataFrame([{'age' : age, 'sex' : sex, 'bmi' : bmi, 'children' : children, 'smoker' : smoker, 'region' : region}])
if st.button("Predict"):
output = predict(model=model, input_df=input_df)
output = '$' + str(int(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()