Update appbackup.py
Browse files- appbackup.py +24 -9
appbackup.py
CHANGED
@@ -1,12 +1,14 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import plotly.graph_objs as go
|
4 |
|
5 |
# Constants from linear regression
|
6 |
REGRESSION_CONSTANTS = {
|
7 |
-
'
|
8 |
-
'
|
9 |
-
'
|
10 |
}
|
11 |
|
12 |
# Load medication data
|
@@ -35,7 +37,6 @@ def generate_predictions(medication_data, site, bmd, mu, sigma):
|
|
35 |
for year in row.index[1:-1]: # Skip 'Medication' and 'Site' columns
|
36 |
if not pd.isna(row[year]):
|
37 |
percentage_increase = row[year]
|
38 |
-
# BMD calculated using initial BMD (from user input)
|
39 |
predicted_bmd = bmd * (1 + percentage_increase)
|
40 |
predicted_tscore = calculate_tscore(predicted_bmd, mu, sigma)
|
41 |
|
@@ -83,6 +84,22 @@ def display_results(predictions, site):
|
|
83 |
def main():
|
84 |
st.title("BMD and T-score Prediction Tool")
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
# Input patient data
|
87 |
bmd_patient = st.number_input(
|
88 |
"Initial BMD",
|
@@ -90,17 +107,15 @@ def main():
|
|
90 |
value=0.800, step=0.001,
|
91 |
format="%.3f"
|
92 |
)
|
93 |
-
site_options = ['FN', 'TH', 'LS']
|
94 |
-
site = st.selectbox("Select Region (Site)", site_options)
|
95 |
|
96 |
# Load constants and medication data
|
97 |
-
constants = REGRESSION_CONSTANTS[site]
|
98 |
medication_data = load_medication_data()
|
99 |
-
|
|
|
100 |
# Generate and display predictions
|
101 |
if st.button("Predict"):
|
102 |
predictions = generate_predictions(medication_data, site, bmd_patient, constants['mu'], constants['sigma'])
|
103 |
-
display_results(predictions,
|
104 |
|
105 |
if __name__ == "__main__":
|
106 |
main()
|
|
|
1 |
+
#file_path = "cleaned_bmd_medication_data.xlsx"
|
2 |
+
|
3 |
import streamlit as st
|
4 |
import pandas as pd
|
5 |
import plotly.graph_objs as go
|
6 |
|
7 |
# Constants from linear regression
|
8 |
REGRESSION_CONSTANTS = {
|
9 |
+
'Femoral Neck': {'mu': 0.916852, 'sigma': 0.120754},
|
10 |
+
'Total Hip': {'mu': 0.955439, 'sigma': 0.125406},
|
11 |
+
'Lumbar spine (L1-L4)': {'mu': 1.131649, 'sigma': 0.139618},
|
12 |
}
|
13 |
|
14 |
# Load medication data
|
|
|
37 |
for year in row.index[1:-1]: # Skip 'Medication' and 'Site' columns
|
38 |
if not pd.isna(row[year]):
|
39 |
percentage_increase = row[year]
|
|
|
40 |
predicted_bmd = bmd * (1 + percentage_increase)
|
41 |
predicted_tscore = calculate_tscore(predicted_bmd, mu, sigma)
|
42 |
|
|
|
84 |
def main():
|
85 |
st.title("BMD and T-score Prediction Tool")
|
86 |
|
87 |
+
# DEXA Machine Selection
|
88 |
+
dexa_machine = st.selectbox("DEXA Machine", ["LUNAR"])
|
89 |
+
|
90 |
+
# Gender Selection
|
91 |
+
gender = st.selectbox("Gender", ["Female"])
|
92 |
+
|
93 |
+
# Location (Site) Selection with Mapping
|
94 |
+
site_mapping = {
|
95 |
+
'Lumbar spine (L1-L4)': 'LS',
|
96 |
+
'Femoral Neck': 'FN',
|
97 |
+
'Total Hip': 'TH'
|
98 |
+
}
|
99 |
+
site_options = list(site_mapping.keys())
|
100 |
+
selected_site = st.selectbox("Select Region (Site)", site_options)
|
101 |
+
site = site_mapping[selected_site] # Map to the actual value in the dataset
|
102 |
+
|
103 |
# Input patient data
|
104 |
bmd_patient = st.number_input(
|
105 |
"Initial BMD",
|
|
|
107 |
value=0.800, step=0.001,
|
108 |
format="%.3f"
|
109 |
)
|
|
|
|
|
110 |
|
111 |
# Load constants and medication data
|
|
|
112 |
medication_data = load_medication_data()
|
113 |
+
constants = REGRESSION_CONSTANTS.get(selected_site, {})
|
114 |
+
|
115 |
# Generate and display predictions
|
116 |
if st.button("Predict"):
|
117 |
predictions = generate_predictions(medication_data, site, bmd_patient, constants['mu'], constants['sigma'])
|
118 |
+
display_results(predictions, selected_site)
|
119 |
|
120 |
if __name__ == "__main__":
|
121 |
main()
|