frame.py 2.6 KB

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