FABLESLIP commited on
Commit
13e305e
·
verified ·
1 Parent(s): 86b3d9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -5
app.py CHANGED
@@ -358,8 +358,9 @@ def _gen_thumbs_background(video: Path, vid_stem: str):
358
  def root():
359
  return {
360
  "ok": True,
361
- "routes": ["/", "/health", "/files", "/upload", "/meta/{vid}", "/frame_idx", "/poster/{vid}", "/window/{vid}",
362
- "/mask", "/mask/{vid}", "/mask/rename", "/mask/delete", "/progress/{vid_stem}", "/ui"]
 
363
  }
364
 
365
  @app.get("/health", tags=["meta"])
@@ -504,6 +505,47 @@ def warmup_stop_api():
504
  return {"ok": True, "was_running": False}
505
  # >>> B1_END warmup_routes
506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
507
 
508
  # >>> A1_BEGIN window_fix
509
  @app.get("/window/{vid}", tags=["io"])
@@ -841,6 +883,9 @@ const warmupCloseBtn = document.getElementById('warmupCloseBtn');
841
  // Helpers popup
842
 
843
 
 
 
 
844
 
845
 
846
 
@@ -886,7 +931,20 @@ async function refreshWarmupUI(){
886
  }
887
  if (warmupProgressFill) warmupProgressFill.style.width = pct + '%';
888
  if (warmupPopupStatus) warmupPopupStatus.textContent = running ? 'Téléchargement en cours…' : 'Terminé';
889
- if (warmupLogs && Array.isArray(s.logs)) warmupLogs.textContent = s.logs.join('\n');
 
 
 
 
 
 
 
 
 
 
 
 
 
890
  if (warmupStopBtn) warmupStopBtn.style.display = running ? 'inline-block' : 'none';
891
 
