Spaces:
Running
Running
init
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
# app.py
|
2 |
# Phiên bản hoàn chỉnh, đã sửa lỗi đọc file audio và đồng bộ hóa phiên bản thư viện.
|
|
|
3 |
|
4 |
import os
|
5 |
import joblib
|
@@ -169,6 +170,13 @@ def predict():
|
|
169 |
if trad_feats is None:
|
170 |
return jsonify({'error': 'Không thể xử lý file audio.'}), 500
|
171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
# Chuẩn bị dữ liệu đầu vào cho các mô hình
|
173 |
combined_feats = np.concatenate([trad_feats, w2v_feats]).reshape(1, -1)
|
174 |
scaled_feats = scaler.transform(combined_feats)
|
@@ -179,6 +187,11 @@ def predict():
|
|
179 |
pred_xgb = model_xgb.predict_proba(scaled_feats)[0][1]
|
180 |
pred_lgb = model_lgb.predict_proba(scaled_feats)[0][1]
|
181 |
pred_cnn = model_cnn.predict(spec_img, verbose=0)[0][0]
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
# Ensemble: Kết hợp kết quả bằng cách lấy trung bình xác suất
|
184 |
final_prediction_prob = (pred_xgb + pred_lgb + pred_cnn) / 3
|
|
|
1 |
# app.py
|
2 |
# Phiên bản hoàn chỉnh, đã sửa lỗi đọc file audio và đồng bộ hóa phiên bản thư viện.
|
3 |
+
# Đã thêm các dòng print để chẩn đoán dữ liệu.
|
4 |
|
5 |
import os
|
6 |
import joblib
|
|
|
170 |
if trad_feats is None:
|
171 |
return jsonify({'error': 'Không thể xử lý file audio.'}), 500
|
172 |
|
173 |
+
# ========== BẮT ĐẦU PHẦN GHI LOG CHẨN ĐOÁN ==========
|
174 |
+
print("\n--- BẮT ĐẦU CHẨN ĐOÁN DỮ LIỆU ĐẦU VÀO ---")
|
175 |
+
print(f"DEBUG | trad_feats stats: mean={np.mean(trad_feats):.2f}, std={np.std(trad_feats):.2f}, min={np.min(trad_feats):.2f}, max={np.max(trad_feats):.2f}")
|
176 |
+
print(f"DEBUG | w2v_feats stats: mean={np.mean(w2v_feats):.2f}, std={np.std(w2v_feats):.2f}, min={np.min(w2v_feats):.2f}, max={np.max(w2v_feats):.2f}")
|
177 |
+
print(f"DEBUG | spec_img stats: mean={np.mean(spec_img):.2f}, std={np.std(spec_img):.2f}, min={np.min(spec_img):.2f}, max={np.max(spec_img):.2f}")
|
178 |
+
# ========== KẾT THÚC PHẦN GHI LOG CHẨN ĐOÁN ===========
|
179 |
+
|
180 |
# Chuẩn bị dữ liệu đầu vào cho các mô hình
|
181 |
combined_feats = np.concatenate([trad_feats, w2v_feats]).reshape(1, -1)
|
182 |
scaled_feats = scaler.transform(combined_feats)
|
|
|
187 |
pred_xgb = model_xgb.predict_proba(scaled_feats)[0][1]
|
188 |
pred_lgb = model_lgb.predict_proba(scaled_feats)[0][1]
|
189 |
pred_cnn = model_cnn.predict(spec_img, verbose=0)[0][0]
|
190 |
+
|
191 |
+
# ========== BẮT ĐẦU PHẦN GHI LOG DỰ ĐOÁN ==========
|
192 |
+
print(f"DEBUG | Individual probabilities (for Male): XGB={pred_xgb:.4f}, LGBM={pred_lgb:.4f}, CNN={pred_cnn:.4f}")
|
193 |
+
# ========== KẾT THÚC PHẦN GHI LOG DỰ ĐOÁN ===========
|
194 |
+
|
195 |
|
196 |
# Ensemble: Kết hợp kết quả bằng cách lấy trung bình xác suất
|
197 |
final_prediction_prob = (pred_xgb + pred_lgb + pred_cnn) / 3
|