Update app.py
Browse files
app.py
CHANGED
@@ -138,6 +138,15 @@ def _download_one(repo_id: str, tries: int = 3) -> bool:
|
|
138 |
"""
|
139 |
cache_home = os.path.expanduser(os.getenv("HF_HOME", "/home/user/.cache/huggingface"))
|
140 |
local_dir = os.path.join(cache_home, "models", repo_id.replace("/", "__"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
for attempt in range(1, tries + 1):
|
142 |
if warmup_stop.is_set():
|
143 |
return False
|
@@ -185,6 +194,9 @@ def _warmup_thread(models: List[str]):
|
|
185 |
warmup_state["ok_count"] = ok_count
|
186 |
else:
|
187 |
_log_warmup(f"ÉCHEC: {repo}")
|
|
|
|
|
|
|
188 |
|
189 |
with warmup_lock:
|
190 |
warmup_state["percent"] = 100
|
@@ -487,6 +499,10 @@ async def warmup_start(payload: Optional[Dict[str, Any]] = Body(None)):
|
|
487 |
models = [str(x).strip() for x in (payload.get("models") or []) if str(x).strip()]
|
488 |
if not models:
|
489 |
models = _default_model_list()
|
|
|
|
|
|
|
|
|
490 |
if not models:
|
491 |
raise HTTPException(400, "Aucun modèle fourni (payload.models) et WARMUP_MODELS vide")
|
492 |
|
@@ -962,13 +978,15 @@ async function refreshWarmupUI(){
|
|
962 |
if (warmupStatusEl) {
|
963 |
const tot = (s.total ?? 0);
|
964 |
if (running) {
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
const idx = (s.idx ?? 0) + 1;
|
969 |
-
warmupStatusEl.textContent = `⏳ ${pct}% — ${s.current||''} (${idx}/${tot}) [inst:${instanceId}]`;
|
970 |
} else {
|
971 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 {
|
@@ -989,6 +1007,7 @@ async function refreshWarmupUI(){
|
|
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
|
@@ -1006,8 +1025,10 @@ async function refreshWarmupUI(){
|
|
1006 |
asked.map(m => ' • ' + m).join('\n')
|
1007 |
);
|
1008 |
})();
|
1009 |
-
if (warmupLogs)
|
1010 |
-
|
|
|
|
|
1011 |
|
1012 |
if (warmupStopBtn) warmupStopBtn.style.display = running ? 'inline-block' : 'none';
|
1013 |
|
|
|
138 |
"""
|
139 |
cache_home = os.path.expanduser(os.getenv("HF_HOME", "/home/user/.cache/huggingface"))
|
140 |
local_dir = os.path.join(cache_home, "models", repo_id.replace("/", "__"))
|
141 |
+
# Déjà présent localement ? On log et on saute proprement.
|
142 |
+
try:
|
143 |
+
if _is_repo_cached(repo_id):
|
144 |
+
_log_warmup(f"Déjà en cache: {repo_id} (skip)")
|
145 |
+
return True
|
146 |
+
except Exception:
|
147 |
+
# En cas d'erreur d'audit, on continue le process normal
|
148 |
+
pass
|
149 |
+
|
150 |
for attempt in range(1, tries + 1):
|
151 |
if warmup_stop.is_set():
|
152 |
return False
|
|
|
194 |
warmup_state["ok_count"] = ok_count
|
195 |
else:
|
196 |
_log_warmup(f"ÉCHEC: {repo}")
|
197 |
+
# Met à jour la progression globale après ce repo (ok ou échec)
|
198 |
+
with warmup_lock:
|
199 |
+
warmup_state["percent"] = int(((i + 1) / max(1, len(models))) * 100)
|
200 |
|
201 |
with warmup_lock:
|
202 |
warmup_state["percent"] = 100
|
|
|
499 |
models = [str(x).strip() for x in (payload.get("models") or []) if str(x).strip()]
|
500 |
if not models:
|
501 |
models = _default_model_list()
|
502 |
+
# Dé-doublonnage en conservant l'ordre
|
503 |
+
seen = set()
|
504 |
+
models = [m for m in models if not (m in seen or seen.add(m))]
|
505 |
+
|
506 |
if not models:
|
507 |
raise HTTPException(400, "Aucun modèle fourni (payload.models) et WARMUP_MODELS vide")
|
508 |
|
|
|
978 |
if (warmupStatusEl) {
|
979 |
const tot = (s.total ?? 0);
|
980 |
if (running) {
|
|
|
|
|
|
|
|
|
|
|
981 |
} else {
|
982 |
+
// Détection fin de run (par job_id) => toast récap une seule fois
|
983 |
+
if (s.done && s.job_id && window._lastNotifiedJobId !== s.job_id) {
|
984 |
+
const tot2 = (s.total ?? 0);
|
985 |
+
const ok2 = Number.isFinite(s.ok_count) ? s.ok_count : '—';
|
986 |
+
showToast(`Warm-up terminé — ${ok2}/${tot2} téléchargés (inst:${instanceId})`);
|
987 |
+
window._lastNotifiedJobId = s.job_id;
|
988 |
+
}
|
989 |
+
|
990 |
if (s.done && Number.isFinite(s.ok_count)) {
|
991 |
warmupStatusEl.textContent = `✅ Terminé — ${s.ok_count}/${tot} téléchargés (inst:${instanceId})`;
|
992 |
} else {
|
|
|
1007 |
if (warmupPopupStatus) warmupPopupStatus.textContent = running ? 'Téléchargement en cours…' : 'Terminé';
|
1008 |
|
1009 |
// PRÉAMBULE FIXE (conservé pendant tout le run)
|
1010 |
+
// (Auto-scroll sur chaque rafraîchissement)
|
1011 |
const logsTxt = Array.isArray(s.logs) ? s.logs.join('\n') : '';
|
1012 |
const fixedPreface = (warmupPreface && warmupPreface.trim().length)
|
1013 |
? warmupPreface
|
|
|
1025 |
asked.map(m => ' • ' + m).join('\n')
|
1026 |
);
|
1027 |
})();
|
1028 |
+
if (warmupLogs) {
|
1029 |
+
warmupLogs.textContent = fixedPreface + '\n\n' + logsTxt;
|
1030 |
+
warmupLogs.scrollTop = warmupLogs.scrollHeight;
|
1031 |
+
}
|
1032 |
|
1033 |
if (warmupStopBtn) warmupStopBtn.style.display = running ? 'inline-block' : 'none';
|
1034 |
|