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: