save changes

This commit is contained in:
2025-08-20 11:05:17 +02:00
parent da12056d5a
commit 0415eb9df0
3 changed files with 46 additions and 30 deletions

View File

@ -18,10 +18,13 @@ const servers = [
baseUrl: process.env.SERVER1_COMFY_BASE_URL,
outputDir: process.env.SERVER1_COMFY_OUTPUT_DIR,
},
//{
// baseUrl: process.env.SERVER2_COMFY_BASE_URL,
// outputDir: process.env.SERVER2_COMFY_OUTPUT_DIR,
//},
/*
{
baseUrl: process.env.SERVER2_COMFY_BASE_URL,
outputDir: process.env.SERVER2_COMFY_OUTPUT_DIR,
},
*/
];
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

View File

@ -146,20 +146,30 @@ async function processItem(genre: string, item: any) {
} = item;
// Determine final scene text
const finalScene =
(typeof scene === 'string' && scene.trim().length > 0)
const finalScene = scene;
/*(typeof scene === 'string' && scene.trim().length > 0)
? scene
: Array.isArray(sceneVariants) && sceneVariants.length > 0
? sceneVariants[0]
: '';
*/
// Choose one random action (fall back to legacy 'action' if needed)
let chosenAction = '';
if (Array.isArray(actions) && actions.length > 0) {
chosenAction = actions[0];
} else if (typeof action === 'string') {
chosenAction = action;
}
/*
if (Array.isArray(actions) && actions.length > 0) {
chosenAction = actions[Math.floor(Math.random() * actions.length)];
} else if (typeof action === 'string') {
chosenAction = action;
}
*/
// Choose random accents (pick 1 or 2 if available)
let chosenAccents = '';
@ -179,11 +189,24 @@ async function processItem(genre: string, item: any) {
// Compose the action text that will be stored in the DB (so later prompt generation can use it)
const actionText = [chosenAction, meta].filter(Boolean).join(' ').trim();
//const actionText = [chosenAction, meta].filter(Boolean).join(' ').trim();
// Generate image_prompt and video_prompt using LM Studio (with retries)
let imagePrompt: string | null = null;
let videoPrompt: string | null = null;
// Check if the item already exists (compare stored action text so duplicates are avoided)
const existing = await query(
'SELECT id FROM video WHERE genre = ? AND sub_genre = ? AND scene = ? AND action = ? AND camera = ?',
[genre, subGenre, finalScene, chosenAction, camera]
) as any[];
if (existing.length > 0) {
logger.info(`Skipped (exists): ${genre} - ${subGenre} - ${finalScene}`);
return;
}
const lmInput = `
Generate two prompts in JSON: { "imagePrompt": "...", "videoPrompt": "..." }.
Image prompt: ~125 words describing a still image representing the scene. Include lighting, mood, style and any accents provided.
@ -220,25 +243,15 @@ async function processItem(genre: string, item: any) {
if (!imagePrompt || !videoPrompt) {
logger.warn(`LMStudio did not return both prompts for ${genre} - ${subGenre} - ${finalScene}. Inserting without prompts.`);
}
// Check if the item already exists (compare stored action text so duplicates are avoided)
const existing = await query(
'SELECT id FROM video WHERE genre = ? AND sub_genre = ? AND scene = ? AND action = ? AND camera = ?',
[genre, subGenre, finalScene, actionText, camera]
) as any[];
if (existing.length === 0) {
// Insert the new item with generated prompts
await query(
'INSERT INTO video (genre, sub_genre, scene, action, camera, image_prompt, video_prompt) VALUES (?, ?, ?, ?, ?, ?, ?)',
[genre, subGenre, finalScene, actionText, camera, imagePrompt, videoPrompt]
[genre, subGenre, finalScene, chosenAction, camera, imagePrompt, videoPrompt]
);
logger.info(`Inserted: ${genre} - ${subGenre} - ${finalScene}`);
logger.info(`Image prompt: ${imagePrompt}`);
logger.info(`Video prompt: ${videoPrompt}`);
} else {
logger.info(`Skipped (exists): ${genre} - ${subGenre} - ${finalScene}`);
}
}
}

View File

@ -16,10 +16,10 @@ interface VideoRecord {
}
const servers = [
{
/*{
baseUrl: process.env.SERVER1_COMFY_BASE_URL,
outputDir: process.env.SERVER1_COMFY_OUTPUT_DIR,
},
},*/
{
baseUrl: process.env.SERVER2_COMFY_BASE_URL,
outputDir: process.env.SERVER2_COMFY_OUTPUT_DIR,