File size: 2,507 Bytes
e664774
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
946bf7b
e664774
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import pickle

# Load pre-trained models
models = {}
with open('Logistic_Regression_model.pkl', 'rb') as f:
    models['Logistic Regression'] = pickle.load(f)

with open('Random_Forest_model.pkl', 'rb') as f:
    models['Random Forest'] = pickle.load(f)

def predict_kidney_stone(gravity, ph, osmo, cond, urea, calc):
    data = {'gravity': [gravity], 'ph': [ph], 'osmo': [osmo], 'cond': [cond], 'urea': [urea], 'calc': [calc]}  # Include 'calc' in the data
    test_df = pd.DataFrame(data)
    
    # Predict using the combined models
    y_pred_lr = models['Logistic Regression'].predict_proba(test_df)[:, 1]
    y_pred_rf = models['Random Forest'].predict_proba(test_df)[:, 1]

    combined_prediction = (y_pred_lr + y_pred_rf) / 2
    
    return combined_prediction[0]

# Streamlit app
import streamlit as st

st.title('Kidney Stone Detection 🧪')
st.write('This app predicts whether a kidney stone is present or not based on input values.')
st.image('https://www.health.com/thmb/vU7eqqoH-LmfHlX4WlPu9t-LyN8=/2000x0/filters:no_upscale():max_bytes(150000):strip_icc()/kindney-disease-causes-GettyImages-1257900987-03002a7b6e244dfaaecfacf4bae2f707.jpg', use_column_width=True)
st.write('Gravity: Indicates urine concentration; higher values increase stone risk.(1 - 1.1)')
st.write('pH: Measures urine acidity; extremes can promote specific stone types. (0-14)')
st.write('Osmo: Reflects urine solute concentration; higher values raise stone risk.(0-2000)')
st.write('Cond: Indicates urine ion concentration; higher values suggest increased stone risk.(0-50)')
st.write('Urea: Waste product from protein metabolism; high levels can raise stone risk.(0-1000)')
st.write('Calc: Essential mineral; excessive levels can increase certain stone types risk.(0-50)')


# Input form
gravity = st.number_input('Gravity', min_value=0.0, max_value=2.0, step=0.001, value=1.021)
ph = st.number_input('pH', min_value=0.0, max_value=14.0, step=0.1, value=4.91)
osmo = st.number_input('Osmo', min_value=0, max_value=2000, step=1, value=442)
cond = st.number_input('Cond', min_value=0.0, max_value=50.0, step=0.1, value=20.8)
urea = st.number_input('Urea', min_value=0, max_value=1000, step=1, value=398)
calc = st.number_input('Calc', min_value=0.0, max_value=50.0, step=1.0, value=6.63)

# Predict
if st.button('Predict'):
    prediction = predict_kidney_stone(gravity, ph, osmo, cond, urea, calc)
    st.write(f'Predicted Probability of Kidney Stone is: {prediction:.4f}%')