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)
|
||||
|
||||
@@ -76,6 +76,8 @@ export default function Home() {
|
||||
<div className="flex justify-between items-start">
|
||||
<div className="flex-1">
|
||||
<h3 className="font-medium text-gray-900">{track.filename}</h3>
|
||||
|
||||
{/* Primary metadata */}
|
||||
<div className="mt-1 flex flex-wrap gap-2">
|
||||
<span className="inline-flex items-center px-2 py-1 rounded text-xs bg-blue-100 text-blue-800">
|
||||
{track.classification.genre.primary}
|
||||
@@ -86,10 +88,40 @@ export default function Home() {
|
||||
<span className="text-xs text-gray-500">
|
||||
{Math.round(track.features.tempo_bpm)} BPM
|
||||
</span>
|
||||
<span className="text-xs text-gray-500">
|
||||
{track.features.key}
|
||||
</span>
|
||||
<span className="text-xs text-gray-500">
|
||||
{Math.floor(track.duration_seconds / 60)}:{String(Math.floor(track.duration_seconds % 60)).padStart(2, '0')}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Secondary moods */}
|
||||
{track.classification.mood.secondary && track.classification.mood.secondary.length > 0 && (
|
||||
<div className="mt-2 flex flex-wrap gap-1">
|
||||
<span className="text-xs text-gray-400">Also:</span>
|
||||
{track.classification.mood.secondary.map((mood, i) => (
|
||||
<span key={i} className="inline-flex items-center px-2 py-0.5 rounded text-xs bg-purple-50 text-purple-600">
|
||||
{mood}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Instruments */}
|
||||
{track.classification.instruments && track.classification.instruments.length > 0 && (
|
||||
<div className="mt-2 flex flex-wrap gap-1">
|
||||
<span className="text-xs text-gray-400">Instruments:</span>
|
||||
{track.classification.instruments.slice(0, 6).map((instrument, i) => (
|
||||
<span key={i} className="inline-flex items-center px-2 py-0.5 rounded text-xs bg-green-50 text-green-700">
|
||||
{instrument}
|
||||
</span>
|
||||
))}
|
||||
{track.classification.instruments.length > 6 && (
|
||||
<span className="text-xs text-gray-400">+{track.classification.instruments.length - 6} more</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="ml-4 flex gap-2">
|
||||
<a
|
||||
|
||||
Reference in New Issue
Block a user