Rathapoom commited on
Commit
0d99249
·
verified ·
1 Parent(s): fe0e27c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -30,14 +30,22 @@ def generate_predictions(medication_data, site, bmd, mu, sigma):
30
  site_data = medication_data[medication_data['Site'] == site]
31
  all_results = []
32
 
 
 
 
 
33
  for _, row in site_data.iterrows():
34
  drug = row['Medication']
35
  predictions = {'Year': ['0'], 'Predicted BMD': [round(bmd, 3)], 'Predicted T-score': [round(calculate_tscore(bmd, mu, sigma), 1)]}
36
 
 
 
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) # Adjusted as per your update
 
 
41
  predicted_tscore = calculate_tscore(predicted_bmd, mu, sigma)
42
 
43
  predictions['Year'].append(year.replace(" Year", "")) # Simplify year label
@@ -103,11 +111,18 @@ def main():
103
  )
104
 
105
  # Load constants and medication data
106
- constants = REGRESSION_CONSTANTS[site]
107
  medication_data = load_medication_data()
 
 
108
 
 
 
 
 
 
109
  # Generate and display predictions
110
  if st.button("Predict"):
 
111
  predictions = generate_predictions(medication_data, site, bmd_patient, constants['mu'], constants['sigma'])
112
  display_results(predictions, site)
113
 
 
30
  site_data = medication_data[medication_data['Site'] == site]
31
  all_results = []
32
 
33
+ if site_data.empty:
34
+ st.warning(f"No data available for the selected site: {site}")
35
+ return all_results # Return empty results
36
+
37
  for _, row in site_data.iterrows():
38
  drug = row['Medication']
39
  predictions = {'Year': ['0'], 'Predicted BMD': [round(bmd, 3)], 'Predicted T-score': [round(calculate_tscore(bmd, mu, sigma), 1)]}
40
 
41
+ st.write(f"Processing drug: {drug}")
42
+
43
  for year in row.index[1:-1]: # Skip 'Medication' and 'Site' columns
44
  if not pd.isna(row[year]):
45
  percentage_increase = row[year]
46
+ st.write(f"Year: {year}, Percentage Increase: {percentage_increase}")
47
+
48
+ predicted_bmd = bmd * (1 + percentage_increase)
49
  predicted_tscore = calculate_tscore(predicted_bmd, mu, sigma)
50
 
51
  predictions['Year'].append(year.replace(" Year", "")) # Simplify year label
 
111
  )
112
 
113
  # Load constants and medication data
 
114
  medication_data = load_medication_data()
115
+ st.write("Loaded Medication Data:")
116
+ st.write(medication_data.head()) # Display the loaded data for verification
117
 
118
+ constants = REGRESSION_CONSTANTS.get(site, {})
119
+ if not constants:
120
+ st.warning(f"No constants available for the selected site: {site}")
121
+ return
122
+
123
  # Generate and display predictions
124
  if st.button("Predict"):
125
+ st.write("Prediction started...")
126
  predictions = generate_predictions(medication_data, site, bmd_patient, constants['mu'], constants['sigma'])
127
  display_results(predictions, site)
128