Update app.py
Browse files
app.py
CHANGED
@@ -143,7 +143,13 @@ def _default_model_list() -> List[str]:
|
|
143 |
try:
|
144 |
lst = json.loads(env)
|
145 |
if isinstance(lst, list):
|
146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
except Exception:
|
148 |
pass
|
149 |
return []
|
@@ -485,25 +491,35 @@ def video_meta(vid: str):
|
|
485 |
|
486 |
@app.post("/upload", tags=["io"])
|
487 |
async def upload(request: Request, file: UploadFile = File(...), redirect: Optional[bool] = True):
|
488 |
-
|
|
|
|
|
|
|
|
|
489 |
if ext not in {".mp4", ".mov", ".mkv", ".webm"}:
|
490 |
raise HTTPException(400, "Formats acceptés : mp4/mov/mkv/webm")
|
491 |
-
|
492 |
dst = DATA_DIR / base
|
493 |
if dst.exists():
|
494 |
dst = DATA_DIR / f"{Path(base).stem}__{uuid.uuid4().hex[:8]}{ext}"
|
|
|
495 |
with dst.open("wb") as f:
|
496 |
shutil.copyfileobj(file.file, f)
|
|
|
497 |
print(f"[UPLOAD] Saved {dst.name} ({dst.stat().st_size} bytes)", file=sys.stdout)
|
|
|
498 |
_poster(dst)
|
499 |
stem = dst.stem
|
500 |
threading.Thread(target=_gen_thumbs_background, args=(dst, stem), daemon=True).start()
|
|
|
501 |
accept = (request.headers.get("accept") or "").lower()
|
502 |
if redirect or "text/html" in accept:
|
503 |
msg = urllib.parse.quote(f"Vidéo importée : {dst.name}. Génération thumbs en cours…")
|
504 |
return RedirectResponse(url=f"/ui?v={urllib.parse.quote(dst.name)}&msg={msg}", status_code=303)
|
|
|
505 |
return {"name": dst.name, "size_bytes": dst.stat().st_size, "gen_started": True}
|
506 |
|
|
|
507 |
@app.get("/progress/{vid_stem}", tags=["io"])
|
508 |
def progress(vid_stem: str):
|
509 |
return progress_data.get(vid_stem, {'percent': 0, 'logs': [], 'done': False})
|
@@ -566,10 +582,12 @@ async def warmup_start(payload: Optional[Dict[str, Any]] = Body(None)):
|
|
566 |
if payload and isinstance(payload, dict):
|
567 |
models = [str(x).strip() for x in (payload.get("models") or []) if str(x).strip()]
|
568 |
if not models:
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
|
|
|
|
573 |
|
574 |
if not models:
|
575 |
raise HTTPException(400, "Aucun modèle fourni (payload.models) et WARMUP_MODELS vide")
|
@@ -694,6 +712,9 @@ def warmup_catalog():
|
|
694 |
"lixiaowen/diffuEraser",
|
695 |
"facebook/sam2-hiera-base",
|
696 |
]
|
|
|
|
|
|
|
697 |
|
698 |
seen = set()
|
699 |
out = [m for m in base if not (m in seen or seen.add(m))]
|
|
|
143 |
try:
|
144 |
lst = json.loads(env)
|
145 |
if isinstance(lst, list):
|
146 |
+
# correction douce de typos connues
|
147 |
+
fixups = {"stabilityai/sd-vae-ft-ms": "stabilityai/sd-vae-ft-mse"}
|
148 |
+
cleaned = [fixups.get(str(x).strip(), str(x).strip()) for x in lst if str(x).strip()]
|
149 |
+
return cleaned
|
150 |
+
|
151 |
+
|
152 |
+
|
153 |
except Exception:
|
154 |
pass
|
155 |
return []
|
|
|
491 |
|
492 |
@app.post("/upload", tags=["io"])
|
493 |
async def upload(request: Request, file: UploadFile = File(...), redirect: Optional[bool] = True):
|
494 |
+
# Sécuriser le nom de fichier (UploadFile.filename peut être None)
|
495 |
+
fname = file.filename or "upload.mp4"
|
496 |
+
base = _safe_name(fname)
|
497 |
+
ext = (Path(base).suffix or ".mp4").lower()
|
498 |
+
|
499 |
if ext not in {".mp4", ".mov", ".mkv", ".webm"}:
|
500 |
raise HTTPException(400, "Formats acceptés : mp4/mov/mkv/webm")
|
501 |
+
|
502 |
dst = DATA_DIR / base
|
503 |
if dst.exists():
|
504 |
dst = DATA_DIR / f"{Path(base).stem}__{uuid.uuid4().hex[:8]}{ext}"
|
505 |
+
|
506 |
with dst.open("wb") as f:
|
507 |
shutil.copyfileobj(file.file, f)
|
508 |
+
|
509 |
print(f"[UPLOAD] Saved {dst.name} ({dst.stat().st_size} bytes)", file=sys.stdout)
|
510 |
+
|
511 |
_poster(dst)
|
512 |
stem = dst.stem
|
513 |
threading.Thread(target=_gen_thumbs_background, args=(dst, stem), daemon=True).start()
|
514 |
+
|
515 |
accept = (request.headers.get("accept") or "").lower()
|
516 |
if redirect or "text/html" in accept:
|
517 |
msg = urllib.parse.quote(f"Vidéo importée : {dst.name}. Génération thumbs en cours…")
|
518 |
return RedirectResponse(url=f"/ui?v={urllib.parse.quote(dst.name)}&msg={msg}", status_code=303)
|
519 |
+
|
520 |
return {"name": dst.name, "size_bytes": dst.stat().st_size, "gen_started": True}
|
521 |
|
522 |
+
|
523 |
@app.get("/progress/{vid_stem}", tags=["io"])
|
524 |
def progress(vid_stem: str):
|
525 |
return progress_data.get(vid_stem, {'percent': 0, 'logs': [], 'done': False})
|
|
|
582 |
if payload and isinstance(payload, dict):
|
583 |
models = [str(x).strip() for x in (payload.get("models") or []) if str(x).strip()]
|
584 |
if not models:
|
585 |
+
# Correction douce de typos connues + dé-doublonnage
|
586 |
+
fixups = {"stabilityai/sd-vae-ft-ms": "stabilityai/sd-vae-ft-mse"}
|
587 |
+
models = [fixups.get(m, m) for m in models]
|
588 |
+
seen = set()
|
589 |
+
models = [m for m in models if not (m in seen or seen.add(m))]
|
590 |
+
|
591 |
|
592 |
if not models:
|
593 |
raise HTTPException(400, "Aucun modèle fourni (payload.models) et WARMUP_MODELS vide")
|
|
|
712 |
"lixiaowen/diffuEraser",
|
713 |
"facebook/sam2-hiera-base",
|
714 |
]
|
715 |
+
# Correction douce de typos connues (catalog)
|
716 |
+
fixups = {"stabilityai/sd-vae-ft-ms": "stabilityai/sd-vae-ft-mse"}
|
717 |
+
base = [fixups.get(m, m) for m in base]
|
718 |
|
719 |
seen = set()
|
720 |
out = [m for m in base if not (m in seen or seen.add(m))]
|