Update app.py
Browse files
app.py
CHANGED
@@ -159,6 +159,7 @@ def _warmup_thread(models: List[str]):
|
|
159 |
warmup_state.update({
|
160 |
"running": True,
|
161 |
"percent": 0,
|
|
|
162 |
"done": False,
|
163 |
"logs": [],
|
164 |
"current": None,
|
@@ -180,6 +181,8 @@ def _warmup_thread(models: List[str]):
|
|
180 |
if ok:
|
181 |
ok_count += 1
|
182 |
_log_warmup(f"OK: {repo}")
|
|
|
|
|
183 |
else:
|
184 |
_log_warmup(f"ÉCHEC: {repo}")
|
185 |
|
@@ -187,6 +190,7 @@ def _warmup_thread(models: List[str]):
|
|
187 |
warmup_state["percent"] = 100
|
188 |
warmup_state["done"] = True
|
189 |
warmup_state["running"] = False
|
|
|
190 |
_log_warmup(f"Terminé: {ok_count}/{len(models)} modèles.")
|
191 |
# <<<< HUGINFACE PATCH: WARMUP STATE+HELPERS END >>>>
|
192 |
# ---------- Helpers ----------
|
@@ -929,12 +933,6 @@ const DEFAULT_MODELS = [
|
|
929 |
];
|
930 |
// >>> A2B2P3_END warmup_defaults
|
931 |
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
function openWarmupPopup(){ if(warmupPopup) warmupPopup.style.display = 'block'; }
|
939 |
|
940 |
function closeWarmupPopup(){ if(warmupPopup) warmupPopup.style.display = 'none'; }
|
@@ -970,13 +968,18 @@ async function refreshWarmupUI(){
|
|
970 |
const idx = (s.idx ?? 0) + 1;
|
971 |
warmupStatusEl.textContent = `⏳ ${pct}% — ${s.current||''} (${idx}/${tot}) [inst:${instanceId}]`;
|
972 |
} else {
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
if (nCache > 0) {
|
977 |
-
warmupStatusEl.textContent = `✅ Terminé — cache local: ${nCache} (inst:${instanceId})`;
|
978 |
} else {
|
979 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
980 |
}
|
981 |
|
982 |
}
|
@@ -985,31 +988,25 @@ async function refreshWarmupUI(){
|
|
985 |
if (warmupProgressFill) warmupProgressFill.style.width = pct + '%';
|
986 |
if (warmupPopupStatus) warmupPopupStatus.textContent = running ? 'Téléchargement en cours…' : 'Terminé';
|
987 |
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
// Préambule construit dynamiquement à partir de /warmup/status
|
993 |
-
let prefaceNow = '';
|
994 |
-
if (Array.isArray(s.audit_cached)) {
|
995 |
-
const n = Number.isFinite(s.audit_count) ? s.audit_count : s.audit_cached.length;
|
996 |
-
prefaceNow =
|
997 |
-
`[Instance ${instanceId}]` + '\n' +
|
998 |
-
'Déjà en cache (' + n + '):\n' +
|
999 |
-
s.audit_cached.map(m => ' • ' + m).join('\n');
|
1000 |
-
|
1001 |
-
}
|
1002 |
-
if (Array.isArray(window.lastRequestedModels) && window.lastRequestedModels.length) {
|
1003 |
-
prefaceNow += (prefaceNow ? '\n\n' : '') +
|
1004 |
-
'Demandé dans cette exécution (' + window.lastRequestedModels.length + '):\n' +
|
1005 |
-
window.lastRequestedModels.map(m => ' • ' + m).join('\n');
|
1006 |
-
}
|
1007 |
const logsTxt = Array.isArray(s.logs) ? s.logs.join('\n') : '';
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1013 |
|
1014 |
|
1015 |
if (warmupStopBtn) warmupStopBtn.style.display = running ? 'inline-block' : 'none';
|
@@ -1092,6 +1089,14 @@ if (warmupStartBtn){
|
|
1092 |
alert('Échec démarrage: ' + r.status + ' ' + t);
|
1093 |
return;
|
1094 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1095 |
// Rafraîchit l’UI et démarre le polling
|
1096 |
await refreshWarmupUI();
|
1097 |
if (!warmupTimer) warmupTimer = setInterval(refreshWarmupUI, 1000);
|
@@ -1102,11 +1107,6 @@ if (warmupStartBtn){
|
|
1102 |
});
|
1103 |
}
|
1104 |
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
if (warmupLogsBtn){
|
1111 |
warmupLogsBtn.addEventListener('click', async ()=>{
|
1112 |
|
|
|
159 |
warmup_state.update({
|
160 |
"running": True,
|
161 |
"percent": 0,
|
162 |
+
"ok_count": 0,
|
163 |
"done": False,
|
164 |
"logs": [],
|
165 |
"current": None,
|
|
|
181 |
if ok:
|
182 |
ok_count += 1
|
183 |
_log_warmup(f"OK: {repo}")
|
184 |
+
with warmup_lock:
|
185 |
+
warmup_state["ok_count"] = ok_count
|
186 |
else:
|
187 |
_log_warmup(f"ÉCHEC: {repo}")
|
188 |
|
|
|
190 |
warmup_state["percent"] = 100
|
191 |
warmup_state["done"] = True
|
192 |
warmup_state["running"] = False
|
193 |
+
warmup_state["ok_count"] = ok_count
|
194 |
_log_warmup(f"Terminé: {ok_count}/{len(models)} modèles.")
|
195 |
# <<<< HUGINFACE PATCH: WARMUP STATE+HELPERS END >>>>
|
196 |
# ---------- Helpers ----------
|
|
|
933 |
];
|
934 |
// >>> A2B2P3_END warmup_defaults
|
935 |
|
|
|
|
|
|
|
|
|
|
|
|
|
936 |
function openWarmupPopup(){ if(warmupPopup) warmupPopup.style.display = 'block'; }
|
937 |
|
938 |
function closeWarmupPopup(){ if(warmupPopup) warmupPopup.style.display = 'none'; }
|
|
|
968 |
const idx = (s.idx ?? 0) + 1;
|
969 |
warmupStatusEl.textContent = `⏳ ${pct}% — ${s.current||''} (${idx}/${tot}) [inst:${instanceId}]`;
|
970 |
} else {
|
971 |
+
// Si le run vient de se terminer et que le backend expose ok_count, on priorise ce résumé
|
972 |
+
if (s.done && Number.isFinite(s.ok_count)) {
|
973 |
+
warmupStatusEl.textContent = `✅ Terminé — ${s.ok_count}/${tot} téléchargés (inst:${instanceId})`;
|
|
|
|
|
974 |
} else {
|
975 |
+
const nCache = Number.isFinite(s.audit_count)
|
976 |
+
? s.audit_count
|
977 |
+
: (Array.isArray(s.audit_cached) ? s.audit_cached.length : 0);
|
978 |
+
if (nCache > 0) {
|
979 |
+
warmupStatusEl.textContent = `✅ Prêt — cache local: ${nCache} (inst:${instanceId})`;
|
980 |
+
} else {
|
981 |
+
warmupStatusEl.textContent = `Prêt (aucun run)`;
|
982 |
+
}
|
983 |
}
|
984 |
|
985 |
}
|
|
|
988 |
if (warmupProgressFill) warmupProgressFill.style.width = pct + '%';
|
989 |
if (warmupPopupStatus) warmupPopupStatus.textContent = running ? 'Téléchargement en cours…' : 'Terminé';
|
990 |
|
991 |
+
// PRÉAMBULE FIXE (conservé pendant tout le run)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
992 |
const logsTxt = Array.isArray(s.logs) ? s.logs.join('\n') : '';
|
993 |
+
const fixedPreface = (warmupPreface && warmupPreface.trim().length)
|
994 |
+
? warmupPreface
|
995 |
+
: (()=>{
|
996 |
+
const n = Number.isFinite(s.audit_count)
|
997 |
+
? s.audit_count
|
998 |
+
: (Array.isArray(s.audit_cached) ? s.audit_cached.length : 0);
|
999 |
+
const cachedList = Array.isArray(s.audit_cached) ? s.audit_cached : [];
|
1000 |
+
const asked = Array.isArray(window.lastRequestedModels) ? window.lastRequestedModels : [];
|
1001 |
+
return (
|
1002 |
+
`[Instance ${instanceId}]` + '\n' +
|
1003 |
+
'Déjà en cache (' + n + '):\n' +
|
1004 |
+
cachedList.map(m => ' • ' + m).join('\n') + '\n\n' +
|
1005 |
+
'Demandé dans cette exécution (' + asked.length + '):\n' +
|
1006 |
+
asked.map(m => ' • ' + m).join('\n')
|
1007 |
+
);
|
1008 |
+
})();
|
1009 |
+
if (warmupLogs) warmupLogs.textContent = fixedPreface + '\n\n' + logsTxt;
|
1010 |
|
1011 |
|
1012 |
if (warmupStopBtn) warmupStopBtn.style.display = running ? 'inline-block' : 'none';
|
|
|
1089 |
alert('Échec démarrage: ' + r.status + ' ' + t);
|
1090 |
return;
|
1091 |
}
|
1092 |
+
// Si un warm-up tourne déjà, on l'indique et on passe en mode "suivi"
|
1093 |
+
try {
|
1094 |
+
const payload = await r.json();
|
1095 |
+
if (payload && payload.already_running) {
|
1096 |
+
showToast("Un warm-up est déjà en cours — j'affiche l'état.");
|
1097 |
+
}
|
1098 |
+
} catch(e) { /* no-op */ }
|
1099 |
+
|
1100 |
// Rafraîchit l’UI et démarre le polling
|
1101 |
await refreshWarmupUI();
|
1102 |
if (!warmupTimer) warmupTimer = setInterval(refreshWarmupUI, 1000);
|
|
|
1107 |
});
|
1108 |
}
|
1109 |
|
|
|
|
|
|
|
|
|
|
|
1110 |
if (warmupLogsBtn){
|
1111 |
warmupLogsBtn.addEventListener('click', async ()=>{
|
1112 |
|