Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,16 @@ import gradio as gr
|
|
| 2 |
import tensorflow as tf
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
| 5 |
-
from PIL import Image
|
| 6 |
|
| 7 |
# Load the model
|
| 8 |
model = tf.keras.models.load_model("FER_DATA.keras")
|
| 9 |
|
| 10 |
# Define the emotion prediction function
|
| 11 |
-
def predict_emotion(
|
| 12 |
-
image =
|
| 13 |
-
image =
|
| 14 |
-
image =
|
|
|
|
| 15 |
image = np.expand_dims(image, axis=-1)
|
| 16 |
image = np.expand_dims(image, axis=0)
|
| 17 |
prediction = model.predict(image)
|
|
@@ -22,9 +22,10 @@ def predict_emotion(image: Image.Image):
|
|
| 22 |
# Launch the Gradio interface
|
| 23 |
iface = gr.Interface(
|
| 24 |
fn=predict_emotion,
|
| 25 |
-
inputs=gr.Image(type="
|
| 26 |
outputs="text",
|
| 27 |
title="MoodSync - Emotion Detection"
|
| 28 |
)
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
| 2 |
import tensorflow as tf
|
| 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_path):
|
| 11 |
+
image = cv2.imread(image_path)
|
| 12 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 13 |
+
image = cv2.resize(image, (48, 48))
|
| 14 |
+
image = image / 255.0
|
| 15 |
image = np.expand_dims(image, axis=-1)
|
| 16 |
image = np.expand_dims(image, axis=0)
|
| 17 |
prediction = model.predict(image)
|
|
|
|
| 22 |
# Launch the Gradio interface
|
| 23 |
iface = gr.Interface(
|
| 24 |
fn=predict_emotion,
|
| 25 |
+
inputs=gr.Image(type="filepath"),
|
| 26 |
outputs="text",
|
| 27 |
title="MoodSync - Emotion Detection"
|
| 28 |
)
|
| 29 |
|
| 30 |
+
# Make it public
|
| 31 |
+
iface.launch(share=True)
|