Spaces:
Sleeping
Sleeping
File size: 846 Bytes
c693ac9 697a32d c693ac9 18a8879 697a32d c693ac9 18a8879 b491107 c693ac9 697a32d 18a8879 697a32d 18a8879 697a32d b491107 697a32d 425297c b491107 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import gradio as gr
import tensorflow as tf
import cv2
import numpy as np
# Load the model
model = tf.keras.models.load_model("FER_DATA.keras")
# Define the emotion prediction function
def predict_emotion(image_path):
image = cv2.imread(image_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image = cv2.resize(image, (48, 48))
image = image / 255.0
image = np.expand_dims(image, axis=-1)
image = np.expand_dims(image, axis=0)
prediction = model.predict(image)
emotion_index = np.argmax(prediction)
emotions = ['Angry', 'Happy', 'Sad', 'Neutral']
return emotions[emotion_index]
# Launch the Gradio interface
iface = gr.Interface(
fn=predict_emotion,
inputs=gr.Image(type="filepath"),
outputs="text",
title="MoodSync - Emotion Detection"
)
# Make it public
iface.launch(share=True)
|