FABLESLIP commited on
Commit
ae85eba
·
verified ·
1 Parent(s): f2b6c38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py CHANGED
@@ -410,6 +410,74 @@ async def upload(request: Request, file: UploadFile = File(...), redirect: Optio
410
  def progress(vid_stem: str):
411
  return progress_data.get(vid_stem, {'percent': 0, 'logs': [], 'done': False})
412
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
  @app.delete("/delete/{vid}", tags=["io"])
414
  def delete_video(vid: str):
415
  v = DATA_DIR / vid
 
410
  def progress(vid_stem: str):
411
  return progress_data.get(vid_stem, {'percent': 0, 'logs': [], 'done': False})
412
 
413
+ # >>> B1_BEGIN warmup_routes
414
+ @app.post("/warmup/start", tags=["warmup"])
415
+ async def warmup_start(request: Request, payload: Optional[Dict[str, Any]] = Body(None)):
416
+ """
417
+ Démarre un warm-up séquentiel.
418
+ Sources de la liste des modèles (dans cet ordre) :
419
+ 1) payload JSON: {"models": ["repo/a", "repo/b", ...]}
420
+ 2) query string: ?models=repo/a,repo/b
421
+ 3) env WARMUP_MODELS (JSON array)
422
+ """
423
+ with warmup_lock:
424
+ if warmup_state.get("running"):
425
+ return {
426
+ "ok": False,
427
+ "running": True,
428
+ "msg": "Warm-up déjà en cours",
429
+ "percent": warmup_state.get("percent", 0),
430
+ "current": warmup_state.get("current"),
431
+ "idx": warmup_state.get("idx", 0),
432
+ "total": warmup_state.get("total", 0),
433
+ }
434
+
435
+ # 1) payload JSON
436
+ models_list: List[str] = []
437
+ if isinstance(payload, dict):
438
+ ml = payload.get("models")
439
+ if isinstance(ml, list):
440
+ models_list = [str(x).strip() for x in ml if str(x).strip()]
441
+
442
+ # 2) query string
443
+ if not models_list:
444
+ qs_models = request.query_params.get("models") or ""
445
+ if qs_models:
446
+ models_list = [s.strip() for s in qs_models.split(",") if s.strip()]
447
+
448
+ # 3) env
449
+ if not models_list:
450
+ models_list = _default_model_list()
451
+
452
+ if not models_list:
453
+ raise HTTPException(400, "Aucun modèle fourni (body.models ou ?models=) et WARMUP_MODELS vide.")
454
+
455
+ t = threading.Thread(target=_warmup_thread, args=(models_list,), daemon=True)
456
+ t.start()
457
+ return {"ok": True, "started": True, "total": len(models_list)}
458
+
459
+ @app.get("/warmup/status", tags=["warmup"])
460
+ def warmup_status():
461
+ """
462
+ État courant du warm-up + 200 dernières lignes de logs.
463
+ """
464
+ with warmup_lock:
465
+ state = dict(warmup_state)
466
+ state["logs"] = warmup_state.get("logs", [])[-200:]
467
+ return state
468
+
469
+ @app.post("/warmup/stop", tags=["warmup"])
470
+ def warmup_stop_route():
471
+ """
472
+ Demande d'arrêt gracieux. Le modèle en cours se termine puis la boucle stoppe.
473
+ """
474
+ if not warmup_state.get("running"):
475
+ return {"ok": True, "was_running": False}
476
+ warmup_stop.set()
477
+ return {"ok": True, "was_running": True}
478
+ # >>> B1_END warmup_routes
479
+
480
+
481
  @app.delete("/delete/{vid}", tags=["io"])
482
  def delete_video(vid: str):
483
  v = DATA_DIR / vid