manikanta2026 commited on
Commit
e3c2886
·
1 Parent(s): 25ccec5
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -1,9 +1,13 @@
 
1
  import numpy as np
2
  import librosa
3
  import pickle
4
  import tensorflow as tf
5
  import gradio as gr
6
 
 
 
 
7
  # Load model and label encoder
8
  model = tf.keras.models.load_model("ann_new_emotion_recognition_model.h5", compile=False)
9
  with open("new_label_encoder.pkl", "rb") as f:
@@ -41,8 +45,9 @@ def predict_emotion(audio_file):
41
  predicted_class = np.argmax(predictions[0])
42
  predicted_emotion = label_encoder.inverse_transform([predicted_class])[0]
43
 
 
44
  emotion_probabilities = {
45
- label_encoder.inverse_transform([i])[0]: f"{pred * 100:.2f}%"
46
  for i, pred in enumerate(predictions[0])
47
  }
48
 
@@ -52,7 +57,10 @@ def predict_emotion(audio_file):
52
  iface = gr.Interface(
53
  fn=predict_emotion,
54
  inputs=gr.Audio(type="filepath"),
55
- outputs=["text", "label"],
 
 
 
56
  title="🎤 Emotion Recognition from Audio",
57
  description="Upload or record audio to identify the emotion being expressed."
58
  )
 
1
+ import os
2
  import numpy as np
3
  import librosa
4
  import pickle
5
  import tensorflow as tf
6
  import gradio as gr
7
 
8
+ # Optional: Suppress TensorFlow logging for cleaner output
9
+ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
10
+
11
  # Load model and label encoder
12
  model = tf.keras.models.load_model("ann_new_emotion_recognition_model.h5", compile=False)
13
  with open("new_label_encoder.pkl", "rb") as f:
 
45
  predicted_class = np.argmax(predictions[0])
46
  predicted_emotion = label_encoder.inverse_transform([predicted_class])[0]
47
 
48
+ # Output confidences as floats (0-100), not strings
49
  emotion_probabilities = {
50
+ label_encoder.inverse_transform([i])[0]: float(pred * 100)
51
  for i, pred in enumerate(predictions[0])
52
  }
53
 
 
57
  iface = gr.Interface(
58
  fn=predict_emotion,
59
  inputs=gr.Audio(type="filepath"),
60
+ outputs=[
61
+ gr.Text(label="Predicted Emotion"),
62
+ gr.Label(label="Emotion Probabilities")
63
+ ],
64
  title="🎤 Emotion Recognition from Audio",
65
  description="Upload or record audio to identify the emotion being expressed."
66
  )