Rathapoom commited on
Commit
48c283c
·
verified ·
1 Parent(s): 90d0cee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import streamlit as st
2
  import pandas as pd
3
  import plotly.graph_objs as go
@@ -12,8 +14,7 @@ REGRESSION_CONSTANTS = {
12
  # Load medication data
13
  @st.cache_data
14
  def load_medication_data():
15
- # Use the combined medication data we cleaned earlier
16
- file_path = "cleaned_bmd_medication_data.xlsx"
17
  return pd.read_excel(file_path)
18
 
19
  # Calculate predicted BMD after medication
@@ -59,6 +60,10 @@ def display_results(predictions, site):
59
  tscore_predictions = result['T-score Predictions']
60
  years = ['0', '1st', '2nd', '3rd', '4th', '5th', '6th', '8th', '10th']
61
 
 
 
 
 
62
  # Create table
63
  data = {
64
  'Year': years[:len(bmd_predictions)],
@@ -69,13 +74,15 @@ def display_results(predictions, site):
69
  st.dataframe(pd.DataFrame(data))
70
 
71
  # Create plots
72
- fig_bmd = go.Figure(data=[go.Scatter(x=data['Year'], y=data['Predicted BMD'], mode='lines+markers', name='BMD')])
73
- fig_bmd.update_layout(title=f"{drug} - Predicted BMD over Time", xaxis_title="Year", yaxis_title="BMD (g/cm²)")
74
- st.plotly_chart(fig_bmd)
75
-
76
- fig_tscore = go.Figure(data=[go.Scatter(x=data['Year'], y=data['Predicted T-score'], mode='lines+markers', name='T-score')])
77
- fig_tscore.update_layout(title=f"{drug} - Predicted T-score over Time", xaxis_title="Year", yaxis_title="T-score")
78
- st.plotly_chart(fig_tscore)
 
 
79
 
80
  # Streamlit UI
81
  def 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
 
14
  # Load medication data
15
  @st.cache_data
16
  def load_medication_data():
17
+ file_path = ""cleaned_bmd_medication_data.xlsx""
 
18
  return pd.read_excel(file_path)
19
 
20
  # Calculate predicted BMD after medication
 
60
  tscore_predictions = result['T-score Predictions']
61
  years = ['0', '1st', '2nd', '3rd', '4th', '5th', '6th', '8th', '10th']
62
 
63
+ # Format values
64
+ bmd_predictions = [f"{bmd:.3f}" for bmd in bmd_predictions]
65
+ tscore_predictions = [f"{tscore:.1f}" for tscore in tscore_predictions]
66
+
67
  # Create table
68
  data = {
69
  'Year': years[:len(bmd_predictions)],
 
74
  st.dataframe(pd.DataFrame(data))
75
 
76
  # Create plots
77
+ fig_bmd = go.Scatter(x=data['Year'], y=[float(bmd) for bmd in bmd_predictions], mode='lines+markers', name='BMD')
78
+ fig_tscore = go.Scatter(x=data['Year'], y=[float(tscore) for tscore in tscore_predictions], mode='lines+markers', name='T-score')
79
+
80
+ # Combine both graphs in a single row
81
+ col1, col2 = st.columns(2)
82
+ with col1:
83
+ st.plotly_chart(go.Figure(data=[fig_bmd], layout=go.Layout(title=f"{drug} - Predicted BMD", xaxis_title="Year", yaxis_title="BMD (g/cm²)")))
84
+ with col2:
85
+ st.plotly_chart(go.Figure(data=[fig_tscore], layout=go.Layout(title=f"{drug} - Predicted T-score", xaxis_title="Year", yaxis_title="T-score")))
86
 
87
  # Streamlit UI
88
  def main():