Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,65 +1,41 @@
|
|
1 |
import joblib
|
2 |
import pandas as pd
|
|
|
3 |
|
4 |
|
5 |
-
EDU_DICT = {'Preschool': 1,
|
6 |
-
'1st-4th': 2,
|
7 |
-
'5th-6th': 3,
|
8 |
-
'7th-8th': 4,
|
9 |
-
'9th': 5,
|
10 |
-
'10th': 6,
|
11 |
-
'11th': 7,
|
12 |
-
'12th': 8,
|
13 |
-
'HS-grad': 9,
|
14 |
-
'Some-college': 10,
|
15 |
-
'Assoc-voc': 11,
|
16 |
-
'Assoc-acdm': 12,
|
17 |
-
'Bachelors': 13,
|
18 |
-
'Masters': 14,
|
19 |
-
'Prof-school': 15,
|
20 |
-
'Doctorate': 16
|
21 |
-
}
|
22 |
|
23 |
-
model =
|
24 |
-
unique_values =
|
25 |
|
26 |
-
unique_class = unique_values["workclass"]
|
27 |
-
unique_education = unique_values["education"]
|
28 |
-
unique_marital_status = unique_values["marital.status"]
|
29 |
-
unique_relationship = unique_values["relationship"]
|
30 |
-
unique_occupation = unique_values["occupation"]
|
31 |
unique_sex = unique_values["sex"]
|
32 |
-
|
33 |
-
|
|
|
|
|
34 |
|
35 |
def main():
|
36 |
-
st.title("
|
37 |
|
38 |
with st.form("questionaire"):
|
39 |
-
age =
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
sex = # user's input
|
47 |
-
hours_per_week = # user's input
|
48 |
-
native_country = # user's input
|
49 |
|
50 |
# clicked==True only when the button is clicked
|
51 |
-
clicked = st.form_submit_button("Predict
|
52 |
if clicked:
|
53 |
result=model.predict(pd.DataFrame({"age": [age],
|
54 |
-
"workclass": [workclass],
|
55 |
-
"education": [EDU_DICT[education]],
|
56 |
-
"marital.status": [Marital_Status],
|
57 |
-
"occupation": [occupation],
|
58 |
-
"relationship": [relationship],
|
59 |
-
"race": [race],
|
60 |
"sex": [sex],
|
61 |
-
"
|
62 |
-
"
|
63 |
-
|
|
|
|
|
|
|
|
|
64 |
|
65 |
# Run main()
|
|
|
1 |
import joblib
|
2 |
import pandas as pd
|
3 |
+
import streamlit as st
|
4 |
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
model = joblib.load('model.joblib')
|
8 |
+
unique_values = joblib.load('unique_values.joblib')
|
9 |
|
|
|
|
|
|
|
|
|
|
|
10 |
unique_sex = unique_values["sex"]
|
11 |
+
unique_smoker = unique_values["smoker"]
|
12 |
+
unique_region = unique_values["region"]
|
13 |
+
|
14 |
+
|
15 |
|
16 |
def main():
|
17 |
+
st.title("medical expenses")
|
18 |
|
19 |
with st.form("questionaire"):
|
20 |
+
age = st.slider("Age", min_value =10,max_value=100)
|
21 |
+
sex = st.selectbox("Sex", options=unique_sex)
|
22 |
+
bmi = st.slider("Bmi",min_value=10,max_value=100)
|
23 |
+
children = st.slider("Children", min_value=10,max_value=100)
|
24 |
+
smoker = st.selectbox("Smoker", options=unique_smoker)
|
25 |
+
region = st.selectbox("Region",options=unique_region)
|
26 |
+
|
|
|
|
|
|
|
27 |
|
28 |
# clicked==True only when the button is clicked
|
29 |
+
clicked = st.form_submit_button("Predict medical expenses")
|
30 |
if clicked:
|
31 |
result=model.predict(pd.DataFrame({"age": [age],
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
"sex": [sex],
|
33 |
+
"bmi": [bmi],
|
34 |
+
"children": [children],
|
35 |
+
"smoker": [smoker],
|
36 |
+
"region": [region]}))
|
37 |
+
st.success("You predict medical expenses is" +result)
|
38 |
+
if __name__ == "__main__":
|
39 |
+
main()
|
40 |
|
41 |
# Run main()
|