import gradio as gr
import tensorflow as tf
import librosa
import numpy as np
import warnings
warnings.filterwarnings('ignore')
# Load model - make sure emotion_model.h5 is uploaded
try:
model = tf.keras.models.load_model('emotion_model.h5', compile=False)
print("Model loaded successfully!")
except Exception as e:
print(f"Error loading model: {e}")
model = None
# Adjust these based on your model training
EMOTIONS = ['angry', 'disgust', 'fearful', 'happy', 'neutral', 'sad', 'surprised']
def preprocess_audio(audio_path):
"""
Adjust this function to match your training preprocessing!
This is just an example - modify based on your model
"""
try:
# Load audio
audio, sr = librosa.load(audio_path, sr=22050, duration=3)
# Extract MFCC features (example - adjust to your training)
mfccs = librosa.feature.mfcc(y=audio, sr=sr, n_mfcc=40)
mfccs = np.mean(mfccs.T, axis=0)
# Reshape for model inpu…