Update app.py
Browse files
app.py
CHANGED
|
@@ -517,6 +517,60 @@ def poster(vid: str):
|
|
| 517 |
return FileResponse(str(p), media_type="image/jpeg")
|
| 518 |
raise HTTPException(404, "Poster introuvable")
|
| 519 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 520 |
# >>> A1_BEGIN window_fix
|
| 521 |
@app.get("/window/{vid}", tags=["io"])
|
| 522 |
def window(vid: str, center: int = 0, count: int = 21):
|
|
|
|
| 517 |
return FileResponse(str(p), media_type="image/jpeg")
|
| 518 |
raise HTTPException(404, "Poster introuvable")
|
| 519 |
|
| 520 |
+
# >>> B1_BEGIN warmup_routes
|
| 521 |
+
from copy import deepcopy
|
| 522 |
+
|
| 523 |
+
@app.post("/warmup/start", tags=["warmup"])
|
| 524 |
+
async def warmup_start(payload: Optional[Dict[str, Any]] = Body(None)):
|
| 525 |
+
"""
|
| 526 |
+
Démarre le téléchargement séquentiel des modèles.
|
| 527 |
+
Corps JSON optionnel: { "models": ["repo1","repo2", ...] }
|
| 528 |
+
Si vide: lit la variable d'env WARMUP_MODELS (JSON).
|
| 529 |
+
"""
|
| 530 |
+
models = []
|
| 531 |
+
if payload and isinstance(payload, dict):
|
| 532 |
+
models = [str(x).strip() for x in (payload.get("models") or []) if str(x).strip()]
|
| 533 |
+
if not models:
|
| 534 |
+
models = _default_model_list()
|
| 535 |
+
if not models:
|
| 536 |
+
raise HTTPException(400, "Aucun modèle fourni (payload.models) et WARMUP_MODELS vide")
|
| 537 |
+
|
| 538 |
+
with warmup_lock:
|
| 539 |
+
if warmup_state.get("running"):
|
| 540 |
+
# Déjà en cours : on renvoie l'état actuel pour info
|
| 541 |
+
return {
|
| 542 |
+
"ok": False,
|
| 543 |
+
"already_running": True,
|
| 544 |
+
"status": deepcopy(warmup_state),
|
| 545 |
+
}
|
| 546 |
+
# Lancer un nouveau thread
|
| 547 |
+
job_id = uuid.uuid4().hex[:8]
|
| 548 |
+
warmup_state["job_id"] = job_id
|
| 549 |
+
th = threading.Thread(target=_warmup_thread, args=(models,), daemon=True)
|
| 550 |
+
th.start()
|
| 551 |
+
|
| 552 |
+
return {"ok": True, "started": True, "total": len(models), "job_id": job_id}
|
| 553 |
+
|
| 554 |
+
@app.get("/warmup/status", tags=["warmup"])
|
| 555 |
+
def warmup_status():
|
| 556 |
+
""" Retourne l'état courant du warm-up (progression, logs, etc.). """
|
| 557 |
+
with warmup_lock:
|
| 558 |
+
data = deepcopy(warmup_state)
|
| 559 |
+
data["ts"] = time.time()
|
| 560 |
+
return data
|
| 561 |
+
|
| 562 |
+
@app.post("/warmup/stop", tags=["warmup"])
|
| 563 |
+
def warmup_stop_api():
|
| 564 |
+
""" Demande l'arrêt propre (on termine le modèle en cours puis on stoppe). """
|
| 565 |
+
with warmup_lock:
|
| 566 |
+
running = bool(warmup_state.get("running"))
|
| 567 |
+
if running:
|
| 568 |
+
warmup_stop.set()
|
| 569 |
+
return {"ok": True, "was_running": True}
|
| 570 |
+
return {"ok": True, "was_running": False}
|
| 571 |
+
# >>> B1_END warmup_routes
|
| 572 |
+
|
| 573 |
+
|
| 574 |
# >>> A1_BEGIN window_fix
|
| 575 |
@app.get("/window/{vid}", tags=["io"])
|
| 576 |
def window(vid: str, center: int = 0, count: int = 21):
|