Add video generation API with job tracking and model loading
This commit is contained in:
+25
-8
@@ -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 ---
|
||||
|
||||
Reference in New Issue
Block a user