Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +51 -39
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,52 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 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 |
-
st.
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
import numpy as np
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# Load model and scaler
|
| 8 |
+
MODEL_PATH = os.path.join(os.path.dirname(__file__), "model", "xgb_model.joblib")
|
| 9 |
+
SCALER_PATH = os.path.join(os.path.dirname(__file__), "model", "scaler.joblib")
|
| 10 |
+
|
| 11 |
+
model = joblib.load(MODEL_PATH)
|
| 12 |
+
scaler = joblib.load(SCALER_PATH)
|
| 13 |
+
|
| 14 |
+
st.title("Hemoglobin Level Predictor")
|
| 15 |
+
|
| 16 |
+
st.markdown(
|
| 17 |
+
"""
|
| 18 |
+
### Developed by Dr. Vinod Kumar Yata's research group
|
| 19 |
+
School of Allied and Healthcare Sciences, Malla Reddy University, Hyderabad, India
|
| 20 |
+
|
| 21 |
+
---
|
| 22 |
+
⚠️ **Warning**:
|
| 23 |
+
This is an experimental tool and should not be used for medical diagnosis.
|
| 24 |
+
Always consult a licensed healthcare provider for medical advice.
|
| 25 |
+
---
|
| 26 |
+
"""
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Input fields
|
| 30 |
+
age = st.number_input("Age", min_value=0, max_value=120, value=30)
|
| 31 |
+
gender = st.selectbox("Gender", options=["Male", "Female"])
|
| 32 |
+
o2_saturation = st.slider("O2 Saturation (%)", min_value=50.0, max_value=100.0, value=98.0)
|
| 33 |
+
bp_systolic = st.number_input("Systolic BP", min_value=50, max_value=200, value=120)
|
| 34 |
+
bp_diastolic = st.number_input("Diastolic BP", min_value=30, max_value=130, value=80)
|
| 35 |
+
respiratory_rate = st.number_input("Respiratory Rate (breaths/min)", min_value=5, max_value=60, value=18)
|
| 36 |
+
|
| 37 |
+
# Map gender to numeric
|
| 38 |
+
gender_num = 1 if gender == "Male" else 0
|
| 39 |
+
|
| 40 |
+
input_df = pd.DataFrame([{
|
| 41 |
+
"Age": age,
|
| 42 |
+
"Gender": gender_num,
|
| 43 |
+
"O2_Saturation": o2_saturation,
|
| 44 |
+
"BP_Systolic": bp_systolic,
|
| 45 |
+
"BP_Diastolic": bp_diastolic,
|
| 46 |
+
"Respiratory_Rate": respiratory_rate
|
| 47 |
+
}])
|
| 48 |
+
|
| 49 |
+
if st.button("Predict Hemoglobin Level"):
|
| 50 |
+
input_scaled = scaler.transform(input_df)
|
| 51 |
+
prediction = model.predict(input_scaled)[0]
|
| 52 |
+
st.success(f"Predicted Hemoglobin Level: {prediction:.2f} g/dL")
|