import streamlit as st import pandas as pd import joblib # Load model and scaler (assumed to be in root directory) model = joblib.load("tuned_xgboost_model.pkl") scaler = joblib.load("scaler.pkl") 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. --- ''', unsafe_allow_html=True ) # Collect 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"]) # Auto-derived features gender_encoded = 1 if gender == "Male" else 0 gender_male = gender_encoded pulse_pressure = sbp - dbp # Create input DataFrame with exactly the features expected by the model input_data = 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 }]) # Run prediction if st.button("Predict Hemoglobin Level"): try: input_scaled = scaler.transform(input_data) 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}")