save changes

This commit is contained in:
2025-08-16 12:04:20 +02:00
parent 1367f4571a
commit 13c878b627

View File

@ -4,50 +4,86 @@ import { generateImage } from './lib/image-generator';
import { generateVideo } from './lib/video-generator'; import { generateVideo } from './lib/video-generator';
import { logger } from './lib/logger'; import { logger } from './lib/logger';
(async () => { async function generateVideoFromKeyword(keyword: string) {
const keyword = 'cyberpunk city';
const numberOfPages = 1; const numberOfPages = 1;
const imagePaths = await downloadPinterestImages(keyword, numberOfPages); const imagePaths = await downloadPinterestImages(keyword, numberOfPages);
logger.info('Downloaded images:', imagePaths); logger.debug('Downloaded images:', imagePaths);
for (const imagePath of imagePaths) { if (imagePaths.length === 0) {
try { logger.warn('No images downloaded, cannot proceed.');
const llmResponseJSON = await describeImage(imagePath, return;
`Describe this image as a prompt for an image generation model. }
Prompt should be in 200 words.
Output should be in this format
---
{
"prompt":""
}
---
`);
const prompt = llmResponseJSON.prompt;
logger.info(`Description for ${imagePath}:`, prompt);
const timestamp = new Date().getTime(); const randomImagePath = imagePaths[Math.floor(Math.random() * imagePaths.length)];
const imageFileName = `${keyword.replace(/\s/g, '_')}_${timestamp}.png`; logger.debug(`Randomly selected image: ${randomImagePath}`);
const generatedImagePath = await generateImage(prompt, imageFileName);
logger.info(`Generated new image from prompt, saved to: ${generatedImagePath}`);
const videoPromptResponse = await describeImage(generatedImagePath, try {
`Generate a prompt for an 8-second video based on the provided image. const imagePromptResponse = await describeImage(randomImagePath,
The prompt should describe a dynamic scene that evolves from the static image. `Describe this image as a prompt for an image generation model.
Output should be in this format Prompt should be in 200 words.
--- Output should be in this format
{ ---
"prompt":"" {
} "prompt":""
--- }
`); ---
const videoPrompt = videoPromptResponse.prompt; `);
logger.info(`Generated video prompt: ${videoPrompt}`); const imagePrompt = imagePromptResponse.prompt;
logger.debug(`Description for ${randomImagePath}:`, imagePrompt);
const videoFileName = `${keyword.replace(/\s/g, '_')}_${timestamp}.mp4`; const timestamp = new Date().getTime();
const generatedVideoPath = await generateVideo(videoPrompt, generatedImagePath, videoFileName); const imageFileName = `${keyword.replace(/\s/g, '_')}_${timestamp}.png`;
logger.info(`Generated video from prompt, saved to: ${generatedVideoPath}`); const generatedImagePath = await generateImage(imagePrompt, imageFileName);
} catch (error) { logger.debug(`Generated new image from prompt, saved to: ${generatedImagePath}`);
logger.error(`Failed to process ${imagePath}:`, error);
const videoPromptResponse = await describeImage(generatedImagePath,
`Generate a prompt for an 8-second video based on the provided image.
The prompt should describe a dynamic scene that evolves from the static image.
Output should be in this format
---
{
"prompt":""
}
---
`);
const videoPrompt = videoPromptResponse.prompt;
logger.debug(`Generated video prompt: ${videoPrompt}`);
const videoFileName = `${keyword.replace(/\s/g, '_')}_${timestamp}.mp4`;
const generatedVideoPath = await generateVideo(videoPrompt, generatedImagePath, videoFileName);
logger.debug(`Generated video from prompt, saved to: ${generatedVideoPath}`);
} catch (error) {
logger.error(`Failed to process ${randomImagePath}:`, error);
}
}
(async () => {
while (1) {
const keywords = [
"beautiful woman portrait",
"handsome man candid",
"interesting street photography",
"stunning landscape",
"vibrant city nightlife",
"elegant fashion model",
"captivating eyes",
"fantasy landscape",
"RPG character art",
"high fashion model",
"city nightscape",
"fireworks display",
"nebula space art",
"3D abstract render"
];
for (const keyword of keywords) {
const startTime = Date.now();
logger.info(`--- Starting process for keyword: ${keyword} ---`);
await generateVideoFromKeyword(keyword);
const endTime = Date.now();
const durationInSeconds = (endTime - startTime) / 1000;
logger.info(`--- Finished process for keyword: ${keyword} in ${durationInSeconds.toFixed(2)} seconds ---`);
} }
} }
})(); })();