TJA-AKI / app.py
1449648578Zyc's picture
Update app.py
474fa3d
raw
history blame contribute delete
No virus
4.55 kB
import streamlit as st
import pandas as pd
import pickle
import streamlit as st
from streamlit.type_util import data_frame_to_bytes
from streamlit_shap import st_shap
import shap
import numpy as np
def xyz(input_value):
return input_value + 42
model = pickle.load(open('xgb_model', 'rb'))
predictor = model
new_title = '<p style="font-family:sans-serif;font-size: 30px;">Risk prediction of Postoperative <b>Acute Kidney Injury</b> following <b>Total Joint Arthroplasty</b></p>'
st.markdown(new_title, unsafe_allow_html=True)
a_options = {"Tumors of bone and soft tissue": 1,"Fracture of bone": 2,"Degenerative changes of the joints or Rheumatoid arthritis": 3}
b_options = {"Resident Surgeon": 1,"Attending Surgeon": 2,"Consultant Surgeon": 3,}
def abc():
with st.form(key='form_parameters'):
st.markdown('### Causes of joint replacement')
st.markdown('---')
a = st.selectbox('Causes of joint replacement ', list(a_options.keys()))
a_value = a_options.get(a, 0)
st.markdown('---')
st.markdown('### Professional title of the chief surgeon')
st.markdown('---')
b = st.selectbox('Professional title of the chief surgeon', list(b_options.keys()))
b_value = b_options.get(b, 0)
st.markdown('---')
st.markdown('### Laboratory Values')
st.markdown('---')
c = st.number_input('Cystatin C (mg/L) [normal range: 0.53 - 0.95 mg/L]')
d = st.number_input('Lactate dehydrogenase (U/L) [normal range: 140-280 U/L]')
Hemoglobin = st.number_input('Hemoglobin (g/L) [normal range: 120-180g/L]')
e = st.number_input('Uric acid(μmol/L) [normal range: 150-428μmol/L]')
Fibrinogen = st.number_input('Fibrinogen (g/L) [normal range: 2.0-4.0g/L]')
st.markdown('---')
st.markdown('### Preoperative vital signs')
st.markdown('---')
f = st.number_input('Systolic blood pressure (mmHg)')
st.markdown('---')
st.markdown('### Intraoperative variables (per 5 minutes)')
st.markdown('---')
ig = st.number_input('Intraoperative blood loss (ml/kg)')
ih_list = st.text_area('Intraoperative pulse (bpm) [separate values with commas]').split(',')
ih_list = [float(x.strip()) for x in ih_list if x.strip()]
ih = sum(ih_list) / len(ih_list) if ih_list else None
intraoperative_f_list = st.text_area('Intraoperative systolic blood pressure (mmHg) [separate values with commas]').split(',')
intraoperative_f_list = [float(x.strip()) for x in intraoperative_f_list if x.strip()]
intraoperative_f = np.std(intraoperative_f_list) if intraoperative_f_list else None
i_list = st.text_area('Intraoperative oxygen saturation (%) [separate values with commas]').split(',')
i_list = [float(x.strip()) for x in i_list if x.strip()]
i = np.std(i_list) if i_list else None
st.markdown('---')
submitted = st.form_submit_button('Predict')
return c, f, Hemoglobin, ig, e, ih, b_value, a_value, d, intraoperative_f, i, Fibrinogen, submitted
def defg(c, f, Hemoglobin, ig, e, ih, b_value, a_value, d, intraoperative_f, i, Fibrinogen, submitted):
data_inf = {'CYS':c,'SBP': f,'HB': Hemoglobin,'Intra_Blood Loss': ig,'UA': e,'Intra_mean_pulse': ih,'The title of surgeons': b_value,'Causes of joint replacement': a_value,'LDH': d,'Intra_SBP_sd': intraoperative_f,'Intra_SPO2_sd': i,'FIB': Fibrinogen,}
data_inf = pd.DataFrame([data_inf])
if submitted:
y_pred_inf = predictor.predict_proba(data_inf)
value = y_pred_inf[0, 1]
with st.container():
st.write('### The possibility of AKI is \n'+ str(value))
st.write('*Threshold is 0.005*')
st.markdown('---')
with st.container():
st.write('## SHAP force plot for this patient')
feature_names = ['CYS', 'SBP', 'HB', 'Intra_Blood Loss', 'UA','Intra_mean_pulse', 'The title of surgeons', 'Causes of joint replacement', 'LDH', 'Intra_SBP_sd', 'Intra_SPO2_sd', 'FIB']
import shap
explainer = shap.TreeExplainer(predictor)
single_datapoint = data_inf
shap_values_single = explainer.shap_values(single_datapoint)
st_shap(shap.force_plot(explainer.expected_value, shap_values_single, single_datapoint), height=400, width=1000)
c, f, Hemoglobin, ig, e, ih, b_value, a_value, d, intraoperative_f, i, Fibrinogen, submitted = abc()
defg(c, f, Hemoglobin, ig, e, ih, b_value, a_value, d, intraoperative_f, i, Fibrinogen, submitted)