cmvr-visual/inference/llm_services/video_edit/profiles.py
zhanghao 88cf14d794 feat: consolidate story studio and editable automatic production
Restructure backend and frontend modules; add story, library, and editor schema migrations.

Support editable automatic production, manual confirmation modes, account and user lifecycle management, compact container scrolling, consistent forms, and per-task result previews.

Update inference and TTS scheduling, deployment guidance, and regression coverage; remove obsolete standalone pages and temporary acceptance artifacts.
2026-11-14 14:07:26 +08:00

123 lines
4.9 KiB
Python

"""Operator-certified profile; readiness never follows a client flag."""
import json
from pathlib import Path
from .protocol import PROFILE, sha256
REVISION = "6f4df10861c758af86ac3c979aacc1bf5c03eff0"
MODEL = "Wan-AI/Wan2.2-Animate-14B-Diffusers"
def validate_settings(settings):
for name in ("video_edit_enabled", "video_edit_poc_enabled"):
if type(getattr(settings, name)) is not bool:
raise ValueError(name + " must be boolean")
if settings.video_edit_profile != PROFILE:
raise ValueError("Unsupported video edit profile")
if type(
settings.video_edit_max_pixels
) is not int or settings.video_edit_max_pixels not in (399360, 921600):
raise ValueError("Unsupported configured video pixel budget")
for name in ("video_edit_max_seconds", "video_edit_max_people"):
if type(getattr(settings, name)) is not int or getattr(settings, name) < 1:
raise ValueError(name + " must be positive integer")
def deployment(settings, verify=False):
from ..store import confined_path, open_confined_file
receipt = settings.app_root / "config" / "video-edit-models.json"
with open_confined_file(receipt, settings.workspace_root) as stream:
data = json.load(stream)
if (
data.get("profile") != PROFILE
or data.get("revision") != REVISION
or not data.get("files")
):
raise ValueError("Video model receipt has wrong profile/revision or no files")
for field in ("model_dir", "preprocess_dir", "checkpoint_dir"):
data[field] = str(
confined_path(data[field], settings.workspace_root, must_exist=True)
)
required = [
Path(data["model_dir"]) / "model_index.json",
Path(data["checkpoint_dir"]) / "det/yolov10m.onnx",
Path(data["checkpoint_dir"]) / "pose2d/vitpose_h_wholebody.onnx/end2end.onnx",
Path(data["checkpoint_dir"]) / "sam2/sam2_hiera_large.pt",
]
required += [
Path(data["preprocess_dir"]) / name
for name in (
"pose2d.py",
"pose2d_utils.py",
"human_visualization.py",
"utils.py",
)
]
listed = {str(Path(entry["path"]).resolve()) for entry in data["files"]}
if any(
not file.is_file() or str(file.resolve()) not in listed for file in required
):
raise ValueError(
"Video model receipt does not cover required checkpoints and code"
)
# Every loaded model/external ONNX tensor must be covered, not just an
# arbitrary sentinel file in the operator receipt.
for field in ("model_dir", "checkpoint_dir"):
for file in Path(data[field]).rglob("*"):
if (
file.is_file()
and not any(
part.startswith(".") for part in file.relative_to(data[field]).parts
)
and str(file.resolve()) not in listed
):
raise ValueError("Unverified video model file in deployment directory")
for entry in data["files"]:
path = confined_path(
entry["path"], settings.workspace_root, must_exist=True, file_only=True
)
if path.stat().st_size != entry["size"] or (
verify and sha256(path) != entry["sha256"]
):
raise ValueError("Video model integrity check failed")
return data
def capabilities(settings):
reason = "Video replacement has not passed real model validation"
ready = False
try:
receipt = deployment(settings)
ready = receipt.get("validated") is True
if not ready:
reason = "Video model PoC validation is pending"
except (OSError, ValueError, KeyError, TypeError):
reason = "Pinned video models or preprocessing dependencies are not ready"
available = settings.video_edit_enabled and ready
return {
"available": available,
"profile": PROFILE,
"model": MODEL,
"max_seconds": settings.video_edit_max_seconds,
"max_people": settings.video_edit_max_people,
"max_pixels": settings.video_edit_max_pixels,
"fps": 24,
"reason": None if available else reason,
}
def validate_submission(settings, inputs, parameters):
if not (settings.video_edit_enabled or settings.video_edit_poc_enabled):
raise ValueError("Video editing is disabled until validated")
receipt = deployment(settings)
if not settings.video_edit_poc_enabled and receipt.get("validated") is not True:
raise ValueError("Video editing has not passed model validation")
if parameters.get("profile", PROFILE) != settings.video_edit_profile:
raise ValueError("Video editing profile mismatch")
if parameters.get("max_pixels", 399360) > settings.video_edit_max_pixels:
raise ValueError("Requested video pixel budget exceeds certified capability")
if len(inputs.get("replacements", [])) > settings.video_edit_max_people:
raise ValueError("Too many replacement people")