Generate MoneyPrinter Comfy prompts from form
This commit is contained in:
@@ -687,6 +687,35 @@ fn workflow_prompt_from_graph(graph: &Value) -> Value {
|
||||
.unwrap_or_else(|| graph.clone())
|
||||
}
|
||||
|
||||
fn generated_comfy_prompt_from_request(body: &Value) -> Value {
|
||||
let model = string_from(body, &["videoModel", "video_model", "model"])
|
||||
.unwrap_or_else(|| "seedance-1-0-lite-t2v".to_string());
|
||||
let ratio = string_from(body, &["ratio", "aspectRatio", "aspect_ratio"]).unwrap_or_else(|| "9:16".to_string());
|
||||
let resolution = string_from(body, &["resolution", "size"]).unwrap_or_else(|| "1080p".to_string());
|
||||
let duration = body
|
||||
.get("duration")
|
||||
.cloned()
|
||||
.unwrap_or_else(|| json!(30));
|
||||
json!({
|
||||
"1": {
|
||||
"class_type": "BoosAPITextToVideo",
|
||||
"inputs": {
|
||||
"model": model,
|
||||
"prompt": "",
|
||||
"ratio": ratio,
|
||||
"resolution": resolution,
|
||||
"duration": duration
|
||||
}
|
||||
},
|
||||
"2": {
|
||||
"class_type": "output.preview_video",
|
||||
"inputs": {
|
||||
"video": ["1", 0]
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async fn workflow_prompt_from_body(
|
||||
state: &AppState,
|
||||
auth: &MoneyPrinterAuth,
|
||||
@@ -711,9 +740,7 @@ async fn workflow_prompt_from_body(
|
||||
.await?;
|
||||
return Ok(workflow_prompt_from_graph(&workflow.graph));
|
||||
}
|
||||
Err(AppError::BadRequest(
|
||||
"Comfy API 模式需要选择工作流模板,或传入 comfyPrompt/promptWorkflow 和节点映射".into(),
|
||||
))
|
||||
Ok(generated_comfy_prompt_from_request(body))
|
||||
}
|
||||
|
||||
fn apply_node_input(prompt: &mut Value, node_id: &str, field: &str, value: Value) -> AppResult<()> {
|
||||
|
||||
@@ -146,6 +146,36 @@ function templateLabel(workflow: WorkflowSummary) {
|
||||
return '私有工作流';
|
||||
}
|
||||
|
||||
function generatedComfyPromptFromForm(model: string, ratio: string, resolution: string, duration: number) {
|
||||
return {
|
||||
'1': {
|
||||
class_type: 'BoosAPITextToVideo',
|
||||
inputs: {
|
||||
model,
|
||||
prompt: '',
|
||||
ratio,
|
||||
resolution,
|
||||
duration,
|
||||
},
|
||||
},
|
||||
'2': {
|
||||
class_type: 'output.preview_video',
|
||||
inputs: {
|
||||
video: ['1', 0],
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function generatedComfyMapping() {
|
||||
return {
|
||||
prompt: { nodeId: '1', field: 'prompt' },
|
||||
ratio: { nodeId: '1', field: 'ratio' },
|
||||
resolution: { nodeId: '1', field: 'resolution' },
|
||||
duration: { nodeId: '1', field: 'duration' },
|
||||
};
|
||||
}
|
||||
|
||||
export default function MoneyPrinter() {
|
||||
const location = useLocation();
|
||||
const audience: SessionAudience = location.pathname.startsWith('/user/') ? 'user' : 'admin';
|
||||
@@ -165,6 +195,7 @@ export default function MoneyPrinter() {
|
||||
const [comfyNodeMapping, setComfyNodeMapping] = useState('{\n "prompt": { "nodeId": "", "field": "prompt" },\n "negativePrompt": { "nodeId": "", "field": "text" },\n "ratio": { "nodeId": "", "field": "ratio" },\n "resolution": { "nodeId": "", "field": "resolution" },\n "duration": { "nodeId": "", "field": "duration" }\n}');
|
||||
const [workflows, setWorkflows] = useState<WorkflowSummary[]>([]);
|
||||
const [templateId, setTemplateId] = useState('');
|
||||
const [useAdvancedComfy, setUseAdvancedComfy] = useState(false);
|
||||
const [jobs, setJobs] = useState<MoneyPrinterJob[]>([]);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
@@ -188,13 +219,19 @@ export default function MoneyPrinter() {
|
||||
const selectedWorkflow = workflows.find((item) => item.publicId === templateId) || null;
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedWorkflow || videoBackend !== 'comfy') return;
|
||||
if (!selectedWorkflow || videoBackend !== 'comfy' || !useAdvancedComfy) return;
|
||||
const prompt = workflowPromptFromGraph(selectedWorkflow.graph);
|
||||
if (prompt) setComfyPrompt(JSON.stringify(prompt, null, 2));
|
||||
const mapping = mappingFromGraph(selectedWorkflow.graph);
|
||||
setComfyNodeMapping(JSON.stringify(mapping || inferMappingFromPrompt(prompt), null, 2));
|
||||
}, [selectedWorkflow?.publicId, videoBackend]);
|
||||
|
||||
useEffect(() => {
|
||||
if (videoBackend !== 'comfy' || useAdvancedComfy) return;
|
||||
setComfyPrompt(JSON.stringify(generatedComfyPromptFromForm(videoModel.trim(), ratio, resolution, duration), null, 2));
|
||||
setComfyNodeMapping(JSON.stringify(generatedComfyMapping(), null, 2));
|
||||
}, [videoBackend, useAdvancedComfy, videoModel, ratio, resolution, duration]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!jobs.some((job) => !terminal(job.status))) return;
|
||||
const timer = window.setInterval(() => {
|
||||
@@ -223,7 +260,7 @@ export default function MoneyPrinter() {
|
||||
requirements,
|
||||
language: '中文',
|
||||
...(videoBackend === 'comfy' ? {
|
||||
templateId: templateId || undefined,
|
||||
templateId: useAdvancedComfy ? templateId || undefined : undefined,
|
||||
comfyPrompt: comfyPrompt.trim() ? JSON.parse(comfyPrompt) : undefined,
|
||||
comfyNodeMapping: comfyNodeMapping.trim() ? JSON.parse(comfyNodeMapping) : undefined,
|
||||
} : {}),
|
||||
@@ -261,6 +298,7 @@ export default function MoneyPrinter() {
|
||||
setComfyPrompt(request.comfyPrompt ? JSON.stringify(request.comfyPrompt, null, 2) : comfyPrompt);
|
||||
setComfyNodeMapping(request.comfyNodeMapping ? JSON.stringify(request.comfyNodeMapping, null, 2) : comfyNodeMapping);
|
||||
setTemplateId(request.templateId || templateId);
|
||||
setUseAdvancedComfy(Boolean(request.templateId));
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -352,9 +390,14 @@ export default function MoneyPrinter() {
|
||||
<div className="money-printer-section-head">
|
||||
<div>
|
||||
<h2>Comfy API 工作流</h2>
|
||||
<p>选择保存过的工作流模板,会自动带入 Comfy API prompt 和节点映射。</p>
|
||||
<p>{useAdvancedComfy ? '使用保存过的工作流模板,会自动带入 Comfy API prompt 和节点映射。' : '已根据上方表单自动生成 Comfy prompt,生成时会注入 AI 改写后的视频提示词。'}</p>
|
||||
</div>
|
||||
<button type="button" className="btn btn-ghost" onClick={() => setUseAdvancedComfy((value) => !value)}>
|
||||
{useAdvancedComfy ? '使用自动生成' : '高级模板'}
|
||||
</button>
|
||||
</div>
|
||||
{useAdvancedComfy && (
|
||||
<>
|
||||
<label className="money-printer-field">
|
||||
<span>工作流模板</span>
|
||||
<select value={templateId} onChange={(event) => setTemplateId(event.target.value)}>
|
||||
@@ -369,7 +412,7 @@ export default function MoneyPrinter() {
|
||||
{selectedWorkflow && (
|
||||
<div className="money-printer-template-meta">
|
||||
<strong>{selectedWorkflow.name}</strong>
|
||||
<span>{mappingFromGraph(selectedWorkflow.graph) ? '已带节点映射' : '这个模板没有内置节点映射,可在下方手动填写。'}</span>
|
||||
<span>{mappingFromGraph(selectedWorkflow.graph) ? '已带节点映射' : '这个模板没有内置节点映射,系统会尝试自动推断。'}</span>
|
||||
</div>
|
||||
)}
|
||||
<label className="money-printer-field">
|
||||
@@ -380,6 +423,14 @@ export default function MoneyPrinter() {
|
||||
<span>节点映射 JSON</span>
|
||||
<textarea value={comfyNodeMapping} onChange={(event) => setComfyNodeMapping(event.target.value)} rows={7} />
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
{!useAdvancedComfy && (
|
||||
<div className="money-printer-template-meta">
|
||||
<strong>自动生成 Comfy prompt</strong>
|
||||
<span>模型 {videoModel || '未填写'} / {ratio} / {resolution} / {duration} 秒</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user