diff --git a/backend/src/core/essentia_classifier.py b/backend/src/core/essentia_classifier.py index 173b846..919c54d 100644 --- a/backend/src/core/essentia_classifier.py +++ b/backend/src/core/essentia_classifier.py @@ -168,12 +168,25 @@ class EssentiaClassifier: predictions = predictions[0] # Remove batch dimension # Get top predictions - top_indices = np.argsort(predictions)[::-1][:5] labels = self.class_labels.get("genre", []) + logger.info(f"Genre predictions shape: {predictions.shape}, num_labels: {len(labels)}") - primary = labels[top_indices[0]] if labels else "unknown" - secondary = [labels[i] for i in top_indices[1:4]] if labels else [] - confidence = float(predictions[top_indices[0]]) + # Ensure we don't go out of bounds + if len(predictions) == 0: + logger.warning("No predictions returned from genre model") + return self._fallback_genre() + + top_indices = np.argsort(predictions)[::-1][:5] + # Only use indices that are within the labels range + valid_top_indices = [i for i in top_indices if i < len(labels)] + + if not valid_top_indices: + logger.warning(f"No valid indices found. Predictions: {len(predictions)}, Labels: {len(labels)}") + return self._fallback_genre() + + primary = labels[valid_top_indices[0]] + secondary = [labels[i] for i in valid_top_indices[1:4]] + confidence = float(predictions[valid_top_indices[0]]) return { "primary": primary, @@ -218,11 +231,19 @@ class EssentiaClassifier: predictions = predictions[0] # Get top predictions - top_indices = np.argsort(predictions)[::-1][:5] labels = self.class_labels.get("mood", []) - primary = labels[top_indices[0]] if labels else "unknown" - secondary = [labels[i] for i in top_indices[1:3]] if labels else [] + if len(predictions) == 0: + return self._fallback_mood() + + top_indices = np.argsort(predictions)[::-1][:5] + valid_top_indices = [i for i in top_indices if i < len(labels)] + + if not valid_top_indices: + return self._fallback_mood() + + primary = labels[valid_top_indices[0]] if valid_top_indices else "unknown" + secondary = [labels[i] for i in valid_top_indices[1:3]] if len(valid_top_indices) > 1 else [] # Estimate arousal and valence from mood labels (simplified) arousal, valence = self._estimate_arousal_valence(primary) diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index f2e25f4..872734e 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -76,6 +76,8 @@ export default function Home() {

{track.filename}

+ + {/* Primary metadata */}
{track.classification.genre.primary} @@ -86,10 +88,40 @@ export default function Home() { {Math.round(track.features.tempo_bpm)} BPM + + {track.features.key} + {Math.floor(track.duration_seconds / 60)}:{String(Math.floor(track.duration_seconds % 60)).padStart(2, '0')}
+ + {/* Secondary moods */} + {track.classification.mood.secondary && track.classification.mood.secondary.length > 0 && ( +
+ Also: + {track.classification.mood.secondary.map((mood, i) => ( + + {mood} + + ))} +
+ )} + + {/* Instruments */} + {track.classification.instruments && track.classification.instruments.length > 0 && ( +
+ Instruments: + {track.classification.instruments.slice(0, 6).map((instrument, i) => ( + + {instrument} + + ))} + {track.classification.instruments.length > 6 && ( + +{track.classification.instruments.length - 6} more + )} +
+ )}