Spaces:
Running
Running
Update app.py
Browse files
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 |
-
#
|
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
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
predicted_axis
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
#st.
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
118 |
else:
|
119 |
-
st.error('Please
|
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()
|