File size: 4,433 Bytes
a344700 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
"""
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: |