Aryan-EcoClim commited on
Commit
dcae606
·
1 Parent(s): 94e3b91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -30
app.py CHANGED
@@ -4,6 +4,8 @@ from PIL import Image
4
  import tensorflow as tf
5
  from utils import preprocess_image
6
 
 
 
7
  # Initialize labels and model
8
  labels = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
9
  model = tf.keras.models.load_model('classify_model.h5')
@@ -96,39 +98,12 @@ if opt == 'Upload image from device':
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
- if training_mode == 'None':
106
- user_choice = 'Predict'
107
- elif training_mode == "Dropout" or "Batch Normalization":
108
- user_choice = 'Train'
109
-
110
-
111
- # Display the current training mode and user choice
112
- st.write(f"Training mode: {training_mode}")
113
- st.write(f"User choice: {user_choice}")
114
-
115
  try:
116
  if image is not None:
117
  st.image(image, width=256, caption='Uploaded Image')
118
-
119
- # Execute different code blocks based on user choice
120
- if user_choice == "Predict":
121
- # Call the model with the training mode argument
122
- # Use a dictionary to map the training mode to the corresponding boolean value
123
- prediction = model.predict(image[np.newaxis, ...], training={"None": False, "Dropout": True, "Batch Normalization": True}[training_mode])
124
  st.success(f'Prediction: {labels[np.argmax(prediction[0], axis=-1)]}')
125
- elif user_choice == "Train":
126
- # Generate some dummy target data for demonstration
127
- # You can replace this with your actual target data
128
- target = np.random.randint(0, 6, size=(1,))
129
- # Call the model without the training argument
130
- loss = model.train_on_batch(image[np.newaxis, ...], target)
131
- st.success(f'Loss: {loss}')
132
-
133
  except Exception as e:
134
  st.error(f"An error occurred: {e}. Please contact us EcoClim Solutions at EcoClimSolutions.wordpress.com.")
 
 
4
  import tensorflow as tf
5
  from utils import preprocess_image
6
 
7
+
8
+
9
  # Initialize labels and model
10
  labels = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
11
  model = tf.keras.models.load_model('classify_model.h5')
 
98
  if file:
99
  image = preprocess_image(file)
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  try:
102
  if image is not None:
103
  st.image(image, width=256, caption='Uploaded Image')
104
+ if st.button('Predict'):
105
+ prediction = model.predict(image[np.newaxis, ...])
 
 
 
 
106
  st.success(f'Prediction: {labels[np.argmax(prediction[0], axis=-1)]}')
 
 
 
 
 
 
 
 
107
  except Exception as e:
108
  st.error(f"An error occurred: {e}. Please contact us EcoClim Solutions at EcoClimSolutions.wordpress.com.")
109
+