File size: 2,424 Bytes
853e9d1
3fc3fa4
 
 
 
9b5cb80
a573ec3
 
 
3fc3fa4
9b5cb80
3fc3fa4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b5cb80
3fc3fa4
a573ec3
 
 
 
9b5cb80
a573ec3
3fc3fa4
 
a573ec3
 
 
 
3fc3fa4
9b5cb80
3fc3fa4
 
a573ec3
 
 
 
 
 
 
 
 
3fc3fa4
 
9b5cb80
3fc3fa4
a573ec3
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import streamlit as st
import pandas as pd
import joblib
import os

# Adjust paths based on container directory structure
BASE_DIR = os.path.dirname(os.path.dirname(__file__))  # one level up from src/
MODEL_PATH = os.path.join(BASE_DIR, "Hb_predict", "tuned_xgboost_model.pkl")
SCALER_PATH = os.path.join(BASE_DIR, "Hb_predict", "scaler.pkl")

# Load model and scaler
model = joblib.load(MODEL_PATH)
scaler = joblib.load(SCALER_PATH)

st.title("Hemoglobin Level Predictor")

st.markdown(
    """
    ### Developed by Dr. Vinod Kumar Yata's research group  
    School of Allied and Healthcare Sciences, Malla Reddy University, Hyderabad, India

    ---
    ⚠️ **Warning**:  
    This is an experimental tool and should not be used for medical diagnosis.  
    Always consult a licensed healthcare provider for medical advice.
    ---
    """
)

# User inputs
age = st.number_input("Age", min_value=0, max_value=120, value=30)
sbp = st.number_input("Systolic Blood Pressure (SBP)", min_value=50, max_value=200, value=120)
dbp = st.number_input("Diastolic Blood Pressure (DBP)", min_value=30, max_value=130, value=80)
heart_rate = st.number_input("Heart Rate", min_value=30, max_value=200, value=75)
respiratory_rate = st.number_input("Respiratory Rate", min_value=5, max_value=60, value=18)
temperature_c = st.number_input("Temperature (°C)", min_value=30.0, max_value=45.0, value=36.5, format="%.1f")
oxygen_saturation = st.slider("Oxygen Saturation (%)", min_value=50.0, max_value=100.0, value=98.0)
gender = st.selectbox("Gender", options=["Male", "Female"])

# Calculate derived features
gender_encoded = 1 if gender == "Male" else 0
gender_male = gender_encoded
pulse_pressure = sbp - dbp

# Prepare input DataFrame matching model feature names exactly
input_df = pd.DataFrame([{
    "Age": age,
    "SBP": sbp,
    "DBP": dbp,
    "HeartRate": heart_rate,
    "RespiratoryRate": respiratory_rate,
    "TemperatureC": temperature_c,
    "OxygenSaturation(%)": oxygen_saturation,
    "Gender_Encoded": gender_encoded,
    "Pulse_Pressure": pulse_pressure,
    "Gender_Male": gender_male
}])

# Predict on button click
if st.button("Predict Hemoglobin Level"):
    try:
        input_scaled = scaler.transform(input_df)
        prediction = model.predict(input_scaled)[0]
        st.success(f"Predicted Hemoglobin Level: {prediction:.2f} g/dL")
    except Exception as e:
        st.error(f"Prediction failed: {e}")