Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,67 +3,58 @@ import pandas as pd
|
|
3 |
import streamlit as st
|
4 |
|
5 |
|
6 |
-
EDU_DICT = {'Preschool': 1,
|
7 |
-
'1st-4th': 2,
|
8 |
-
'5th-6th': 3,
|
9 |
-
'7th-8th': 4,
|
10 |
-
'9th': 5,
|
11 |
-
'10th': 6,
|
12 |
-
'11th': 7,
|
13 |
-
'12th': 8,
|
14 |
-
'HS-grad': 9,
|
15 |
-
'Some-college': 10,
|
16 |
-
'Assoc-voc': 11,
|
17 |
-
'Assoc-acdm': 12,
|
18 |
-
'Bachelors': 13,
|
19 |
-
'Masters': 14,
|
20 |
-
'Prof-school': 15,
|
21 |
-
'Doctorate': 16
|
22 |
-
}
|
23 |
-
|
24 |
model = joblib.load('model.joblib')
|
25 |
unique_values = joblib.load('unique_values.joblib')
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
32 |
unique_sex = unique_values["sex"]
|
33 |
-
|
34 |
-
|
|
|
35 |
|
36 |
def main():
|
37 |
-
st.title("
|
38 |
|
39 |
with st.form("questionaire"):
|
40 |
-
age = st.slider("Age", min_value=
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
50 |
|
51 |
# clicked==True only when the button is clicked
|
52 |
-
clicked = st.form_submit_button("Predict
|
53 |
if clicked:
|
54 |
result=model.predict(pd.DataFrame({"age": [age],
|
55 |
-
"
|
56 |
-
"
|
57 |
-
"
|
58 |
-
"
|
59 |
-
"
|
60 |
-
"
|
|
|
|
|
61 |
"sex": [sex],
|
62 |
-
"
|
63 |
-
"
|
64 |
# Show prediction
|
65 |
-
result = '
|
66 |
-
st.success("Your prediction
|
67 |
|
68 |
# Run main()
|
69 |
if __name__ == "__main__":
|
|
|
3 |
import streamlit as st
|
4 |
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
model = joblib.load('model.joblib')
|
7 |
unique_values = joblib.load('unique_values.joblib')
|
8 |
|
9 |
+
unique_age = unique_values["age"]
|
10 |
+
unique_anaemia = unique_values["anaemia"]
|
11 |
+
unique_creatinine_phosphokinase = unique_values["creatinine_phosphokinase"]
|
12 |
+
unique_diabetes = unique_values["relationship"]
|
13 |
+
unique_ejection_fraction = unique_values["ejection_fraction"]
|
14 |
+
unique_high_blood_pressure = unique_values["high_blood_pressure"]
|
15 |
+
unique_platelets = unique_values["platelets"]
|
16 |
+
unique_serum_creatinine = unique_values["serum_creatinine"]
|
17 |
+
unique_serum_sodium = unique_values["serum_sodium"]
|
18 |
unique_sex = unique_values["sex"]
|
19 |
+
unique_smoking = unique_values["smoking"]
|
20 |
+
unique_time = unique_values["time"]
|
21 |
+
|
22 |
|
23 |
def main():
|
24 |
+
st.title("Predict death rates from heart failure")
|
25 |
|
26 |
with st.form("questionaire"):
|
27 |
+
age = st.slider("Age", min_value=0, max_value=100)
|
28 |
+
anaemia = st.selectbox("anaemia", options= unique_anaemia)
|
29 |
+
creatinine_phosphokinase = st.slider("creatinine_phosphokinase", min_value=0, max_value=100)
|
30 |
+
diabetes = st.selectbox("diabetes", options=unique_diabetes)
|
31 |
+
ejection_fraction = st.slider("ejection_fraction", min_value=0, max_value=100)
|
32 |
+
high_blood_pressure = st.selectbox("high_blood_pressure", options= unique_high_blood_pressure)
|
33 |
+
platelets = st.slider("platelets", min_value=0, max_value=100)
|
34 |
+
serum_creatinine = st.slider("serum_creatinine", min_value=0, max_value=100)
|
35 |
+
serum_sodium = st.slider("serum_sodium", min_value=1, max_value=100)
|
36 |
+
sex = st.selectbox("sex", options= unique_sex)
|
37 |
+
smoking = st.slider("smoking",options= unique_smoking)
|
38 |
+
time= st.slider("time", options= unique_time)
|
39 |
|
40 |
# clicked==True only when the button is clicked
|
41 |
+
clicked = st.form_submit_button("Predict death rates")
|
42 |
if clicked:
|
43 |
result=model.predict(pd.DataFrame({"age": [age],
|
44 |
+
"anaemia": [anaemia],
|
45 |
+
"creatinine_phosphokinase": [creatinine_phosphokinase],
|
46 |
+
"diabetes": [diabetes],
|
47 |
+
"ejection_fraction": [ejection_fraction],
|
48 |
+
"high_blood_pressure": [high_blood_pressure],
|
49 |
+
"platelets": [platelets],
|
50 |
+
"serum_creatinine": [serum_creatinine],
|
51 |
+
"serum_sodium ": [serum_sodium ],
|
52 |
"sex": [sex],
|
53 |
+
"smoking": [smoking],
|
54 |
+
"time": [time]}))
|
55 |
# Show prediction
|
56 |
+
result = '1' if result[0] == 1 else '0'
|
57 |
+
st.success("Your prediction death is ", result)
|
58 |
|
59 |
# Run main()
|
60 |
if __name__ == "__main__":
|