Ahmadkhan12 commited on
Commit
bfb3b6f
·
verified ·
1 Parent(s): 7ffdd20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -22,11 +22,11 @@ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
22
 
23
  def preprocess_image(image):
24
  """Preprocess image to match model input requirements"""
25
- image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
26
- image_resized = cv2.resize(image, (224, 224)) # Resize image to model input size
27
- image_input = np.transpose(image_resized, (2, 0, 1)) # Change data format for the model
 
28
  image_input = image_input.astype(np.float32) / 255.0 # Normalize the image
29
- image_input = np.expand_dims(image_input, axis=0) # Add batch dimension
30
  return image_input
31
 
32
  def predict_emotion(image_input):
 
22
 
23
  def preprocess_image(image):
24
  """Preprocess image to match model input requirements"""
25
+ image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY) # Convert image to grayscale
26
+ image_resized = cv2.resize(image, (48, 48)) # Resize image to 48x48
27
+ image_input = np.expand_dims(image_resized, axis=0) # Add batch dimension
28
+ image_input = np.expand_dims(image_input, axis=0) # Add channel dimension (for grayscale)
29
  image_input = image_input.astype(np.float32) / 255.0 # Normalize the image
 
30
  return image_input
31
 
32
  def predict_emotion(image_input):