Generate MoneyPrinter Comfy prompts from form
This commit is contained in:
@@ -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,34 +390,47 @@ 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>
|
||||
<label className="money-printer-field">
|
||||
<span>工作流模板</span>
|
||||
<select value={templateId} onChange={(event) => setTemplateId(event.target.value)}>
|
||||
<option value="">请选择模板</option>
|
||||
{workflows.map((workflow) => (
|
||||
<option key={workflow.publicId} value={workflow.publicId}>
|
||||
{workflow.name} · {templateLabel(workflow)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
{selectedWorkflow && (
|
||||
{useAdvancedComfy && (
|
||||
<>
|
||||
<label className="money-printer-field">
|
||||
<span>工作流模板</span>
|
||||
<select value={templateId} onChange={(event) => setTemplateId(event.target.value)}>
|
||||
<option value="">请选择模板</option>
|
||||
{workflows.map((workflow) => (
|
||||
<option key={workflow.publicId} value={workflow.publicId}>
|
||||
{workflow.name} · {templateLabel(workflow)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
{selectedWorkflow && (
|
||||
<div className="money-printer-template-meta">
|
||||
<strong>{selectedWorkflow.name}</strong>
|
||||
<span>{mappingFromGraph(selectedWorkflow.graph) ? '已带节点映射' : '这个模板没有内置节点映射,系统会尝试自动推断。'}</span>
|
||||
</div>
|
||||
)}
|
||||
<label className="money-printer-field">
|
||||
<span>Comfy prompt JSON</span>
|
||||
<textarea value={comfyPrompt} onChange={(event) => setComfyPrompt(event.target.value)} rows={7} placeholder='{"12":{"class_type":"...","inputs":{...}}}' />
|
||||
</label>
|
||||
<label className="money-printer-field">
|
||||
<span>节点映射 JSON</span>
|
||||
<textarea value={comfyNodeMapping} onChange={(event) => setComfyNodeMapping(event.target.value)} rows={7} />
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
{!useAdvancedComfy && (
|
||||
<div className="money-printer-template-meta">
|
||||
<strong>{selectedWorkflow.name}</strong>
|
||||
<span>{mappingFromGraph(selectedWorkflow.graph) ? '已带节点映射' : '这个模板没有内置节点映射,可在下方手动填写。'}</span>
|
||||
<strong>自动生成 Comfy prompt</strong>
|
||||
<span>模型 {videoModel || '未填写'} / {ratio} / {resolution} / {duration} 秒</span>
|
||||
</div>
|
||||
)}
|
||||
<label className="money-printer-field">
|
||||
<span>Comfy prompt JSON</span>
|
||||
<textarea value={comfyPrompt} onChange={(event) => setComfyPrompt(event.target.value)} rows={7} placeholder='{"12":{"class_type":"...","inputs":{...}}}' />
|
||||
</label>
|
||||
<label className="money-printer-field">
|
||||
<span>节点映射 JSON</span>
|
||||
<textarea value={comfyNodeMapping} onChange={(event) => setComfyNodeMapping(event.target.value)} rows={7} />
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user