Aryan-EcoClim commited on
Commit
f2681cd
·
1 Parent(s): 23ecd0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -13
app.py CHANGED
@@ -96,26 +96,36 @@ if opt == 'Upload image from device':
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.")
 
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.")