|
|
"""
|
|
|
Test application locally before deploying
|
|
|
"""
|
|
|
|
|
|
import os
|
|
|
import sys
|
|
|
|
|
|
print("="*70)
|
|
|
print("LOCAL TEST - Speech Emotion Recognition")
|
|
|
print("="*70)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("\n3οΈβ£ Testing model loading...")
|
|
|
|
|
|
try:
|
|
|
from src.ensemble_model import EnsembleEmotionRecognizer
|
|
|
|
|
|
model = EnsembleEmotionRecognizer(weights_dir='weights')
|
|
|
print(" β Model loaded successfully")
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("\n4οΈβ£ Testing feature extraction...")
|
|
|
|
|
|
try:
|
|
|
from src.feature_extraction import extract_features
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
import librosa
|
|
|
y = np.random.randn(22050 * 3)
|
|
|
|
|
|
|
|
|
import soundfile as sf
|
|
|
sf.write('temp_test.wav', y, 22050)
|
|
|
|
|
|
|
|
|
features, _, _ = extract_features('temp_test.wav')
|
|
|
print(f" β Features extracted: shape {features.shape}")
|
|
|
|
|
|
|
|
|
prediction = model.predict(features)
|
|
|
print(f" β Prediction works: {model.decode_emotion(prediction[0])}")
|
|
|
|
|
|
|
|
|
os.remove('temp_test.wav')
|
|
|
|
|
|
except Exception as e:
|
|
|
print(f" β Error in feature extraction: {e}")
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
total_size += size
|
|
|
if size > 10: |