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 { logger } from './lib/logger';
(async () => {
const keyword = 'cyberpunk city';
async function generateVideoFromKeyword(keyword: string) {
const numberOfPages = 1;
const imagePaths = await downloadPinterestImages(keyword, numberOfPages);
logger.info('Downloaded images:', imagePaths);
logger.debug('Downloaded images:', imagePaths);
for (const imagePath of imagePaths) {
try {
const llmResponseJSON = await describeImage(imagePath,
`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);
if (imagePaths.length === 0) {
logger.warn('No images downloaded, cannot proceed.');
return;
}
const timestamp = new Date().getTime();
const imageFileName = `${keyword.replace(/\s/g, '_')}_${timestamp}.png`;
const generatedImagePath = await generateImage(prompt, imageFileName);
logger.info(`Generated new image from prompt, saved to: ${generatedImagePath}`);
const randomImagePath = imagePaths[Math.floor(Math.random() * imagePaths.length)];
logger.debug(`Randomly selected image: ${randomImagePath}`);
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.info(`Generated video prompt: ${videoPrompt}`);
try {
const imagePromptResponse = await describeImage(randomImagePath,
`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 imagePrompt = imagePromptResponse.prompt;
logger.debug(`Description for ${randomImagePath}:`, imagePrompt);
const videoFileName = `${keyword.replace(/\s/g, '_')}_${timestamp}.mp4`;
const generatedVideoPath = await generateVideo(videoPrompt, generatedImagePath, videoFileName);
logger.info(`Generated video from prompt, saved to: ${generatedVideoPath}`);
} catch (error) {
logger.error(`Failed to process ${imagePath}:`, error);
const timestamp = new Date().getTime();
const imageFileName = `${keyword.replace(/\s/g, '_')}_${timestamp}.png`;
const generatedImagePath = await generateImage(imagePrompt, imageFileName);
logger.debug(`Generated new image from prompt, saved to: ${generatedImagePath}`);
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 ---`);
}
}
})();