Spaces:
Running
Running
Commit
·
23ecd0c
1
Parent(s):
3c77bcb
Update app.py
Browse files
app.py
CHANGED
@@ -96,12 +96,26 @@ if opt == 'Upload image from device':
|
|
96 |
if file:
|
97 |
image = preprocess_image(file)
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
try:
|
100 |
if image is not None:
|
101 |
st.image(image, width=256, caption='Uploaded Image')
|
102 |
if st.button('Predict'):
|
103 |
-
|
|
|
104 |
st.success(f'Prediction: {labels[np.argmax(prediction[0], axis=-1)]}')
|
105 |
except Exception as e:
|
106 |
st.error(f"An error occurred: {e}. Please contact us EcoClim Solutions at EcoClimSolutions.wordpress.com.")
|
107 |
-
|
|
|
96 |
if file:
|
97 |
image = preprocess_image(file)
|
98 |
|
99 |
+
# initialize the session state with a default value
|
100 |
+
if 'training_mode' not in st.session_state:
|
101 |
+
st.session_state.training_mode = False
|
102 |
+
|
103 |
+
# create a button widget
|
104 |
+
button = st.button('Toggle training mode')
|
105 |
+
|
106 |
+
# update the session state when the button is clicked
|
107 |
+
if button:
|
108 |
+
st.session_state.training_mode = not st.session_state.training_mode
|
109 |
+
|
110 |
+
# display the current training mode
|
111 |
+
st.write(f'Training mode: {st.session_state.training_mode}')
|
112 |
+
|
113 |
try:
|
114 |
if image is not None:
|
115 |
st.image(image, width=256, caption='Uploaded Image')
|
116 |
if st.button('Predict'):
|
117 |
+
# call the model with the training mode argument
|
118 |
+
prediction = model.predict(image[np.newaxis, ...], training=st.session_state.training_mode)
|
119 |
st.success(f'Prediction: {labels[np.argmax(prediction[0], axis=-1)]}')
|
120 |
except Exception as e:
|
121 |
st.error(f"An error occurred: {e}. Please contact us EcoClim Solutions at EcoClimSolutions.wordpress.com.")
|
|