Spaces:
Running
Running
Upload 5 files
Browse files- models.py +2 -2
- router_prompts.py +11 -6
models.py
CHANGED
|
@@ -269,7 +269,7 @@ class PostUpdate(BaseModel):
|
|
| 269 |
|
| 270 |
class PromptCreate(BaseModel):
|
| 271 |
""" 发布提示词 """
|
| 272 |
-
prompt_type: str # "image" 或 "
|
| 273 |
category: str # 所属分类(人物/动作等)
|
| 274 |
title: str # 标题
|
| 275 |
content: str # 公开介绍文案
|
|
@@ -298,5 +298,5 @@ class PromptUpdate(BaseModel):
|
|
| 298 |
|
| 299 |
class PromptCategoryAdd(BaseModel):
|
| 300 |
""" 添加提示词分类 """
|
| 301 |
-
prompt_type: str # "image" 或 "
|
| 302 |
name: str # 分类名称(≤8字,去重)
|
|
|
|
| 269 |
|
| 270 |
class PromptCreate(BaseModel):
|
| 271 |
""" 发布提示词 """
|
| 272 |
+
prompt_type: str # "image"、"video" 或 "music"(所属子界面)
|
| 273 |
category: str # 所属分类(人物/动作等)
|
| 274 |
title: str # 标题
|
| 275 |
content: str # 公开介绍文案
|
|
|
|
| 298 |
|
| 299 |
class PromptCategoryAdd(BaseModel):
|
| 300 |
""" 添加提示词分类 """
|
| 301 |
+
prompt_type: str # "image"、"video" 或 "music"
|
| 302 |
name: str # 分类名称(≤8字,去重)
|
router_prompts.py
CHANGED
|
@@ -40,10 +40,11 @@ logger = logging.getLogger("ComfyUI-Ranking.Prompts")
|
|
| 40 |
# 内置默认分类(首次读取 prompt_categories.json 不存在时自动初始化)
|
| 41 |
DEFAULT_CATEGORIES = {
|
| 42 |
"image": ["人物", "动物", "植物", "道具", "建筑"],
|
| 43 |
-
"video": ["动作", "表情变化", "天气变化", "光效变化", "运镜", "视觉风格"]
|
|
|
|
| 44 |
}
|
| 45 |
|
| 46 |
-
VALID_PROMPT_TYPES = ("image", "video")
|
| 47 |
|
| 48 |
# 内容长度上限
|
| 49 |
MAX_TITLE_LEN = 50
|
|
@@ -103,6 +104,10 @@ def _load_categories() -> dict:
|
|
| 103 |
"video": list(DEFAULT_CATEGORIES["video"])
|
| 104 |
}
|
| 105 |
db.save_data("prompt_categories.json", categories)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
return categories
|
| 107 |
|
| 108 |
|
|
@@ -139,7 +144,7 @@ def _mask_prompt_text(prompt_data: dict, can_view: bool) -> dict:
|
|
| 139 |
async def get_prompt_categories(prompt_type: str = None):
|
| 140 |
"""
|
| 141 |
获取提示词分类列表
|
| 142 |
-
- prompt_type: image / video,不传则返回全部
|
| 143 |
"""
|
| 144 |
categories = _load_categories()
|
| 145 |
if prompt_type in VALID_PROMPT_TYPES:
|
|
@@ -154,7 +159,7 @@ async def add_prompt_category(request: Request, body: PromptCategoryAdd, current
|
|
| 154 |
添加提示词分类(登录用户均可,重名去重)
|
| 155 |
"""
|
| 156 |
if body.prompt_type not in VALID_PROMPT_TYPES:
|
| 157 |
-
raise HTTPException(status_code=400, detail="分类所属类型必须是 image 或
|
| 158 |
|
| 159 |
name = (body.name or "").strip()
|
| 160 |
if not name:
|
|
@@ -216,7 +221,7 @@ async def get_prompts(prompt_type: str = None, category: str = None,
|
|
| 216 |
page: int = 1, limit: int = 20, sort: str = "latest"):
|
| 217 |
"""
|
| 218 |
获取提示词列表(分页,支持类型/分类筛选与多种排序)
|
| 219 |
-
- prompt_type: image / video(子界面筛选)
|
| 220 |
- category: 分类筛选
|
| 221 |
- sort: latest / likes / favorites / views / daily_views / tips
|
| 222 |
⚠️ 列表接口永不下发 prompt_text(付费内容脱敏)
|
|
@@ -338,7 +343,7 @@ async def create_prompt(prompt: PromptCreate, current_user: str = Depends(requir
|
|
| 338 |
"""
|
| 339 |
# 参数校验
|
| 340 |
if prompt.prompt_type not in VALID_PROMPT_TYPES:
|
| 341 |
-
raise HTTPException(status_code=400, detail="提示词类型必须是 image 或
|
| 342 |
title = (prompt.title or "").strip()
|
| 343 |
content = (prompt.content or "").strip()
|
| 344 |
prompt_text = (prompt.prompt_text or "").strip()
|
|
|
|
| 40 |
# 内置默认分类(首次读取 prompt_categories.json 不存在时自动初始化)
|
| 41 |
DEFAULT_CATEGORIES = {
|
| 42 |
"image": ["人物", "动物", "植物", "道具", "建筑"],
|
| 43 |
+
"video": ["动作", "表情变化", "天气变化", "光效变化", "运镜", "视觉风格"],
|
| 44 |
+
"music": ["中国风", "流行", "说唱", "摇滚", "电音", "纯音乐"]
|
| 45 |
}
|
| 46 |
|
| 47 |
+
VALID_PROMPT_TYPES = ("image", "video", "music")
|
| 48 |
|
| 49 |
# 内容长度上限
|
| 50 |
MAX_TITLE_LEN = 50
|
|
|
|
| 104 |
"video": list(DEFAULT_CATEGORIES["video"])
|
| 105 |
}
|
| 106 |
db.save_data("prompt_categories.json", categories)
|
| 107 |
+
# 存量分类文件补全 music 分组(历史数据只有 image/video 键)
|
| 108 |
+
if "music" not in categories:
|
| 109 |
+
categories["music"] = list(DEFAULT_CATEGORIES["music"])
|
| 110 |
+
db.save_data("prompt_categories.json", categories)
|
| 111 |
return categories
|
| 112 |
|
| 113 |
|
|
|
|
| 144 |
async def get_prompt_categories(prompt_type: str = None):
|
| 145 |
"""
|
| 146 |
获取提示词分类列表
|
| 147 |
+
- prompt_type: image / video / music,不传则返回全部
|
| 148 |
"""
|
| 149 |
categories = _load_categories()
|
| 150 |
if prompt_type in VALID_PROMPT_TYPES:
|
|
|
|
| 159 |
添加提示词分类(登录用户均可,重名去重)
|
| 160 |
"""
|
| 161 |
if body.prompt_type not in VALID_PROMPT_TYPES:
|
| 162 |
+
raise HTTPException(status_code=400, detail="分类所属类型必须是 image、video 或 music")
|
| 163 |
|
| 164 |
name = (body.name or "").strip()
|
| 165 |
if not name:
|
|
|
|
| 221 |
page: int = 1, limit: int = 20, sort: str = "latest"):
|
| 222 |
"""
|
| 223 |
获取提示词列表(分页,支持类型/分类筛选与多种排序)
|
| 224 |
+
- prompt_type: image / video / music(子界面筛选)
|
| 225 |
- category: 分类筛选
|
| 226 |
- sort: latest / likes / favorites / views / daily_views / tips
|
| 227 |
⚠️ 列表接口永不下发 prompt_text(付费内容脱敏)
|
|
|
|
| 343 |
"""
|
| 344 |
# 参数校验
|
| 345 |
if prompt.prompt_type not in VALID_PROMPT_TYPES:
|
| 346 |
+
raise HTTPException(status_code=400, detail="提示词类型必须是 image、video 或 music")
|
| 347 |
title = (prompt.title or "").strip()
|
| 348 |
content = (prompt.content or "").strip()
|
| 349 |
prompt_text = (prompt.prompt_text or "").strip()
|