Fix bequcoup de choses : Genre OK, affichage des infos sur le front
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user