Add video generation API with job tracking and model loading

This commit is contained in:
2026-06-03 18:58:11 -04:00
parent bd0cd4f9ff
commit ab580a2004
11 changed files with 388 additions and 68 deletions
+25 -8
View File
@@ -2,18 +2,35 @@ from __future__ import annotations
from typing import Optional
from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, field_validator
from app.config import settings
# --- Request ---
class GenerateRequest(BaseModel):
prompt: Optional[str] = Field(None, description="Optional text prompt to guide generation")
width: int = Field(768, ge=256, le=2048, multiple_of=32, description="Video width (must be divisible by 32)")
height: int = Field(512, ge=256, le=2048, multiple_of=32, description="Video height (must be divisible by 32)")
num_frames: int = Field(65, ge=9, le=257, description="Frame count (must be 8n+1)")
fps: float = Field(24.0, gt=0, le=60, description="Frames per second")
seed: Optional[int] = Field(None, description="Random seed for reproducibility")
class GenerateForm(BaseModel):
prompt: Optional[str] = Field(None, max_length=1000)
width: int = Field(768, ge=256, le=2048, multiple_of=32)
height: int = Field(512, ge=256, le=2048, multiple_of=32)
num_frames: int = Field(65, ge=9, le=settings.max_frame_count)
fps: float = Field(24.0, gt=0, le=60)
seed: Optional[int] = Field(None)
model_config = {"extra": "forbid"}
@field_validator("num_frames")
@classmethod
def check_frames(cls, v: int) -> int:
if v % 8 != 1:
n = v // 8
candidates = sorted(
8 * i + 1
for i in range(max(1, n - 2), n + 3)
if 8 * i + 1 <= settings.max_frame_count
)
raise ValueError(f"num_frames must be 8n+1. Got {v}. Closest valid: {candidates}")
return v
# --- Job Status ---