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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -29
app.py CHANGED
@@ -449,47 +449,59 @@ def poster(vid: str):
449
  return FileResponse(str(p), media_type="image/jpeg")
450
  raise HTTPException(404, "Poster introuvable")
451
 
 
452
  @app.get("/window/{vid}", tags=["io"])
453
  def window(vid: str, center: int = 0, count: int = 21):
454
  v = DATA_DIR / vid
455
  if not v.exists():
456
  raise HTTPException(404, "Vidéo introuvable")
 
457
  m = _meta(v)
458
  if not m:
459
  raise HTTPException(500, "Métadonnées indisponibles")
460
- frames = m["frames"]
 
461
  count = max(3, int(count))
462
- center = max(0, min(int(center), max(0, frames-1)))
 
463
  if frames <= 0:
464
  print(f"[WINDOW] frames=0 for {vid}", file=sys.stdout)
465
- return {"vid": vid, "start": start, "count": n, "selected": sel, "items": items, "frames": frames}
466
- # <<<< HUGINFACE PATCH: WARMUP ROUTES START >>>>
467
- @app.post("/warmup/start", tags=["warmup"])
468
- async def warmup_start(payload: Optional[Dict[str, Any]] = Body(None)):
469
- """
470
- Lance un téléchargement séquentiel d'une liste de modèles HF.
471
- Body JSON: {"models": ["org/modelA","org/modelB", ...]} (optionnel)
472
- À défaut, lit WARMUP_MODELS (env).
473
- """
474
- models = (payload or {}).get("models") or _default_model_list()
475
- if not isinstance(models, list) or not models:
476
- raise HTTPException(400, "Liste 'models' vide. Fournir JSON {models:[\"org/model\"]} ou variable d'environnement WARMUP_MODELS.")
477
- if warmup_state.get("running"):
478
- return {"started": False, "already_running": True, "state": warmup_state}
479
- t = threading.Thread(target=_warmup_thread, args=(models,), daemon=True)
480
- t.start()
481
- return {"started": True, "count": len(models)}
482
-
483
- @app.get("/warmup/status", tags=["warmup"])
484
- def warmup_status():
485
- with warmup_lock:
486
- return dict(warmup_state)
 
 
 
 
 
 
 
 
 
 
 
 
 
487
 
488
- @app.post("/warmup/stop", tags=["warmup"])
489
- def warmup_stop_api():
490
- warmup_stop.set()
491
- return {"stopping": True}
492
- # <<<< HUGINFACE PATCH: WARMUP ROUTES END >>>>
493
  # ----- Masques -----
494
 
495
  @app.post("/mask", tags=["mask"])
 
449
  return FileResponse(str(p), media_type="image/jpeg")
450
  raise HTTPException(404, "Poster introuvable")
451
 
452
+ # >>> A1_BEGIN window_fix
453
  @app.get("/window/{vid}", tags=["io"])
454
  def window(vid: str, center: int = 0, count: int = 21):
455
  v = DATA_DIR / vid
456
  if not v.exists():
457
  raise HTTPException(404, "Vidéo introuvable")
458
+
459
  m = _meta(v)
460
  if not m:
461
  raise HTTPException(500, "Métadonnées indisponibles")
462
+
463
+ frames = int(m.get("frames") or 0)
464
  count = max(3, int(count))
465
+ center = max(0, min(int(center), max(0, frames - 1)))
466
+
467
  if frames <= 0:
468
  print(f"[WINDOW] frames=0 for {vid}", file=sys.stdout)
469
+ return {
470
+ "vid": vid,
471
+ "start": 0,
472
+ "count": 0,
473
+ "selected": 0,
474
+ "items": [],
475
+ "frames": 0,
476
+ }
477
+
478
+ if frames <= count:
479
+ start = 0
480
+ sel = center
481
+ n = frames
482
+ else:
483
+ start = max(0, min(center - (count // 2), frames - count))
484
+ n = count
485
+ sel = center - start
486
+
487
+ items = []
488
+ bust = int(time.time() * 1000)
489
+ for i in range(n):
490
+ idx = start + i
491
+ url = f"/thumbs/f_{v.stem}_{idx}.jpg?b={bust}"
492
+ items.append({"i": i, "idx": idx, "url": url})
493
+
494
+ print(f"[WINDOW] {vid} start={start} n={n} sel={sel} frames={frames}", file=sys.stdout)
495
+ return {
496
+ "vid": vid,
497
+ "start": start,
498
+ "count": n,
499
+ "selected": sel,
500
+ "items": items,
501
+ "frames": frames,
502
+ }
503
+ # >>> A1_END window_fix
504
 
 
 
 
 
 
505
  # ----- Masques -----
506
 
507
  @app.post("/mask", tags=["mask"])