Files
hfut-bishe/python_server/app/routes/meta.py
T
2026-05-14 18:37:18 +08:00

94 lines
4.1 KiB
Python

from __future__ import annotations
from typing import Any, Dict
from fastapi import APIRouter
router = APIRouter(tags=["meta"])
@router.get("/models")
def get_models() -> Dict[str, Any]:
"""
返回一个兼容 Qt 前端的 schema:
{
"models": {
"depth": { "key": { "name": "..."} ... },
"segment": { ... },
"inpaint": { "key": { "name": "...", "params": [...] } ... }
}
}
"""
return {
"models": {
"depth": {
"midas": {"name": "MiDaS (default)"},
"zoedepth_n": {"name": "ZoeDepth (ZoeD_N)"},
"zoedepth_k": {"name": "ZoeDepth (ZoeD_K)"},
"zoedepth_nk": {"name": "ZoeDepth (ZoeD_NK)"},
"depth_anything_v2_vits": {"name": "Depth Anything V2 (vits)"},
"depth_anything_v2_vitb": {"name": "Depth Anything V2 (vitb)"},
"depth_anything_v2_vitl": {"name": "Depth Anything V2 (vitl)"},
"depth_anything_v2_vitg": {"name": "Depth Anything V2 (vitg)"},
"dpt_large": {"name": "DPT (large)"},
"dpt_hybrid": {"name": "DPT (hybrid)"},
"midas_dpt_beit_large_512": {"name": "MiDaS (dpt_beit_large_512)"},
"midas_dpt_swin2_large_384": {"name": "MiDaS (dpt_swin2_large_384)"},
"midas_dpt_swin2_tiny_256": {"name": "MiDaS (dpt_swin2_tiny_256)"},
"midas_dpt_levit_224": {"name": "MiDaS (dpt_levit_224)"},
},
"segment": {
"sam": {"name": "SAM (vit_h)"},
"mask2former_debug": {"name": "SAM (compat mask2former_debug)"},
"mask2former": {"name": "Mask2Former (not implemented)"},
},
"inpaint": {
"flux_fill": {
"name": "FLUX.1 Fill (default)",
"params": [{"id": "prompt", "label": "prompt", "optional": True}],
},
"sdxl_inpaint": {
"name": "sdxl_inpaint",
"params": [{"id": "prompt", "label": "prompt", "optional": True}],
},
"lama": {"name": "lama", "params": []},
"copy": {"name": "copy (debug)", "params": []},
"controlnet": {
"name": "controlnet",
"params": [{"id": "prompt", "label": "prompt", "optional": True}],
},
},
"animation": {
"animatediff": {
"name": "AnimateDiff (Text-to-Video)",
"params": [
{"id": "prompt", "label": "提示词", "optional": False},
{"id": "negative_prompt", "label": "负向提示词", "optional": True},
{"id": "num_inference_steps", "label": "采样步数", "optional": True},
{"id": "guidance_scale", "label": "CFG Scale", "optional": True},
{"id": "width", "label": "宽度", "optional": True},
{"id": "height", "label": "高度", "optional": True},
{"id": "video_length", "label": "帧数", "optional": True},
{"id": "seed", "label": "随机种子", "optional": True},
],
},
"character_sequence": {
"name": "Character PNG Sequence (30 FPS)",
"endpoint": "/animate/character_sequence",
"params": [
{"id": "image_b64", "label": "透明背景角色 PNG", "optional": False},
{"id": "prompt", "label": "动画提示词", "optional": False},
{"id": "background_color", "label": "纯色背景", "optional": True},
{"id": "video_length", "label": "帧数", "optional": True},
{"id": "background_tolerance", "label": "背景剔除阈值", "optional": True},
],
},
},
}
}
@router.get("/health")
def health() -> Dict[str, str]:
return {"status": "ok"}