Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,17 @@ id2label = {
|
|
20 |
6: "Surprised"
|
21 |
}
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Function to classify emotions from audio
|
25 |
def classify_emotion(audio_file):
|
@@ -42,8 +53,10 @@ def classify_emotion(audio_file):
|
|
42 |
|
43 |
# Convert class ID to emotion label
|
44 |
predicted_emotion = id2label.get(predicted_class_id, "Unknown")
|
45 |
-
|
46 |
-
|
|
|
|
|
47 |
|
48 |
# Gradio Interface
|
49 |
interface = gr.Interface(
|
@@ -51,7 +64,7 @@ interface = gr.Interface(
|
|
51 |
inputs=gr.Audio(type="filepath"),
|
52 |
outputs="text",
|
53 |
title="Speech Emotion Classifier π",
|
54 |
-
description="Upload an audio file and the model will classify its emotion (
|
55 |
)
|
56 |
|
57 |
# Launch the app
|
|
|
20 |
6: "Surprised"
|
21 |
}
|
22 |
|
23 |
+
emotion_emojis = {
|
24 |
+
"Neutral": "π",
|
25 |
+
"Happy": "π",
|
26 |
+
"Sad": "π’",
|
27 |
+
"Angry": "π ",
|
28 |
+
"Fearful": "π¨",
|
29 |
+
"Disgusted": "π€’",
|
30 |
+
"Surprised": "π²"
|
31 |
+
}
|
32 |
+
|
33 |
+
|
34 |
|
35 |
# Function to classify emotions from audio
|
36 |
def classify_emotion(audio_file):
|
|
|
53 |
|
54 |
# Convert class ID to emotion label
|
55 |
predicted_emotion = id2label.get(predicted_class_id, "Unknown")
|
56 |
+
emoji = emotion_emojis.get(predicted_emotion, "β")
|
57 |
+
|
58 |
+
return f"Predicted Emotion: {predicted_emotion} {emoji}"
|
59 |
+
|
60 |
|
61 |
# Gradio Interface
|
62 |
interface = gr.Interface(
|
|
|
64 |
inputs=gr.Audio(type="filepath"),
|
65 |
outputs="text",
|
66 |
title="Speech Emotion Classifier π",
|
67 |
+
description="Upload an audio file and the model will classify its emotion (Neutral, Happy, Sad, Angry, Fearful, Disgust, Surprised)."
|
68 |
)
|
69 |
|
70 |
# Launch the app
|