app.py
Browse files
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import cv2
|
4 |
+
from tensorflow.keras.models import load_model
|
5 |
+
|
6 |
+
model = load_model("emotion_model.h5")
|
7 |
+
emotion_labels = ['Angry', 'Disgust', 'Fear', 'Happy', 'Neutral', 'Sad', 'Surprise']
|
8 |
+
|
9 |
+
def detect_emotion(image):
|
10 |
+
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
11 |
+
face = cv2.resize(gray, (48, 48))
|
12 |
+
face = face.reshape(1, 48, 48, 1) / 255.0
|
13 |
+
prediction = model.predict(face)
|
14 |
+
emotion = emotion_labels[np.argmax(prediction)]
|
15 |
+
return emotion
|
16 |
+
|
17 |
+
iface = gr.Interface(fn=detect_emotion, inputs=gr.Image(type="numpy", shape=(224, 224)), outputs="text")
|
18 |
+
iface.launch()
|