IKRAMELHADI
commited on
Commit
·
18c1168
1
Parent(s):
00b7913
modif interpretation results
Browse files
app.py
CHANGED
|
@@ -141,6 +141,52 @@ def html_result(badge_text, duration, rating_text, downloads_text, extra_html=""
|
|
| 141 |
</div>
|
| 142 |
""".strip()
|
| 143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
# =========================
|
| 146 |
# INTERPRETATION (COMMUNE)
|
|
@@ -449,10 +495,11 @@ def predict_from_freesound_url(url: str):
|
|
| 449 |
if MIN_EFFECT <= duration <= MAX_EFFECT:
|
| 450 |
badge = "🔊 Effet sonore (URL → features API)"
|
| 451 |
dl_class = int(predict_with_model_fs(xgb_effect_num, sound, xgb_effect_feat_num))
|
| 452 |
-
|
|
|
|
|
|
|
| 453 |
dl_text = NUM_DOWNLOADS_MAP_FR.get(dl_class, str(dl_class))
|
| 454 |
|
| 455 |
-
avg_class = avg_label_to_class(avg_text)
|
| 456 |
conclusion = interpret_results(avg_class, dl_class)
|
| 457 |
|
| 458 |
extra = f"""
|
|
@@ -467,10 +514,12 @@ def predict_from_freesound_url(url: str):
|
|
| 467 |
if MIN_MUSIC <= duration <= MAX_MUSIC:
|
| 468 |
badge = "🎵 Musique (URL → features API)"
|
| 469 |
dl_class = int(predict_with_model_fs(xgb_music_num, sound, xgb_music_feat_num))
|
| 470 |
-
|
|
|
|
|
|
|
|
|
|
| 471 |
dl_text = NUM_DOWNLOADS_MAP_FR.get(dl_class, str(dl_class))
|
| 472 |
|
| 473 |
-
avg_class = avg_label_to_class(avg_text)
|
| 474 |
conclusion = interpret_results(avg_class, dl_class)
|
| 475 |
|
| 476 |
extra = f"""
|
|
@@ -843,10 +892,10 @@ def predict_from_metadata_url(url: str):
|
|
| 843 |
pred_downloads_text = NUM_DOWNLOADS_MAP.get(pred_num_downloads_val, str(pred_num_downloads_val))
|
| 844 |
|
| 845 |
# avg rating (label)
|
| 846 |
-
|
|
|
|
|
|
|
| 847 |
|
| 848 |
-
# 8) transformer en classes (pour interprétation + cohérence visuelle)
|
| 849 |
-
avg_class = avg_label_to_class(pred_avg_rating_label)
|
| 850 |
dl_class = int(pred_num_downloads_val) if isinstance(pred_num_downloads_val, (int, np.integer)) else 0
|
| 851 |
|
| 852 |
rating_display = str(pred_avg_rating_label)
|
|
|
|
| 141 |
</div>
|
| 142 |
""".strip()
|
| 143 |
|
| 144 |
+
def normalize_avg_rating_label_fr(label) -> str:
|
| 145 |
+
"""
|
| 146 |
+
Convertit n'importe quel label avg_rating (EN/FR/variantes) en FR stable.
|
| 147 |
+
Sorties possibles : "Informations manquantes", "Faible", "Moyen", "Élevé"
|
| 148 |
+
"""
|
| 149 |
+
if label is None:
|
| 150 |
+
return "Informations manquantes"
|
| 151 |
+
|
| 152 |
+
s = str(label).strip().lower()
|
| 153 |
+
|
| 154 |
+
# manquant
|
| 155 |
+
if "miss" in s or "missing" in s or "none" in s or "no" in s or "nan" in s:
|
| 156 |
+
return "Informations manquantes"
|
| 157 |
+
if "info" in s and "manq" in s:
|
| 158 |
+
return "Informations manquantes"
|
| 159 |
+
|
| 160 |
+
# élevé
|
| 161 |
+
if "high" in s or "élev" in s or "eleve" in s:
|
| 162 |
+
return "Élevé"
|
| 163 |
+
|
| 164 |
+
# moyen
|
| 165 |
+
if "medium" in s or "moy" in s:
|
| 166 |
+
return "Moyen"
|
| 167 |
+
|
| 168 |
+
# faible
|
| 169 |
+
if "low" in s or "faibl" in s:
|
| 170 |
+
return "Faible"
|
| 171 |
+
|
| 172 |
+
# fallback (si le modèle renvoie un truc inattendu)
|
| 173 |
+
return "Informations manquantes"
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def avg_fr_to_class(avg_fr: str) -> int:
|
| 177 |
+
"""
|
| 178 |
+
Convertit l'étiquette FR en classe 0..3 pour interpret_results()
|
| 179 |
+
"""
|
| 180 |
+
s = str(avg_fr).strip().lower()
|
| 181 |
+
if "manqu" in s:
|
| 182 |
+
return 0
|
| 183 |
+
if "faibl" in s:
|
| 184 |
+
return 1
|
| 185 |
+
if "moy" in s:
|
| 186 |
+
return 2
|
| 187 |
+
if "élev" in s or "eleve" in s:
|
| 188 |
+
return 3
|
| 189 |
+
return 0
|
| 190 |
|
| 191 |
# =========================
|
| 192 |
# INTERPRETATION (COMMUNE)
|
|
|
|
| 495 |
if MIN_EFFECT <= duration <= MAX_EFFECT:
|
| 496 |
badge = "🔊 Effet sonore (URL → features API)"
|
| 497 |
dl_class = int(predict_with_model_fs(xgb_effect_num, sound, xgb_effect_feat_num))
|
| 498 |
+
avg_text_raw = str(predict_with_model_fs(xgb_effect_avg, sound, xgb_effect_feat_avg, le_effect_avg))
|
| 499 |
+
avg_text = normalize_avg_rating_label_fr(avg_text_raw)
|
| 500 |
+
avg_class = avg_fr_to_class(avg_text)
|
| 501 |
dl_text = NUM_DOWNLOADS_MAP_FR.get(dl_class, str(dl_class))
|
| 502 |
|
|
|
|
| 503 |
conclusion = interpret_results(avg_class, dl_class)
|
| 504 |
|
| 505 |
extra = f"""
|
|
|
|
| 514 |
if MIN_MUSIC <= duration <= MAX_MUSIC:
|
| 515 |
badge = "🎵 Musique (URL → features API)"
|
| 516 |
dl_class = int(predict_with_model_fs(xgb_music_num, sound, xgb_music_feat_num))
|
| 517 |
+
avg_text_raw = str(predict_with_model_fs(xgb_music_avg, sound, xgb_music_feat_avg, le_music_avg))
|
| 518 |
+
avg_text = normalize_avg_rating_label_fr(avg_text_raw)
|
| 519 |
+
avg_class = avg_fr_to_class(avg_text)
|
| 520 |
+
|
| 521 |
dl_text = NUM_DOWNLOADS_MAP_FR.get(dl_class, str(dl_class))
|
| 522 |
|
|
|
|
| 523 |
conclusion = interpret_results(avg_class, dl_class)
|
| 524 |
|
| 525 |
extra = f"""
|
|
|
|
| 892 |
pred_downloads_text = NUM_DOWNLOADS_MAP.get(pred_num_downloads_val, str(pred_num_downloads_val))
|
| 893 |
|
| 894 |
# avg rating (label)
|
| 895 |
+
pred_avg_rating_label_raw = predict_with_model_meta(model_ar, df_for_model, le=current_le)
|
| 896 |
+
pred_avg_rating_label = normalize_avg_rating_label_fr(pred_avg_rating_label_raw)
|
| 897 |
+
avg_class = avg_fr_to_class(pred_avg_rating_label)
|
| 898 |
|
|
|
|
|
|
|
| 899 |
dl_class = int(pred_num_downloads_val) if isinstance(pred_num_downloads_val, (int, np.integer)) else 0
|
| 900 |
|
| 901 |
rating_display = str(pred_avg_rating_label)
|