nguyennp86's picture
Initial deployment: Speech Emotion Recognition
a344700 verified
"""
Test application locally before deploying
"""
import os
import sys
print("="*70)
print("LOCAL TEST - Speech Emotion Recognition")
print("="*70)
# ============================================================================
# 1. CHECK FILES
# ============================================================================
print("\n1️⃣ Checking required files...")
required_files = [
'app.py',
'requirements.txt',
'README.md',
'src/__init__.py',
'src/feature_extraction.py',
'src/ensemble_model.py',
'src/utils.py',
'weights/xgboost_model.pkl',
'weights/lightgbm_model.pkl',
'weights/gradientboost_model.pkl',
'weights/adaboost_model.pkl',
'weights/scaler.pkl',
'weights/label_encoder.pkl',
'weights/config.json'
]
missing_files = []
for file in required_files:
if os.path.exists(file):
print(f" βœ“ {file}")
else:
print(f" βœ— {file} - MISSING")
missing_files.append(file)
if missing_files:
print(f"\n❌ Missing {len(missing_files)} files. Please create them first.")
sys.exit(1)
# ============================================================================
# 2. TEST IMPORTS
# ============================================================================
print("\n2️⃣ Testing imports...")
try:
import numpy
print(" βœ“ numpy")
except:
print(" βœ— numpy - Install: pip install numpy")
try:
import pandas
print(" βœ“ pandas")
except:
print(" βœ— pandas - Install: pip install pandas")
try:
import sklearn
print(" βœ“ scikit-learn")
except:
print(" βœ— scikit-learn - Install: pip install scikit-learn")
try:
import xgboost
print(" βœ“ xgboost")
except:
print(" βœ— xgboost - Install: pip install xgboost")
try:
import lightgbm
print(" βœ“ lightgbm")
except:
print(" βœ— lightgbm - Install: pip install lightgbm")
try:
import librosa
print(" βœ“ librosa")
except:
print(" βœ— librosa - Install: pip install librosa")
try:
import gradio
print(" βœ“ gradio")
except:
print(" βœ— gradio - Install: pip install gradio")
# ============================================================================
# 3. TEST MODEL LOADING
# ============================================================================
print("\n3️⃣ Testing model loading...")
try:
from src.ensemble_model import EnsembleEmotionRecognizer
model = EnsembleEmotionRecognizer(weights_dir='weights')
print(" βœ“ Model loaded successfully")
# Get model info
info = model.get_model_info()
print(f" βœ“ Models: {', '.join(info['models'])}")
print(f" βœ“ Features: {info['n_features_selected']}/{info['n_features_total']}")
print(f" βœ“ Emotions: {', '.join(info['emotions'])}")
except Exception as e:
print(f" βœ— Error loading model: {e}")
sys.exit(1)
# ============================================================================
# 4. TEST FEATURE EXTRACTION
# ============================================================================
print("\n4️⃣ Testing feature extraction...")
try:
from src.feature_extraction import extract_features
import numpy as np
# Create dummy audio
import librosa
y = np.random.randn(22050 * 3) # 3 seconds of random audio
# Save to temp file
import soundfile as sf
sf.write('temp_test.wav', y, 22050)
# Extract features
features, _, _ = extract_features('temp_test.wav')
print(f" βœ“ Features extracted: shape {features.shape}")
# Test prediction
prediction = model.predict(features)
print(f" βœ“ Prediction works: {model.decode_emotion(prediction[0])}")
# Cleanup
os.remove('temp_test.wav')
except Exception as e:
print(f" βœ— Error in feature extraction: {e}")
sys.exit(1)
# ============================================================================
# 5. FILE SIZES
# ============================================================================
print("\n5️⃣ Checking file sizes...")
total_size = 0
for file in required_files:
if os.path.exists(file):
size = os.path.getsize(file) / 1024 / 1024 # MB
total_size += size
if size > 10: