Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -48,29 +48,16 @@ def predict_new_j0_j45(age, aca_magnitude, aca_axis_deg):
|
|
48 |
new_j45 = model_j45(input_data_j45).item()
|
49 |
return new_j0, new_j45
|
50 |
|
51 |
-
def
|
52 |
-
"""Calculate magnitude
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
# Apply the conditional logic
|
62 |
-
if j0 > 0:
|
63 |
-
if j45 > 0:
|
64 |
-
final_axis = Z
|
65 |
-
else:
|
66 |
-
final_axis = Z + 180
|
67 |
-
else:
|
68 |
-
final_axis = Z + 90
|
69 |
-
|
70 |
-
# Ensure the final axis is between 0 and 180
|
71 |
-
final_axis = final_axis % 180
|
72 |
-
|
73 |
-
return magnitude, final_axis, Z # Return Z as the intermediate axis
|
74 |
|
75 |
def main():
|
76 |
st.set_page_config(page_title='Astigmatism Prediction', page_icon=':eyeglasses:', layout='wide')
|
@@ -84,31 +71,36 @@ def main():
|
|
84 |
|
85 |
if st.button('Predict!'):
|
86 |
if 18 <= age <= 90 and 0 <= aca_magnitude <= 10 and 0 <= aca_axis <= 180:
|
87 |
-
# Calculate initial J0 and J45 (for
|
88 |
initial_j0, initial_j45 = calculate_initial_j0_j45(aca_magnitude, aca_axis)
|
89 |
|
90 |
# Predict new J0 and J45 using the models
|
91 |
new_j0, new_j45 = predict_new_j0_j45(age, aca_magnitude, aca_axis)
|
92 |
|
93 |
# Calculate predicted magnitude and axis
|
94 |
-
predicted_magnitude
|
|
|
95 |
|
96 |
st.success(f'Predicted Total Corneal Astigmatism Magnitude: {predicted_magnitude:.2f} D')
|
97 |
st.success(f'Predicted Total Corneal Astigmatism Axis: {predicted_axis:.1f}°')
|
98 |
|
99 |
# Display intermediate values for verification
|
|
|
100 |
st.info(f'Initial J0: {initial_j0:.2f}, Initial J45: {initial_j45:.2f}')
|
101 |
st.info(f'Predicted J0: {new_j0:.2f}, Predicted J45: {new_j45:.2f}')
|
102 |
-
st.info(f'
|
103 |
-
st.info(f'
|
|
|
104 |
|
105 |
# Additional debugging information
|
106 |
st.subheader('Debugging Information:')
|
107 |
-
st.write(f'
|
108 |
-
st.write(f'
|
109 |
-
st.write(f'
|
110 |
-
st.write(f'
|
111 |
-
st.write(f'
|
|
|
|
|
112 |
else:
|
113 |
st.error('Please ensure all inputs are within the specified ranges.')
|
114 |
|
|
|
48 |
new_j45 = model_j45(input_data_j45).item()
|
49 |
return new_j0, new_j45
|
50 |
|
51 |
+
def calculate_magnitude(j0, j45):
|
52 |
+
"""Calculate magnitude from J0 and J45."""
|
53 |
+
return math.sqrt(j0**2 + j45**2)
|
54 |
+
|
55 |
+
def calculate_axis(j0, j45):
|
56 |
+
"""Calculate axis from J0 and J45."""
|
57 |
+
axis = 0.5 * math.degrees(math.atan2(j45, j0))
|
58 |
+
if axis < 0:
|
59 |
+
axis += 180
|
60 |
+
return axis
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
def main():
|
63 |
st.set_page_config(page_title='Astigmatism Prediction', page_icon=':eyeglasses:', layout='wide')
|
|
|
71 |
|
72 |
if st.button('Predict!'):
|
73 |
if 18 <= age <= 90 and 0 <= aca_magnitude <= 10 and 0 <= aca_axis <= 180:
|
74 |
+
# Calculate initial J0 and J45 (for comparison)
|
75 |
initial_j0, initial_j45 = calculate_initial_j0_j45(aca_magnitude, aca_axis)
|
76 |
|
77 |
# Predict new J0 and J45 using the models
|
78 |
new_j0, new_j45 = predict_new_j0_j45(age, aca_magnitude, aca_axis)
|
79 |
|
80 |
# Calculate predicted magnitude and axis
|
81 |
+
predicted_magnitude = calculate_magnitude(new_j0, new_j45)
|
82 |
+
predicted_axis = calculate_axis(new_j0, new_j45)
|
83 |
|
84 |
st.success(f'Predicted Total Corneal Astigmatism Magnitude: {predicted_magnitude:.2f} D')
|
85 |
st.success(f'Predicted Total Corneal Astigmatism Axis: {predicted_axis:.1f}°')
|
86 |
|
87 |
# Display intermediate values for verification
|
88 |
+
st.info(f'Input ACA - Magnitude: {aca_magnitude:.2f} D, Axis: {aca_axis:.1f}°')
|
89 |
st.info(f'Initial J0: {initial_j0:.2f}, Initial J45: {initial_j45:.2f}')
|
90 |
st.info(f'Predicted J0: {new_j0:.2f}, Predicted J45: {new_j45:.2f}')
|
91 |
+
st.info(f'Intermediate calculations:')
|
92 |
+
st.info(f' atan2(J45, J0): {math.degrees(math.atan2(new_j45, new_j0)):.2f}°')
|
93 |
+
st.info(f' 0.5 * atan2(J45, J0): {0.5 * math.degrees(math.atan2(new_j45, new_j0)):.2f}°')
|
94 |
|
95 |
# Additional debugging information
|
96 |
st.subheader('Debugging Information:')
|
97 |
+
st.write(f'Input age: {age}')
|
98 |
+
st.write(f'Input ACA magnitude: {aca_magnitude:.2f} D')
|
99 |
+
st.write(f'Input ACA axis: {aca_axis:.1f}°')
|
100 |
+
st.write(f'Calculated ACA X: {aca_magnitude * math.cos(math.radians(aca_axis)):.4f}')
|
101 |
+
st.write(f'Calculated ACA Y: {aca_magnitude * math.sin(math.radians(aca_axis)):.4f}')
|
102 |
+
st.write(f'Model J0 input: [{age}, {aca_axis}, {aca_magnitude * math.cos(math.radians(aca_axis)):.4f}]')
|
103 |
+
st.write(f'Model J45 input: [{age}, {aca_axis}, {aca_magnitude * math.sin(math.radians(aca_axis)):.4f}]')
|
104 |
else:
|
105 |
st.error('Please ensure all inputs are within the specified ranges.')
|
106 |
|