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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -38,13 +38,13 @@ def calculate_bmd_increase(baseline_bmd, percentage_increase):
38
  return baseline_bmd * (1 + percentage_increase)
39
 
40
  # Step 4: Create a table showing BMD prediction and T-score conversion for each year for each drug
41
- def create_bmd_and_tscore_prediction_tables(df_bmd_data, selected_drugs, bmd_patient, c_avg_new, c_sd_new):
42
  years = ['1st', '2nd', '3rd', '4th', '5th', '6th', '8th', '10th']
43
  drug_tables = {}
44
 
45
  # Loop through each selected drug and generate the prediction table
46
  for drug in selected_drugs:
47
- predictions = []
48
  for year in years:
49
  if not pd.isna(df_bmd_data.loc[df_bmd_data['Drug'] == drug, year].values[0]):
50
  percent_increase = df_bmd_data.loc[df_bmd_data['Drug'] == drug, year].values[0]
@@ -68,9 +68,9 @@ def display_prediction_tables_and_plots(prediction_tables, baseline_bmd, baselin
68
  st.dataframe(table)
69
 
70
  # Create and display separate plots for each drug
71
- years = ['0'] + list(table['Year'])
72
- bmd_values = [baseline_bmd] + list(table['Predicted BMD'])
73
- tscore_values = [baseline_tscore] + list(table['Predicted T-score'])
74
 
75
  # Create BMD plot
76
  trace_bmd = go.Scatter(x=years, y=bmd_values, mode='lines+markers', name=f'{drug} (BMD)', line=dict(color='blue'))
@@ -110,7 +110,7 @@ def main_with_separate_tables(file_path, bmd_patient, tscore_patient, C_avg_luna
110
  c_avg_new, c_sd_new = adjust_constants(bmd_patient, tscore_patient, C_avg_lunar, C_sd_lunar)
111
 
112
  # Step 4: Create separate prediction tables for each selected drug
113
- prediction_tables = create_bmd_and_tscore_prediction_tables(df_bmd_data, selected_drugs, bmd_patient, c_avg_new, c_sd_new)
114
 
115
  # Display baseline BMD and T-score
116
  st.write(f"Baseline: BMD = {bmd_patient:.3f}, T-score = {tscore_patient:.2f}")
@@ -122,14 +122,14 @@ def main_with_separate_tables(file_path, bmd_patient, tscore_patient, C_avg_luna
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',
135
  'Romosozumab', 'Romosozumab + Denosumab', 'Romosozumab + Alendronate',
@@ -142,7 +142,7 @@ def main():
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)
 
38
  return baseline_bmd * (1 + percentage_increase)
39
 
40
  # Step 4: Create a table showing BMD prediction and T-score conversion for each year for each drug
41
+ def create_bmd_and_tscore_prediction_tables(df_bmd_data, selected_drugs, bmd_patient, tscore_patient, c_avg_new, c_sd_new):
42
  years = ['1st', '2nd', '3rd', '4th', '5th', '6th', '8th', '10th']
43
  drug_tables = {}
44
 
45
  # Loop through each selected drug and generate the prediction table
46
  for drug in selected_drugs:
47
+ predictions = [('0', bmd_patient, tscore_patient)] # Add initial value (Year 0)
48
  for year in years:
49
  if not pd.isna(df_bmd_data.loc[df_bmd_data['Drug'] == drug, year].values[0]):
50
  percent_increase = df_bmd_data.loc[df_bmd_data['Drug'] == drug, year].values[0]
 
68
  st.dataframe(table)
69
 
70
  # Create and display separate plots for each drug
71
+ years = list(table['Year'])
72
+ bmd_values = list(table['Predicted BMD'])
73
+ tscore_values = list(table['Predicted T-score'])
74
 
75
  # Create BMD plot
76
  trace_bmd = go.Scatter(x=years, y=bmd_values, mode='lines+markers', name=f'{drug} (BMD)', line=dict(color='blue'))
 
110
  c_avg_new, c_sd_new = adjust_constants(bmd_patient, tscore_patient, C_avg_lunar, C_sd_lunar)
111
 
112
  # Step 4: Create separate prediction tables for each selected drug
113
+ prediction_tables = create_bmd_and_tscore_prediction_tables(df_bmd_data, selected_drugs, bmd_patient, tscore_patient, c_avg_new, c_sd_new)
114
 
115
  # Display baseline BMD and T-score
116
  st.write(f"Baseline: BMD = {bmd_patient:.3f}, T-score = {tscore_patient:.2f}")
 
122
  def main():
123
  st.title("BMD and T-score Prediction Tool")
124
 
 
 
 
 
125
  # Input patient data
126
  bmd_patient = st.number_input("Initial BMD", min_value=0.0, max_value=2.0, value=0.635, step=0.001, format="%.3f")
127
  tscore_patient = st.number_input("Initial T-score", min_value=-5.0, max_value=2.0, value=-2.5, step=0.01, format="%.2f")
128
 
129
+ # Site options (Total Hip, Femoral Neck, Lumbar Spine)
130
+ site_options = ['Total Hip', 'Femoral Neck', 'Lumbar Spine (L1-L4)']
131
+ site = st.selectbox("Select site", site_options)
132
+
133
  # Drug options
134
  drug_options = ['Teriparatide', 'Teriparatide + Denosumab', 'Denosumab', 'Denosumab + Teriparatide',
135
  'Romosozumab', 'Romosozumab + Denosumab', 'Romosozumab + Alendronate',
 
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
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)