Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,26 +3,25 @@ import tensorflow as tf
|
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
# Load model
|
| 7 |
model = tf.keras.models.load_model("FER_DATA.keras")
|
| 8 |
|
| 9 |
-
# Define emotion
|
| 10 |
-
emotions = ['Angry', 'Happy', 'Sad', 'Neutral']
|
| 11 |
-
|
| 12 |
def predict_emotion(image):
|
| 13 |
image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
| 14 |
image = cv2.resize(image, (48, 48))
|
| 15 |
image = image / 255.0
|
| 16 |
image = np.expand_dims(image, axis=-1)
|
| 17 |
image = np.expand_dims(image, axis=0)
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
# Gradio interface
|
| 23 |
iface = gr.Interface(
|
| 24 |
fn=predict_emotion,
|
| 25 |
-
inputs=gr.Image(type="numpy", shape
|
| 26 |
outputs="text",
|
| 27 |
title="MoodSync - Emotion Detection"
|
| 28 |
)
|
|
|
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
+
# Load the model
|
| 7 |
model = tf.keras.models.load_model("FER_DATA.keras")
|
| 8 |
|
| 9 |
+
# Define the emotion prediction function
|
|
|
|
|
|
|
| 10 |
def predict_emotion(image):
|
| 11 |
image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
| 12 |
image = cv2.resize(image, (48, 48))
|
| 13 |
image = image / 255.0
|
| 14 |
image = np.expand_dims(image, axis=-1)
|
| 15 |
image = np.expand_dims(image, axis=0)
|
| 16 |
+
prediction = model.predict(image)
|
| 17 |
+
emotion_index = np.argmax(prediction)
|
| 18 |
+
emotions = ['Angry', 'Happy', 'Sad', 'Neutral']
|
| 19 |
+
return emotions[emotion_index]
|
| 20 |
|
| 21 |
+
# Launch the Gradio interface
|
| 22 |
iface = gr.Interface(
|
| 23 |
fn=predict_emotion,
|
| 24 |
+
inputs=gr.Image(type="numpy"), # Removed shape
|
| 25 |
outputs="text",
|
| 26 |
title="MoodSync - Emotion Detection"
|
| 27 |
)
|