完善fastapi接口

This commit is contained in:
puke
2025-11-05 19:46:47 +08:00
parent eee604d8e9
commit 15899afb6f
11 changed files with 595 additions and 56 deletions

37
api/schemas/frame.py Normal file
View File

@@ -0,0 +1,37 @@
"""
Frame/Template rendering API schemas
"""
from typing import Optional
from pydantic import BaseModel, Field
class FrameRenderRequest(BaseModel):
"""Frame rendering request"""
template: str = Field(
...,
description="Template key (e.g., '1080x1920/default.html'). Can also be just filename (e.g., 'default.html') to use default size."
)
title: Optional[str] = Field(None, description="Frame title (optional)")
text: str = Field(..., description="Frame text content")
image: str = Field(..., description="Image path or URL")
class Config:
json_schema_extra = {
"example": {
"template": "1080x1920/default.html",
"title": "Sample Title",
"text": "This is a sample text for the frame.",
"image": "resources/example.png"
}
}
class FrameRenderResponse(BaseModel):
"""Frame rendering response"""
success: bool = True
message: str = "Success"
frame_path: str = Field(..., description="Path to generated frame image")
width: int = Field(..., description="Frame width in pixels")
height: int = Field(..., description="Frame height in pixels")

57
api/schemas/resources.py Normal file
View File

@@ -0,0 +1,57 @@
"""
Resource discovery API schemas
"""
from typing import List, Optional
from pydantic import BaseModel, Field
class WorkflowInfo(BaseModel):
"""Workflow information"""
name: str = Field(..., description="Workflow filename")
display_name: str = Field(..., description="Display name with source info")
source: str = Field(..., description="Source (runninghub or selfhost)")
path: str = Field(..., description="Full path to workflow file")
key: str = Field(..., description="Workflow key (source/name)")
workflow_id: Optional[str] = Field(None, description="RunningHub workflow ID (if applicable)")
class WorkflowListResponse(BaseModel):
"""Workflow list response"""
success: bool = True
message: str = "Success"
workflows: List[WorkflowInfo] = Field(..., description="List of available workflows")
class TemplateInfo(BaseModel):
"""Template information"""
name: str = Field(..., description="Template filename")
display_name: str = Field(..., description="Display name")
size: str = Field(..., description="Size (e.g., 1080x1920)")
width: int = Field(..., description="Width in pixels")
height: int = Field(..., description="Height in pixels")
orientation: str = Field(..., description="Orientation (portrait/landscape/square)")
path: str = Field(..., description="Full path to template file")
key: str = Field(..., description="Template key (size/name)")
class TemplateListResponse(BaseModel):
"""Template list response"""
success: bool = True
message: str = "Success"
templates: List[TemplateInfo] = Field(..., description="List of available templates")
class BGMInfo(BaseModel):
"""BGM information"""
name: str = Field(..., description="BGM filename")
path: str = Field(..., description="Full path to BGM file")
source: str = Field(..., description="Source (default or custom)")
class BGMListResponse(BaseModel):
"""BGM list response"""
success: bool = True
message: str = "Success"
bgm_files: List[BGMInfo] = Field(..., description="List of available BGM files")

View File

@@ -2,19 +2,32 @@
TTS API schemas
"""
from typing import Optional
from pydantic import BaseModel, Field
class TTSSynthesizeRequest(BaseModel):
"""TTS synthesis request"""
text: str = Field(..., description="Text to synthesize")
voice_id: str = Field("[Chinese] zh-CN Yunjian", description="Voice ID")
workflow: Optional[str] = Field(
None,
description="TTS workflow key (e.g., 'runninghub/tts_edge.json' or 'selfhost/tts_edge.json'). If not specified, uses default workflow from config."
)
ref_audio: Optional[str] = Field(
None,
description="Reference audio path for voice cloning (optional). Can be a local file path or URL."
)
voice_id: Optional[str] = Field(
None,
description="Voice ID (deprecated, use workflow instead)"
)
class Config:
json_schema_extra = {
"example": {
"text": "Hello, welcome to Pixelle-Video!",
"voice_id": "[Chinese] zh-CN Yunjian"
"workflow": "runninghub/tts_edge.json",
"ref_audio": None
}
}

View File

@@ -23,7 +23,20 @@ class VideoGenerateRequest(BaseModel):
# === Basic Config ===
n_scenes: int = Field(5, ge=1, le=20, description="Number of scenes (generate mode only)")
voice_id: str = Field("[Chinese] zh-CN Yunjian", description="TTS voice ID")
# === TTS Parameters ===
tts_workflow: Optional[str] = Field(
None,
description="TTS workflow key (e.g., 'runninghub/tts_edge.json'). If not specified, uses default workflow from config."
)
ref_audio: Optional[str] = Field(
None,
description="Reference audio path for voice cloning (optional)"
)
voice_id: Optional[str] = Field(
None,
description="(Deprecated) TTS voice ID for legacy compatibility"
)
# === LLM Parameters ===
min_narration_words: int = Field(5, ge=1, le=100, description="Min narration words")