fix: normalize media prompts and patent views
This commit is contained in:
53
api/main.py
53
api/main.py
@@ -2664,6 +2664,15 @@ SUBJECT_VIEW_LABELS: dict[str, str] = {
|
||||
"back_detail": "背部特写",
|
||||
}
|
||||
|
||||
OBJECT_PATENT_VIEW_LABELS: dict[str, str] = {
|
||||
"front": "正投影主视图",
|
||||
"back": "正投影后视图",
|
||||
"left": "正投影左视图",
|
||||
"right": "正投影右视图",
|
||||
"top": "正投影俯视图",
|
||||
"bottom": "正投影仰视图",
|
||||
}
|
||||
|
||||
|
||||
def _subject_view_labels(kind: SubjectKind, requested: list[str] | None = None) -> list[tuple[SubjectView, str]]:
|
||||
if requested:
|
||||
@@ -2672,7 +2681,8 @@ def _subject_view_labels(kind: SubjectKind, requested: list[str] | None = None)
|
||||
key = "".join(ch for ch in str(raw).strip().lower() if ch.isalnum() or ch == "_")
|
||||
if key and key not in normalized:
|
||||
normalized.append(key)
|
||||
return [(key, SUBJECT_VIEW_LABELS.get(key, key.replace("_", " "))) for key in normalized[:10]]
|
||||
labels = OBJECT_PATENT_VIEW_LABELS if kind == "object" else SUBJECT_VIEW_LABELS
|
||||
return [(key, labels.get(key, SUBJECT_VIEW_LABELS.get(key, key.replace("_", " ")))) for key in normalized[:10]]
|
||||
if kind == "living":
|
||||
return [
|
||||
("front", "正面站立"),
|
||||
@@ -2687,16 +2697,36 @@ def _subject_view_labels(kind: SubjectKind, requested: list[str] | None = None)
|
||||
("back_neck_detail", "后颈/肩背特写"),
|
||||
]
|
||||
return [
|
||||
("front", "正面"),
|
||||
("back", "背面"),
|
||||
("left", "左侧"),
|
||||
("right", "右侧"),
|
||||
("top", "正投影俯视图"),
|
||||
("bottom", "正投影仰视图"),
|
||||
("front", OBJECT_PATENT_VIEW_LABELS["front"]),
|
||||
("back", OBJECT_PATENT_VIEW_LABELS["back"]),
|
||||
("left", OBJECT_PATENT_VIEW_LABELS["left"]),
|
||||
("right", OBJECT_PATENT_VIEW_LABELS["right"]),
|
||||
("top", OBJECT_PATENT_VIEW_LABELS["top"]),
|
||||
("bottom", OBJECT_PATENT_VIEW_LABELS["bottom"]),
|
||||
]
|
||||
|
||||
|
||||
def _subject_view_projection_clause(view: str) -> str:
|
||||
if view == "front":
|
||||
return (
|
||||
"Patent-style orthographic main/front elevation view: look straight at the designated main face, "
|
||||
"with the viewing direction perpendicular to that face. No perspective, no tilt, no 3/4 angle, no isometric view. "
|
||||
)
|
||||
if view == "back":
|
||||
return (
|
||||
"Patent-style orthographic rear elevation view: look straight at the rear face, "
|
||||
"with the viewing direction perpendicular to that face. No perspective, no tilt, no 3/4 angle, no isometric view. "
|
||||
)
|
||||
if view == "left":
|
||||
return (
|
||||
"Patent-style orthographic left side elevation view: look straight at the product's left side, "
|
||||
"with the viewing direction perpendicular to that side face. No perspective, no tilt, no 3/4 angle, no isometric view. "
|
||||
)
|
||||
if view == "right":
|
||||
return (
|
||||
"Patent-style orthographic right side elevation view: look straight at the product's right side, "
|
||||
"with the viewing direction perpendicular to that side face. No perspective, no tilt, no 3/4 angle, no isometric view. "
|
||||
)
|
||||
if view == "top":
|
||||
return (
|
||||
"Patent-style orthographic top view: look straight down from directly above the product, "
|
||||
@@ -5597,13 +5627,14 @@ def generate_image(job_id: str, idx: int, req: GenerateReq) -> Job:
|
||||
reference_path = sel_path
|
||||
reference_source = f"gen:{sel.id[:6]}"
|
||||
|
||||
full_prompt = req.prompt.strip()
|
||||
raw_prompt = req.prompt.strip()
|
||||
if req.extra_prompt.strip():
|
||||
full_prompt = f"{full_prompt}. Include: {req.extra_prompt.strip()}"
|
||||
raw_prompt = f"{raw_prompt}. Include: {req.extra_prompt.strip()}"
|
||||
if req.negative_prompt.strip():
|
||||
full_prompt = f"{full_prompt}. Avoid: {req.negative_prompt.strip()}"
|
||||
if not full_prompt:
|
||||
raw_prompt = f"{raw_prompt}. Avoid: {req.negative_prompt.strip()}"
|
||||
if not raw_prompt:
|
||||
raise HTTPException(400, "prompt required")
|
||||
full_prompt = _ensure_english(raw_prompt)
|
||||
if not IMAGE_API_KEY:
|
||||
raise HTTPException(503, "IMAGE_API_KEY 或 LLM_API_KEY 未配置")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user