利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.
Python ai-video-generatorcontent-creationffmpeginstagram-reelsllmpythonshort-videosubtitlestext-to-speechtiktokvideo-automationvideo-workflowworkflow-automationyoutube-shorts
fix(schema): validate subtitle render geometry before generation
Rudy Celeklif4ead6dbdcc9
diff --git a/app/models/schema.py b/app/models/schema.pyindex 06a29dc8..070ee2e7 100644--- a/app/models/schema.py+++ b/app/models/schema.py@@ -146,15 +146,17 @@ class VideoParams(BaseModel):subtitle_animation: SubtitleAnimation = _get_valid_ui_choice("subtitle_animation", _SUBTITLE_ANIMATIONS, "none")- custom_position: float = config.ui.get("custom_position", 70.0)+ custom_position: float = Field(+ default=config.ui.get("custom_position", 70.0), ge=0, le=100, allow_inf_nan=False+ )font_name: Optional[str] = "STHeitiMedium.ttc"text_fore_color: Optional[str] = "#FFFFFF"text_background_color: Union[bool, str] = Falserounded_subtitle_background: bool = False- font_size: int = 60+ font_size: int = Field(default=60, ge=1)stroke_color: Optional[str] = "#000000"- stroke_width: float = 1.5+ stroke_width: float = Field(default=1.5, ge=0, allow_inf_nan=False)n_threads: Optional[int] = 2paragraph_number: int = Field(default=1, ge=1, le=10)video_script_prompt: str = Field(default="", max_length=2000)@@ -181,9 +183,9 @@ class SubtitleRequest(BaseModel):text_fore_color: Optional[str] = "#FFFFFF"text_background_color: Union[bool, str] = Falserounded_subtitle_background: bool = False- font_size: int = 60+ font_size: int = Field(default=60, ge=1)stroke_color: Optional[str] = "#000000"- stroke_width: float = 1.5+ stroke_width: float = Field(default=1.5, ge=0, allow_inf_nan=False)video_source: Optional[str] = "local"subtitle_enabled: Optional[bool] = Truediff --git a/test/services/test_render_parameter_validation.py b/test/services/test_render_parameter_validation.pynew file mode 100644index 00000000..29e39924--- /dev/null+++ b/test/services/test_render_parameter_validation.py@@ -0,0 +1,54 @@+import pytest+from pydantic import ValidationError+from app.models.schema import TaskVideoRequest, VideoParams, SubtitleRequest+++ "model,required",+ [+ (TaskVideoRequest, {"video_subject": "coffee"}),+ (SubtitleRequest, {"video_script": "coffee"}),+ ],+)+ "field,value",+ [+ ("font_size", 0),+ ("font_size", -1),+ ("stroke_width", -1.0),+ ("stroke_width", float("inf")),+ ],+)+def test_invalid_subtitle_render_values_rejected_before_generation(+ model, required, field, value+):+ with pytest.raises(ValidationError):+ model(**required, **{field: value})+++ "field,value",+ [+ ("custom_position", -1.0),+ ("custom_position", 101.0),+ ("custom_position", float("nan")),+ ],+)+def test_invalid_video_render_values_rejected_before_generation(field, value):+ with pytest.raises(ValidationError):+ TaskVideoRequest(video_subject="coffee", **{field: value})+++def test_valid_render_boundaries_and_optional_thread_default_remain_usable():+ params = VideoParams(+ video_subject="coffee",+ font_size=1,+ stroke_width=0,+ custom_position=100,+ n_threads=None,+ )+ assert params.font_size == 1 and params.n_threads is None+ assert (+ SubtitleRequest(video_script="coffee", font_size=1, stroke_width=0).stroke_width+ == 0+ )