Spaces:
Running
Running
Commit
·
f2681cd
1
Parent(s):
23ecd0c
Update app.py
Browse files
app.py
CHANGED
@@ -96,26 +96,36 @@ if opt == 'Upload image from device':
|
|
96 |
if file:
|
97 |
image = preprocess_image(file)
|
98 |
|
99 |
-
#
|
100 |
-
|
101 |
-
st.session_state.training_mode = False
|
102 |
|
103 |
-
#
|
104 |
-
|
105 |
|
106 |
-
#
|
107 |
-
|
108 |
-
st.session_state.training_mode = not st.session_state.training_mode
|
109 |
|
110 |
-
#
|
111 |
-
st.write(f
|
|
|
112 |
|
113 |
try:
|
114 |
if image is not None:
|
115 |
st.image(image, width=256, caption='Uploaded Image')
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
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.")
|
|
|
96 |
if file:
|
97 |
image = preprocess_image(file)
|
98 |
|
99 |
+
# Sidebar section
|
100 |
+
st.sidebar.title("Options")
|
|
|
101 |
|
102 |
+
# Create a radio button widget for training mode
|
103 |
+
training_mode = st.sidebar.radio("Select training mode", ["None", "Dropout", "Batch Normalization"])
|
104 |
|
105 |
+
# Create a select box widget for user choice
|
106 |
+
user_choice = st.sidebar.selectbox("Select what you want to do", ["Predict", "Train"])
|
|
|
107 |
|
108 |
+
# Display the current training mode and user choice
|
109 |
+
st.write(f"Training mode: {training_mode}")
|
110 |
+
st.write(f"User choice: {user_choice}")
|
111 |
|
112 |
try:
|
113 |
if image is not None:
|
114 |
st.image(image, width=256, caption='Uploaded Image')
|
115 |
+
|
116 |
+
# Execute different code blocks based on user choice
|
117 |
+
if user_choice == "Predict":
|
118 |
+
# Call the model with the training mode argument
|
119 |
+
# Use a dictionary to map the training mode to the corresponding boolean value
|
120 |
+
prediction = model.predict_on_batch(image[np.newaxis, ...], training={"None": False, "Dropout": True, "Batch Normalization": True}[training_mode])
|
121 |
st.success(f'Prediction: {labels[np.argmax(prediction[0], axis=-1)]}')
|
122 |
+
elif user_choice == "Train":
|
123 |
+
# Generate some dummy target data for demonstration
|
124 |
+
# You can replace this with your actual target data
|
125 |
+
target = np.random.randint(0, 6, size=(1,))
|
126 |
+
# Call the model with the training mode argument
|
127 |
+
# Use a dictionary to map the training mode to the corresponding boolean value
|
128 |
+
loss = model.train_on_batch(image[np.newaxis, ...], target, training={"None": False, "Dropout": True, "Batch Normalization": True}[training_mode])
|
129 |
+
st.success(f'Loss: {loss}')
|
130 |
except Exception as e:
|
131 |
st.error(f"An error occurred: {e}. Please contact us EcoClim Solutions at EcoClimSolutions.wordpress.com.")
|