| 1 | # Copyright (C) 2025 AIDC-AI |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | # See the License for the specific language governing permissions and |
| 11 | # limitations under the License. |
| 12 | |
| 13 | """ |
| 14 | Video generation API schemas |
| 15 | """ |
| 16 | |
| 17 | from typing import Optional, Literal, Dict, Any |
| 18 | from pydantic import BaseModel, Field |
| 19 | |
| 20 | |
| 21 | class VideoGenerateRequest(BaseModel): |
| 22 | """Video generation request""" |
| 23 | |
| 24 | # === Input === |
| 25 | text: str = Field(..., description="Source text for video generation") |
| 26 | |
| 27 | # === Processing Mode === |
| 28 | mode: Literal["generate", "fixed"] = Field( |
| 29 | "generate", |
| 30 | description="Processing mode: 'generate' (AI generates narrations) or 'fixed' (use text as-is)" |
| 31 | ) |
| 32 | |
| 33 | # === Optional Title === |
| 34 | title: Optional[str] = Field(None, description="Video title (auto-generated if not provided)") |
| 35 | |
| 36 | # === Basic Config === |
| 37 | n_scenes: Optional[int] = Field(5, ge=1, le=20, description="Number of scenes (only used in 'generate' mode, ignored in 'fixed' mode)") |
| 38 | |
| 39 | # === TTS Parameters === |
| 40 | tts_workflow: Optional[str] = Field( |
| 41 | None, |
| 42 | description="TTS workflow key (e.g., 'runninghub/tts_edge.json'). If not specified, uses default workflow from config." |
| 43 | ) |
| 44 | ref_audio: Optional[str] = Field( |
| 45 | None, |
| 46 | description="Reference audio path for voice cloning (optional)" |
| 47 | ) |
| 48 | voice_id: Optional[str] = Field( |
| 49 | None, |
| 50 | description="(Deprecated) TTS voice ID for legacy compatibility" |
| 51 | ) |
| 52 | |
| 53 | # === LLM Parameters === |
| 54 | min_narration_words: int = Field(5, ge=1, le=100, description="Min narration words") |
| 55 | max_narration_words: int = Field(20, ge=1, le=200, description="Max narration words") |
| 56 | min_image_prompt_words: int = Field(30, ge=10, le=100, description="Min image prompt words") |
| 57 | max_image_prompt_words: int = Field(60, ge=10, le=200, description="Max image prompt words") |
| 58 | |
| 59 | # === Media Parameters === |
| 60 | # Note: media_width and media_height are auto-determined from template meta tags |
| 61 | media_workflow: Optional[str] = Field(None, description="Custom media workflow (image or video)") |
| 62 | |
| 63 | # === Video Parameters === |
| 64 | video_fps: int = Field(30, ge=15, le=60, description="Video FPS") |
| 65 | |
| 66 | # === Frame Template (determines video size) === |
| 67 | frame_template: Optional[str] = Field( |
| 68 | None, |
| 69 | description="HTML template path with size (e.g., '1080x1920/default.html'). Video size is auto-determined from template." |
| 70 | ) |
| 71 | |
| 72 | # === Template Custom Parameters === |
| 73 | template_params: Optional[Dict[str, Any]] = Field( |
| 74 | None, |
| 75 | description="Custom template parameters (e.g., {'accent_color': '#ff0000', 'background': 'url'}). " |
| 76 | "Available parameters depend on the template. Use GET /api/templates/{template_path}/params to discover them." |
| 77 | ) |
| 78 | |
| 79 | # === Image Style === |
| 80 | prompt_prefix: Optional[str] = Field(None, description="Image style prefix") |
| 81 | |
| 82 | # === BGM === |
| 83 | bgm_path: Optional[str] = Field(None, description="Background music path") |
| 84 | bgm_volume: float = Field(0.3, ge=0.0, le=1.0, description="BGM volume (0.0-1.0)") |
| 85 | |
| 86 | class Config: |
| 87 | json_schema_extra = { |
| 88 | "example": { |
| 89 | "text": "Atomic Habits teaches us that small changes compound over time to produce remarkable results.", |
| 90 | "mode": "generate", |
| 91 | "n_scenes": 5, |
| 92 | "frame_template": "1080x1920/image_default.html", |
| 93 | "template_params": { |
| 94 | "accent_color": "#3498db", |
| 95 | "background": "https://example.com/custom-bg.jpg" |
| 96 | }, |
| 97 | "title": "The Power of Atomic Habits" |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | |
| 102 | class VideoGenerateResponse(BaseModel): |
| 103 | """Video generation response (synchronous)""" |
| 104 | success: bool = True |
| 105 | message: str = "Success" |
| 106 | video_url: str = Field(..., description="URL to access generated video") |
| 107 | duration: float = Field(..., description="Video duration in seconds") |
| 108 | file_size: int = Field(..., description="File size in bytes") |
| 109 | |
| 110 | |
| 111 | class VideoGenerateAsyncResponse(BaseModel): |
| 112 | """Video generation async response""" |
| 113 | success: bool = True |
| 114 | message: str = "Task created successfully" |
| 115 | task_id: str = Field(..., description="Task ID for tracking progress") |
| 116 | |
| 117 |