返回 Pixelle-Video
frame.py
根目录 / api / schemas / frame.py
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 Frame/Template rendering API schemas
15 """
16
17 from typing import Optional, Dict, Any, List
18 from pydantic import BaseModel, Field
19
20
21 class FrameRenderRequest(BaseModel):
22 """Frame rendering request"""
23 template: str = Field(
24 ...,
25 description="Template key (e.g., '1080x1920/default.html'). Can also be just filename (e.g., 'default.html') to use default size."
26 )
27 title: Optional[str] = Field(None, description="Frame title (optional)")
28 text: str = Field(..., description="Frame text content")
29 image: Optional[str] = Field(None, description="Image path or URL (optional)")
30
31 class Config:
32 json_schema_extra = {
33 "example": {
34 "template": "1080x1920/default.html",
35 "title": "Sample Title",
36 "text": "This is a sample text for the frame.",
37 "image": "resources/example.png"
38 }
39 }
40
41
42 class FrameRenderResponse(BaseModel):
43 """Frame rendering response"""
44 success: bool = True
45 message: str = "Success"
46 frame_path: str = Field(..., description="Path to generated frame image")
47 width: int = Field(..., description="Frame width in pixels")
48 height: int = Field(..., description="Frame height in pixels")
49
50
51 class TemplateParamConfig(BaseModel):
52 """Single template parameter configuration"""
53 type: str = Field(..., description="Parameter type: 'text', 'number', 'color', 'bool'")
54 default: Any = Field(..., description="Default value")
55 label: str = Field(..., description="Display label for the parameter")
56
57
58 class TemplateParamsResponse(BaseModel):
59 """Template parameters response"""
60 success: bool = True
61 message: str = "Success"
62 template: str = Field(..., description="Template path")
63 media_width: int = Field(..., description="Media width from template meta tags")
64 media_height: int = Field(..., description="Media height from template meta tags")
65 params: Dict[str, TemplateParamConfig] = Field(
66 default_factory=dict,
67 description="Custom parameters defined in template. Key is parameter name, value is config."
68 )
69
70
70 lines PYTHON