save code

This commit is contained in:
Your Name
2026-04-06 17:47:45 +08:00
parent ecdef627d4
commit 79d8c6d17f
7 changed files with 241 additions and 27 deletions
+5 -1
View File
@@ -37,6 +37,7 @@ NODE_MODEL = "11" # 模特
NODE_SHIRT = "10" # 上衣
# NODE_PANTS = "4" # 裤子
NODE_OUTPUT = "33" # 输出
NODE_PROMPT = "31" # 文本提示(PrimitiveStringMultiline
app = FastAPI(title="ComfyUI 换装服务")
@@ -82,6 +83,7 @@ def upload_to_oss(image_path, object_name=None):
class TryOnRequest(BaseModel):
model_image: str # base64 模特图片
shirt_image: str # base64 上衣图片
change_desc: str = "" # 换装/编辑描述,可空;非空时替换节点 31 的 inputs
class TryOnResponse(BaseModel):
@@ -155,7 +157,9 @@ async def try_on(req: TryOnRequest):
# 加载工作流模板
workflow = json.loads(WORKFLOW_PATH.read_text(encoding="utf-8"))
desc = (req.change_desc or "").strip()
if desc:
workflow[NODE_PROMPT]["inputs"] = {"value": desc}
async with httpx.AsyncClient(timeout=60.0) as client:
# 解码两张图片
+70
View File
@@ -196,6 +196,49 @@
background: #7c3aed22;
}
.prompt-panel {
width: 100%;
max-width: 900px;
margin-bottom: 24px;
background: #1a1a24;
border-radius: 16px;
padding: 20px;
border: 1px solid #2a2a3a;
}
.prompt-panel .prompt-title {
font-size: 0.85rem;
font-weight: 600;
color: #a78bfa;
margin-bottom: 12px;
}
.radio-row {
display: flex;
align-items: flex-start;
gap: 10px;
margin-bottom: 10px;
cursor: pointer;
font-size: 0.9rem;
color: #ccc;
}
.radio-row input { margin-top: 3px; accent-color: #7c3aed; flex-shrink: 0; }
.change-desc-input {
width: 100%;
margin-top: 4px;
padding: 12px;
border-radius: 10px;
border: 1px solid #333;
background: #12121a;
color: #e0e0e0;
font-family: inherit;
font-size: 0.88rem;
resize: vertical;
min-height: 88px;
}
.change-desc-input:disabled {
opacity: 0.45;
cursor: not-allowed;
}
@media (max-width: 640px) {
.upload-grid { grid-template-columns: 1fr; }
h1 { font-size: 1.5rem; }
@@ -226,6 +269,19 @@
</div>
</div>
<div class="prompt-panel" id="prompt-panel">
<div class="prompt-title">提示词(change_desc</div>
<label class="radio-row">
<input type="radio" name="prompt_mode" id="prompt-default" value="default" checked />
<span>使用默认(传空,不覆盖工作流节点 31)</span>
</label>
<label class="radio-row">
<input type="radio" name="prompt_mode" id="prompt-custom" value="custom" />
<span>自定义提示词</span>
</label>
<textarea id="change-desc" class="change-desc-input" placeholder="输入换装/编辑描述…" rows="4" disabled></textarea>
</div>
<button class="btn-run" id="btn-run" disabled>开始换装</button>
<div class="status-bar" id="status-bar"></div>
@@ -261,6 +317,19 @@
setupUpload('input-model', 'preview-model', 'card-model', 'model');
setupUpload('input-shirt', 'preview-shirt', 'card-shirt', 'shirt');
const promptDefault = document.getElementById('prompt-default');
const promptCustom = document.getElementById('prompt-custom');
const changeDescEl = document.getElementById('change-desc');
function syncPromptUi() {
changeDescEl.disabled = !promptCustom.checked;
}
promptDefault.addEventListener('change', syncPromptUi);
promptCustom.addEventListener('change', syncPromptUi);
function getChangeDesc() {
return promptCustom.checked ? changeDescEl.value.trim() : '';
}
function updateRunButton() {
const btn = document.getElementById('btn-run');
btn.disabled = !(images.model && images.shirt);
@@ -298,6 +367,7 @@
body: JSON.stringify({
model_image: images.model,
shirt_image: images.shirt,
change_desc: getChangeDesc(),
}),
});