ameliabb0913 commited on
Commit
aba0045
Β·
verified Β·
1 Parent(s): 202a7dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
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
- return f"Predicted Emotion: {predicted_emotion}"
 
 
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 (e.g., Happy, Sad, Angry)."
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