Update app.py
Browse files
app.py
CHANGED
@@ -169,24 +169,44 @@ def main():
|
|
169 |
unsafe_allow_html=True
|
170 |
)
|
171 |
|
172 |
-
|
173 |
-
if age
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
st.markdown('<p class="error">Error: Age must be between 18 and 90.</p>', unsafe_allow_html=True)
|
175 |
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
178 |
st.markdown('<p class="error">Error: ACA Magnitude must be between 0 and 10.</p>', unsafe_allow_html=True)
|
179 |
|
180 |
-
|
181 |
-
|
|
|
|
|
|
|
182 |
st.markdown('<p class="error">Error: ACA Axis must be between 0 and 180.</p>', unsafe_allow_html=True)
|
183 |
|
184 |
if st.button('Predict!'):
|
185 |
-
if
|
186 |
-
|
187 |
-
|
|
|
|
|
|
|
188 |
else:
|
189 |
-
st.error('Please
|
190 |
|
191 |
if __name__ == '__main__':
|
192 |
main()
|
|
|
169 |
unsafe_allow_html=True
|
170 |
)
|
171 |
|
172 |
+
# Use session state to store input values
|
173 |
+
if 'age' not in st.session_state:
|
174 |
+
st.session_state.age = None
|
175 |
+
if 'aca_magnitude' not in st.session_state:
|
176 |
+
st.session_state.aca_magnitude = None
|
177 |
+
if 'aca_axis' not in st.session_state:
|
178 |
+
st.session_state.aca_axis = None
|
179 |
+
|
180 |
+
# Age input
|
181 |
+
age = st.number_input('Enter Patient Age:', min_value=18.0, max_value=90.0, step=0.1, value=st.session_state.age)
|
182 |
+
if age != st.session_state.age:
|
183 |
+
st.session_state.age = age
|
184 |
+
if age is not None and (age < 18 or age > 90):
|
185 |
st.markdown('<p class="error">Error: Age must be between 18 and 90.</p>', unsafe_allow_html=True)
|
186 |
|
187 |
+
# ACA Magnitude input
|
188 |
+
aca_magnitude = st.number_input('Enter ACA Magnitude:', min_value=0.0, max_value=10.0, step=0.1, value=st.session_state.aca_magnitude)
|
189 |
+
if aca_magnitude != st.session_state.aca_magnitude:
|
190 |
+
st.session_state.aca_magnitude = aca_magnitude
|
191 |
+
if aca_magnitude is not None and (aca_magnitude < 0 or aca_magnitude > 10):
|
192 |
st.markdown('<p class="error">Error: ACA Magnitude must be between 0 and 10.</p>', unsafe_allow_html=True)
|
193 |
|
194 |
+
# ACA Axis input
|
195 |
+
aca_axis = st.number_input('Enter ACA Axis:', min_value=0.0, max_value=180.0, step=0.1, value=st.session_state.aca_axis)
|
196 |
+
if aca_axis != st.session_state.aca_axis:
|
197 |
+
st.session_state.aca_axis = aca_axis
|
198 |
+
if aca_axis is not None and (aca_axis < 0 or aca_axis > 180):
|
199 |
st.markdown('<p class="error">Error: ACA Axis must be between 0 and 180.</p>', unsafe_allow_html=True)
|
200 |
|
201 |
if st.button('Predict!'):
|
202 |
+
if age is not None and aca_magnitude is not None and aca_axis is not None:
|
203 |
+
if 18 <= age <= 90 and 0 <= aca_magnitude <= 10 and 0 <= aca_axis <= 180:
|
204 |
+
astigmatism = predict_astigmatism(age, aca_axis, aca_magnitude)
|
205 |
+
st.success(f'Predicted Total Corneal Astigmatism: {astigmatism:.4f}')
|
206 |
+
else:
|
207 |
+
st.error('Please correct the input errors before predicting.')
|
208 |
else:
|
209 |
+
st.error('Please fill in all fields before predicting.')
|
210 |
|
211 |
if __name__ == '__main__':
|
212 |
main()
|