high77 commited on
Commit
3fc3fa4
·
verified ·
1 Parent(s): 976adf7

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
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")