Jfink09 commited on
Commit
41dd67e
·
verified ·
1 Parent(s): 74ad4c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -44
app.py CHANGED
@@ -56,67 +56,59 @@ def predict_new_j0_j45(age, aca_magnitude, aca_axis_deg):
56
  def main():
57
  st.title('Total Corneal Astigmatism Prediction')
58
 
59
- # Initialize session state for input values if not already present
60
- if 'age' not in st.session_state:
61
- st.session_state.age = ''
62
- if 'aca_magnitude' not in st.session_state:
63
- st.session_state.aca_magnitude = ''
64
- if 'aca_axis' not in st.session_state:
65
- st.session_state.aca_axis = ''
66
-
67
- # Input fields with session state
68
  age = st.number_input('Enter Patient Age (18-90 Years):',
69
  min_value=18.0, max_value=90.0,
70
- value=st.session_state.age,
71
  step=0.1,
72
  key='age')
73
 
74
  aca_magnitude = st.number_input('Enter ACA Magnitude (0-10 Diopters):',
75
  min_value=0.0, max_value=10.0,
76
- value=st.session_state.aca_magnitude,
77
  step=0.01,
78
  key='aca_magnitude')
79
 
80
  aca_axis = st.number_input('Enter ACA Axis (0-180 Degrees):',
81
  min_value=0.0, max_value=180.0,
82
- value=st.session_state.aca_axis,
83
  step=0.1,
84
  key='aca_axis')
85
 
86
  if st.button('Predict!'):
87
- if 18 <= age <= 90 and 0 <= aca_magnitude <= 10 and 0 <= aca_axis <= 180:
88
- # Calculate initial J0 and J45
89
- initial_j0, initial_j45 = calculate_initial_j0_j45(aca_magnitude, aca_axis)
90
-
91
- # Predict new J0 and J45 using the models
92
- new_j0, new_j45 = predict_new_j0_j45(age, aca_magnitude, aca_axis)
93
-
94
- # Calculate predicted magnitude and axis
95
- predicted_magnitude = math.sqrt(new_j0**2 + new_j45**2)
96
- predicted_axis = 0.5 * math.degrees(math.atan2(new_j45, new_j0))
97
- if predicted_axis < 0:
98
- predicted_axis += 180
99
-
100
- # Display results in green success boxes
101
- st.success(f'Predicted Total Corneal Astigmatism Magnitude: {predicted_magnitude:.2f} D')
102
- st.success(f'Predicted Total Corneal Astigmatism Axis: {predicted_axis:.1f}°')
103
-
104
- # Display intermediate values for verification
105
- #st.info(f'''
106
- #Input ACA - Magnitude: {aca_magnitude:.2f} D, Axis: {aca_axis:.1f}°
107
- #Initial J0: {initial_j0:.2f}, Initial J45: {initial_j45:.2f}
108
- #Predicted J0: {new_j0:.2f}, Predicted J45: {new_j45:.2f}
109
- #''')
110
-
111
- # Additional debugging information (optional)
112
- #if st.checkbox('Show detailed model inputs and outputs'):
113
- #st.subheader('Debugging Information:')
114
- #st.write(f"Input tensor for J0: {torch.tensor([[age, aca_axis, initial_j0]], dtype=torch.float32)}")
115
- #st.write(f"Input tensor for J45: {torch.tensor([[age, aca_axis, initial_j45]], dtype=torch.float32)}")
116
- #st.write(f"Raw J0 output: {new_j0}")
117
- #st.write(f"Raw J45 output: {new_j45}")
 
 
 
118
  else:
119
- st.error('Please ensure all inputs are within the specified ranges.')
120
 
121
  if __name__ == '__main__':
122
  main()
 
56
  def main():
57
  st.title('Total Corneal Astigmatism Prediction')
58
 
59
+ # Input fields without default values
 
 
 
 
 
 
 
 
60
  age = st.number_input('Enter Patient Age (18-90 Years):',
61
  min_value=18.0, max_value=90.0,
 
62
  step=0.1,
63
  key='age')
64
 
65
  aca_magnitude = st.number_input('Enter ACA Magnitude (0-10 Diopters):',
66
  min_value=0.0, max_value=10.0,
 
67
  step=0.01,
68
  key='aca_magnitude')
69
 
70
  aca_axis = st.number_input('Enter ACA Axis (0-180 Degrees):',
71
  min_value=0.0, max_value=180.0,
 
72
  step=0.1,
73
  key='aca_axis')
74
 
75
  if st.button('Predict!'):
76
+ if age and aca_magnitude and aca_axis: # Check if all inputs have been provided
77
+ if 18 <= age <= 90 and 0 <= aca_magnitude <= 10 and 0 <= aca_axis <= 180:
78
+ # Calculate initial J0 and J45
79
+ initial_j0, initial_j45 = calculate_initial_j0_j45(aca_magnitude, aca_axis)
80
+
81
+ # Predict new J0 and J45 using the models
82
+ new_j0, new_j45 = predict_new_j0_j45(age, aca_magnitude, aca_axis)
83
+
84
+ # Calculate predicted magnitude and axis
85
+ predicted_magnitude = math.sqrt(new_j0**2 + new_j45**2)
86
+ predicted_axis = 0.5 * math.degrees(math.atan2(new_j45, new_j0))
87
+ if predicted_axis < 0:
88
+ predicted_axis += 180
89
+
90
+ # Display results in green success boxes
91
+ st.success(f'Predicted Total Corneal Astigmatism Magnitude: {predicted_magnitude:.2f} D')
92
+ st.success(f'Predicted Total Corneal Astigmatism Axis: {predicted_axis:.1f}°')
93
+
94
+ # Display intermediate values for verification
95
+ #st.info(f'''
96
+ #Input ACA - Magnitude: {aca_magnitude:.2f} D, Axis: {aca_axis:.1f}°
97
+ #Initial J0: {initial_j0:.2f}, Initial J45: {initial_j45:.2f}
98
+ #Predicted J0: {new_j0:.2f}, Predicted J45: {new_j45:.2f}
99
+ #''')
100
+
101
+ # Additional debugging information (optional)
102
+ #if st.checkbox('Show detailed model inputs and outputs'):
103
+ #st.subheader('Debugging Information:')
104
+ #st.write(f"Input tensor for J0: {torch.tensor([[age, aca_axis, initial_j0]], dtype=torch.float32)}")
105
+ #st.write(f"Input tensor for J45: {torch.tensor([[age, aca_axis, initial_j45]], dtype=torch.float32)}")
106
+ #st.write(f"Raw J0 output: {new_j0}")
107
+ #st.write(f"Raw J45 output: {new_j45}")
108
+ else:
109
+ st.error('Please ensure all inputs are within the specified ranges.')
110
  else:
111
+ st.error('Please fill in all input fields before predicting.')
112
 
113
  if __name__ == '__main__':
114
  main()