save code
This commit is contained in:
@@ -36,6 +36,7 @@ NODE_MODEL = "11" # 模特
|
||||
NODE_SHIRT = "10" # 上衣
|
||||
NODE_PANTS = "4" # 裤子
|
||||
NODE_OUTPUT = "33" # 输出
|
||||
NODE_PROMPT = "31" # 文本提示(PrimitiveStringMultiline)
|
||||
|
||||
app = FastAPI(title="ComfyUI 换装服务")
|
||||
|
||||
@@ -73,6 +74,7 @@ class TryOnRequest(BaseModel):
|
||||
model_image: str # base64 模特图片
|
||||
shirt_image: str # base64 上衣图片
|
||||
pants_image: str # base64 裤子图片
|
||||
change_desc: str = "" # 换装/编辑描述,可空;非空时替换节点 31 的 inputs
|
||||
|
||||
|
||||
class TryOnResponse(BaseModel):
|
||||
@@ -146,6 +148,10 @@ 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:
|
||||
# 解码三张图片
|
||||
try:
|
||||
|
||||
@@ -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; }
|
||||
@@ -235,6 +278,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>
|
||||
|
||||
@@ -271,6 +327,19 @@
|
||||
setupUpload('input-shirt', 'preview-shirt', 'card-shirt', 'shirt');
|
||||
setupUpload('input-pants', 'preview-pants', 'card-pants', 'pants');
|
||||
|
||||
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 && images.pants);
|
||||
@@ -309,6 +378,7 @@
|
||||
model_image: images.model,
|
||||
shirt_image: images.shirt,
|
||||
pants_image: images.pants,
|
||||
change_desc: getChangeDesc(),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user