Rathapoom commited on
Commit
6da89d6
·
verified ·
1 Parent(s): 1cab071

Update app(backup).py

Browse files
Files changed (1) hide show
  1. app(backup).py +33 -15
app(backup).py CHANGED
@@ -2,13 +2,20 @@ import streamlit as st
2
  import pandas as pd
3
  import plotly.graph_objs as go
4
 
5
- # Step 1: Load the cleaned sheet "Clean TH avg rise BMD" and display it
6
- def load_clean_bmd_data(file_path):
7
- sheet_clean_th_avg_rise = 'Clean TH avg rise BMD'
8
- df_clean_th_avg_rise = pd.read_excel(file_path, sheet_name=sheet_clean_th_avg_rise)
 
 
 
 
 
 
 
9
 
10
  # Select relevant columns: Drug names and BMD percentage increases
11
- df_cleaned = df_clean_th_avg_rise[['Unnamed: 0', '1st', '2nd', '3rd', '4th', '5th', '6th', '8th', '10th']]
12
 
13
  # Rename the first column to 'Drug'
14
  df_cleaned.columns = ['Drug', '1st', '2nd', '3rd', '4th', '5th', '6th', '8th', '10th']
@@ -95,9 +102,9 @@ def calculate_tscore_from_bmd(bmd_patient, c_avg, c_sd):
95
  return (bmd_patient - c_avg) / c_sd
96
 
97
  # Main function to load data, run the application, and plot results with T-score labels
98
- def main_with_separate_tables(file_path, bmd_patient, tscore_patient, C_avg_lunar, C_sd_lunar, selected_drugs):
99
- # Step 1: Load and clean BMD data from the Excel sheet
100
- df_bmd_data = load_clean_bmd_data(file_path)
101
 
102
  # Step 2: Adjust constants based on the patient's data
103
  c_avg_new, c_sd_new = adjust_constants(bmd_patient, tscore_patient, C_avg_lunar, C_sd_lunar)
@@ -115,9 +122,13 @@ def main_with_separate_tables(file_path, bmd_patient, tscore_patient, C_avg_luna
115
  def main():
116
  st.title("BMD and T-score Prediction Tool")
117
 
 
 
 
 
118
  # Input patient data
119
- bmd_patient = st.number_input("Initial BMD", min_value=0.0, max_value=2.0, value=0.635, step=0.001)
120
- tscore_patient = st.number_input("Initial T-score", min_value=-5.0, max_value=2.0, value=-2.5, step=0.01)
121
 
122
  # Drug options
123
  drug_options = ['Teriparatide', 'Teriparatide + Denosumab', 'Denosumab', 'Denosumab + Teriparatide',
@@ -128,9 +139,16 @@ def main():
128
  # Add option to select multiple drugs
129
  selected_drugs = st.multiselect("Select drugs to compare", drug_options)
130
 
131
- # Set C_avg and C_sd for Lunar device (example values)
132
- C_avg_lunar = 0.95 # Example: Average BMD for Total Hip from Excel (Lunar)
133
- C_sd_lunar = 0.12 # Example: SD for Total Hip (Lunar)
 
 
 
 
 
 
 
134
 
135
  # Example file path
136
  file_path = "BMD constant calculator.xlsx"
@@ -141,7 +159,7 @@ def main():
141
  else:
142
  # Run prediction and plot results
143
  if st.button("Predict"):
144
- main_with_separate_tables(file_path, bmd_patient, tscore_patient, C_avg_lunar, C_sd_lunar, selected_drugs)
145
 
146
  if __name__ == "__main__":
147
- main()
 
2
  import pandas as pd
3
  import plotly.graph_objs as go
4
 
5
+ # Step 1: Load the cleaned sheet based on the selected site
6
+ def load_clean_bmd_data(file_path, site):
7
+ sheet_name = ''
8
+ if site == 'Total Hip':
9
+ sheet_name = 'Clean TH avg rise BMD'
10
+ elif site == 'Femoral Neck':
11
+ sheet_name = 'clean FN avg rise BMD'
12
+ elif site == 'Lumbar Spine (L1-L4)':
13
+ sheet_name = 'clean LS avg rise BMD'
14
+
15
+ df_clean_bmd_data = pd.read_excel(file_path, sheet_name=sheet_name)
16
 
17
  # Select relevant columns: Drug names and BMD percentage increases
18
+ df_cleaned = df_clean_bmd_data[['Unnamed: 0', '1st', '2nd', '3rd', '4th', '5th', '6th', '8th', '10th']]
19
 
20
  # Rename the first column to 'Drug'
21
  df_cleaned.columns = ['Drug', '1st', '2nd', '3rd', '4th', '5th', '6th', '8th', '10th']
 
102
  return (bmd_patient - c_avg) / c_sd
103
 
104
  # Main function to load data, run the application, and plot results with T-score labels
105
+ def main_with_separate_tables(file_path, bmd_patient, tscore_patient, C_avg_lunar, C_sd_lunar, selected_drugs, site):
106
+ # Step 1: Load and clean BMD data from the selected site (Total Hip, Femoral Neck, Lumbar Spine)
107
+ df_bmd_data = load_clean_bmd_data(file_path, site)
108
 
109
  # Step 2: Adjust constants based on the patient's data
110
  c_avg_new, c_sd_new = adjust_constants(bmd_patient, tscore_patient, C_avg_lunar, C_sd_lunar)
 
122
  def main():
123
  st.title("BMD and T-score Prediction Tool")
124
 
125
+ # Site options (Total Hip, Femoral Neck, Lumbar Spine)
126
+ site_options = ['Total Hip', 'Femoral Neck', 'Lumbar Spine (L1-L4)']
127
+ site = st.selectbox("Select site", site_options)
128
+
129
  # Input patient data
130
+ bmd_patient = st.number_input("Initial BMD", min_value=0.0, max_value=2.0, value=0.635, step=0.001, format="%.3f")
131
+ tscore_patient = st.number_input("Initial T-score", min_value=-5.0, max_value=2.0, value=-2.5, step=0.01, format="%.2f")
132
 
133
  # Drug options
134
  drug_options = ['Teriparatide', 'Teriparatide + Denosumab', 'Denosumab', 'Denosumab + Teriparatide',
 
139
  # Add option to select multiple drugs
140
  selected_drugs = st.multiselect("Select drugs to compare", drug_options)
141
 
142
+ # Set constants for each site
143
+ if site == 'Total Hip':
144
+ C_avg_lunar = 0.95 # Example: Average BMD for Total Hip from Excel (Lunar)
145
+ C_sd_lunar = 0.12 # Example: SD for Total Hip (Lunar)
146
+ elif site == 'Femoral Neck':
147
+ C_avg_lunar = 0.905 # Example: Average BMD for Femoral Neck from Excel (Lunar)
148
+ C_sd_lunar = 0.116 # Example: SD for Femoral Neck (Lunar)
149
+ elif site == 'Lumbar Spine (L1-L4)':
150
+ C_avg_lunar = 1.097 # Example: Average BMD for Lumbar Spine (L1-L4) from Excel (Lunar)
151
+ C_sd_lunar = 0.128 # Example: SD for Lumbar Spine (L1-L4) (Lunar)
152
 
153
  # Example file path
154
  file_path = "BMD constant calculator.xlsx"
 
159
  else:
160
  # Run prediction and plot results
161
  if st.button("Predict"):
162
+ main_with_separate_tables(file_path, bmd_patient, tscore_patient, C_avg_lunar, C_sd_lunar, selected_drugs, site)
163
 
164
  if __name__ == "__main__":
165
+ main()