VishnuEcoClim commited on
Commit
96aab6f
·
1 Parent(s): 6750728

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -10,18 +10,15 @@ def classify_garbage(img_path, model):
10
  processed_img = preprocess(img_path)
11
  prediction = model.predict(processed_img)
12
 
13
- class_labels = ["cardboard", "glass", "metal", "paper", "plastic", "trash"]
14
  predicted_class = np.argmax(prediction, axis=1)[0]
15
- classification_result = class_labels[predicted_class]
16
 
17
  # Get the confidence (probability) of the predicted class
18
  confidence = prediction[0][predicted_class] * 100 # Convert probability to percentage
19
 
20
  return classification_result, confidence
21
 
22
- # Load labels
23
- labels = gen_labels()
24
-
25
  # Streamlit app layout
26
  st.markdown('<center><h1>Garbage Segregation</h1></center>', unsafe_allow_html=True)
27
  st.markdown('<center><h3>Please upload Waste Image to find its Category</h3></center>', unsafe_allow_html=True)
@@ -46,9 +43,13 @@ if 'image' in locals(): # Check if image variable exists
46
  if st.button('Predict'):
47
  try:
48
  model = model_arc() # Initialize your model
49
- predicted_class, confidence = classify_garbage(image, model)
50
 
51
- st.info('The uploaded image has been classified as "{}" waste with {:.2f}% confidence.'.format(predicted_class, confidence))
 
 
 
 
 
52
 
53
  except Exception as e:
54
  st.error(f"An error occurred: {e}")
 
10
  processed_img = preprocess(img_path)
11
  prediction = model.predict(processed_img)
12
 
13
+ labels = gen_labels()
14
  predicted_class = np.argmax(prediction, axis=1)[0]
15
+ classification_result = labels[predicted_class]
16
 
17
  # Get the confidence (probability) of the predicted class
18
  confidence = prediction[0][predicted_class] * 100 # Convert probability to percentage
19
 
20
  return classification_result, confidence
21
 
 
 
 
22
  # Streamlit app layout
23
  st.markdown('<center><h1>Garbage Segregation</h1></center>', unsafe_allow_html=True)
24
  st.markdown('<center><h3>Please upload Waste Image to find its Category</h3></center>', unsafe_allow_html=True)
 
43
  if st.button('Predict'):
44
  try:
45
  model = model_arc() # Initialize your model
 
46
 
47
+ # Ensure image shape is correct and add batch dimension
48
+ img_array = preprocess(image) # This should return an array of shape (1, 256, 256, 3)
49
+
50
+ predicted_class, confidence = classify_garbage(img_array, model)
51
+
52
+ st.info('The uploaded image has been classified as "{}" with {:.2f}% confidence.'.format(predicted_class, confidence))
53
 
54
  except Exception as e:
55
  st.error(f"An error occurred: {e}")