FER_Model / app.py
FarazAli34's picture
Update app.py
b491107 verified
raw
history blame contribute delete
846 Bytes
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)