892
  if (running) {
@@ -923,14 +981,33 @@ if (warmupStartBtn){
923
  models = DEFAULT_MODELS;
924
  }
925
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
926
  // Ouvre la popup et affiche immédiatement la liste demandée
927
  openWarmupPopup();
928
  if (warmupPopupStatus) warmupPopupStatus.textContent = 'Préparation en cours…';
929
- if (warmupLogs) {
930
- warmupLogs.textContent = 'Warm-up demandé pour :\n' + models.map(m=>' '+m).join('\n');
931
  warmupLogs.scrollTop = warmupLogs.scrollHeight; // auto-scroll vers le bas
932
  }
933
 
 
934
  // Sécurité : évite 2 timers concurrents
935
  if (warmupTimer) { clearInterval(warmupTimer); warmupTimer = null; }
936
 
@@ -962,6 +1039,20 @@ if (warmupStartBtn){
962
 
963
  if (warmupLogsBtn){
964
  warmupLogsBtn.addEventListener('click', async ()=>{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
965
  openWarmupPopup();
966
  await refreshWarmupUI();
967
  if (!warmupTimer) warmupTimer = setInterval(refreshWarmupUI, 1000);
 
358
  def root():
359
  return {
360
  "ok": True,
361
+ "routes": ["/", "/health", "/files", "/upload", "/meta/{vid}", "/frame_idx", "/poster/{vid}", "/window/{vid}",
362
+ "/mask", "/mask/{vid}", "/mask/rename", "/mask/delete", "/progress/{vid_stem}", "/ui",
363
+ "/warmup/start", "/warmup/status", "/warmup/stop", "/warmup/audit"]
364
  }
365
 
366
  @app.get("/health", tags=["meta"])
 
505
  return {"ok": True, "was_running": False}
506
  # >>> B1_END warmup_routes
507
 
508
+ # >>> B2_BEGIN warmup_audit
509
+ def _hf_cache_dir() -> str:
510
+ return os.path.expanduser(os.getenv("HF_HOME", "/home/user/.cache/huggingface"))
511
+
512
+ def _is_repo_cached(repo_id: str) -> bool:
513
+ local_dir = os.path.join(_hf_cache_dir(), "models", repo_id.replace("/", "__"))
514
+ try:
515
+ return os.path.isdir(local_dir) and any(os.scandir(local_dir))
516
+ except FileNotFoundError:
517
+ return False
518
+
519
+ def _list_cached_repos() -> List[str]:
520
+ base = os.path.join(_hf_cache_dir(), "models")
521
+ out: List[str] = []
522
+ try:
523
+ for e in os.scandir(base):
524
+ if e.is_dir():
525
+ out.append(e.name.replace("__", "/"))
526
+ except FileNotFoundError:
527
+ pass
528
+ return sorted(out)
529
+
530
+ @app.get("/warmup/audit", tags=["warmup"])
531
+ def warmup_audit():
532
+ """
533
+ Retourne l'état du cache HF côté serveur.
534
+ - cached: tous les repos détectés localement
535
+ - present_default / missing_default: croisement avec WARMUP_MODELS (si défini)
536
+ """
537
+ cached = _list_cached_repos()
538
+ defaults = _default_model_list()
539
+ present_default = [r for r in defaults if r in cached]
540
+ missing_default = [r for r in defaults if r not in cached]
541
+ return {
542
+ "count": len(cached),
543
+ "cached": cached,
544
+ "present_default": present_default,
545
+ "missing_default": missing_default,
546
+ }
547
+ # >>> B2_END warmup_audit
548
+
549
 
550
  # >>> A1_BEGIN window_fix
551
  @app.get("/window/{vid}", tags=["io"])
 
883
  // Helpers popup
884
 
885
 
886
+ // >>> C2_BEGIN warmup_preface
887
+ let warmupPreface = '';
888
+ // >>> C2_END warmup_preface
889
 
890
 
891
 
 
931
  }
932
  if (warmupProgressFill) warmupProgressFill.style.width = pct + '%';
933
  if (warmupPopupStatus) warmupPopupStatus.textContent = running ? 'Téléchargement en cours…' : 'Terminé';
934
+
935
+
936
+
937
+
938
+
939
+
940
+
941
+ const logsTxt = Array.isArray(s.logs) ? s.logs.join('\n') : '';
942
+ if (warmupLogs) warmupLogs.textContent = (warmupPreface ? (warmupPreface + '\n') : '') + logsTxt;
943
+
944
+
945
+
946
+
947
+
948
  if (warmupStopBtn) warmupStopBtn.style.display = running ? 'inline-block' : 'none';
949
 
950
  if (running) {
 
981
  models = DEFAULT_MODELS;
982
  }
983
 
984
+
985
+ // Préface (audit du cache serveur, pour afficher le cumul)
986
+ try {
987
+ const ra = await fetch('/warmup/audit');
988
+ const audit = ra.ok ? await ra.json() : null;
989
+ const cached = (audit && Array.isArray(audit.cached)) ? audit.cached : [];
990
+ warmupPreface =
991
+ 'Déjà en cache (' + cached.length + '):\n' +
992
+ cached.map(m => ' • ' + m).join('\n') + '\n\n' +
993
+ 'Demandé dans cette exécution (' + models.length + '):\n' +
994
+ models.map(m => ' • ' + m).join('\n');
995
+ } catch(e) {
996
+ warmupPreface = '';
997
+ }
998
+
999
+
1000
+
1001
+
1002
  // Ouvre la popup et affiche immédiatement la liste demandée
1003
  openWarmupPopup();
1004
  if (warmupPopupStatus) warmupPopupStatus.textContent = 'Préparation en cours…';
1005
+ if (warmupLogs) {
1006
+ warmupLogs.textContent = (warmupPreface ? warmupPreface + '\n' : '') + '— démarrage…';
1007
  warmupLogs.scrollTop = warmupLogs.scrollHeight; // auto-scroll vers le bas
1008
  }
1009
 
1010
+
1011
  // Sécurité : évite 2 timers concurrents
1012
  if (warmupTimer) { clearInterval(warmupTimer); warmupTimer = null; }
1013
 
 
1039
 
1040
  if (warmupLogsBtn){
1041
  warmupLogsBtn.addEventListener('click', async ()=>{
1042
+
1043
+ // Recalcule une préface à la volée (hors exécution)
1044
+ try{
1045
+ const ra = await fetch('/warmup/audit');
1046
+ const audit = ra.ok ? await ra.json() : null;
1047
+ const cached = (audit && Array.isArray(audit.cached)) ? audit.cached : [];
1048
+ if (!warmupPreface) {
1049
+ warmupPreface =
1050
+ 'Déjà en cache (' + cached.length + '):\n' +
1051
+ cached.map(m => ' • ' + m).join('\n');
1052
+ }
1053
+ }catch(e){}
1054
+
1055
+
1056
  openWarmupPopup();
1057
  await refreshWarmupUI();
1058
  if (!warmupTimer) warmupTimer = setInterval(refreshWarmupUI, 1000);