Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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.
|
26 |
-
image_resized = cv2.resize(image, (
|
27 |
-
image_input = np.
|
|
|
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):
|