Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import joblib
|
| 5 |
-
import numpy as np
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
st.title("Hemoglobin Level Predictor")
|
| 11 |
|
|
@@ -23,25 +22,32 @@ st.markdown(
|
|
| 23 |
unsafe_allow_html=True
|
| 24 |
)
|
| 25 |
|
|
|
|
| 26 |
age = st.number_input("Age", min_value=0, max_value=120, value=30)
|
| 27 |
gender = st.selectbox("Gender", options=["Male", "Female"])
|
| 28 |
-
o2_saturation = st.slider("
|
| 29 |
bp_systolic = st.number_input("Systolic BP", min_value=50, max_value=200, value=120)
|
| 30 |
bp_diastolic = st.number_input("Diastolic BP", min_value=30, max_value=130, value=80)
|
| 31 |
respiratory_rate = st.number_input("Respiratory Rate (breaths/min)", min_value=5, max_value=60, value=18)
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
|
|
|
|
| 35 |
input_df = pd.DataFrame([{
|
| 36 |
"Age": age,
|
| 37 |
-
"
|
| 38 |
-
"
|
| 39 |
"BP_Systolic": bp_systolic,
|
| 40 |
-
"
|
| 41 |
-
"Respiratory_Rate": respiratory_rate
|
|
|
|
| 42 |
}])
|
| 43 |
|
| 44 |
if st.button("Predict Hemoglobin Level"):
|
|
|
|
| 45 |
input_scaled = scaler.transform(input_df)
|
|
|
|
| 46 |
prediction = model.predict(input_scaled)[0]
|
| 47 |
st.success(f"Predicted Hemoglobin Level: {prediction:.2f} g/dL")
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import joblib
|
|
|
|
| 4 |
|
| 5 |
+
# Load model and scaler with correct filenames
|
| 6 |
+
model = joblib.load("model/tuned_xgboost_model.pkl")
|
| 7 |
+
scaler = joblib.load("model/scaler.pkl")
|
| 8 |
|
| 9 |
st.title("Hemoglobin Level Predictor")
|
| 10 |
|
|
|
|
| 22 |
unsafe_allow_html=True
|
| 23 |
)
|
| 24 |
|
| 25 |
+
# Input fields (ensure the feature names match your trained model's expected features)
|
| 26 |
age = st.number_input("Age", min_value=0, max_value=120, value=30)
|
| 27 |
gender = st.selectbox("Gender", options=["Male", "Female"])
|
| 28 |
+
o2_saturation = st.slider("Oxygen Saturation (%)", min_value=50.0, max_value=100.0, value=98.0)
|
| 29 |
bp_systolic = st.number_input("Systolic BP", min_value=50, max_value=200, value=120)
|
| 30 |
bp_diastolic = st.number_input("Diastolic BP", min_value=30, max_value=130, value=80)
|
| 31 |
respiratory_rate = st.number_input("Respiratory Rate (breaths/min)", min_value=5, max_value=60, value=18)
|
| 32 |
|
| 33 |
+
# Map gender to expected model encoding
|
| 34 |
+
gender_male = 1 if gender == "Male" else 0
|
| 35 |
+
gender_female = 1 - gender_male # if needed for one-hot features
|
| 36 |
|
| 37 |
+
# Build input dataframe with exact feature names your model expects
|
| 38 |
input_df = pd.DataFrame([{
|
| 39 |
"Age": age,
|
| 40 |
+
"Gender_Encoded": gender_male, # or "Gender_Male" if that’s the column name
|
| 41 |
+
"OxygenSaturation(%)": o2_saturation, # exact feature name from training
|
| 42 |
"BP_Systolic": bp_systolic,
|
| 43 |
+
"DBP": bp_diastolic,
|
| 44 |
+
"Respiratory_Rate": respiratory_rate,
|
| 45 |
+
# Add any other features your model needs here, with correct names!
|
| 46 |
}])
|
| 47 |
|
| 48 |
if st.button("Predict Hemoglobin Level"):
|
| 49 |
+
# Scale inputs
|
| 50 |
input_scaled = scaler.transform(input_df)
|
| 51 |
+
# Predict using model
|
| 52 |
prediction = model.predict(input_scaled)[0]
|
| 53 |
st.success(f"Predicted Hemoglobin Level: {prediction:.2f} g/dL")
|