save changes

This commit is contained in:
2025-10-02 07:34:50 +02:00
parent bdca42e821
commit 1de8749195
8 changed files with 1078 additions and 3116 deletions

View File

@ -0,0 +1,78 @@
import * as fs from 'fs';
import * as path from 'path';
import { convertImageWithFile } from '../../lib/image-converter';
import dotenv from 'dotenv';
dotenv.config();
const girlDir = path.join(__dirname, '../../../input/girl');
const monsterDir = path.join(__dirname, '../../../input/monster');
const outputDir = path.join(__dirname, '../../../generated');
const prompt = "只提取图1中的女生把她放在图2的怪物之间。";
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const comfyBaseUrl = process.env.SERVER2_COMFY_BASE_URL;
const comfyOutputDir = process.env.SERVER2_COMFY_OUTPUT_DIR;
if (!comfyBaseUrl || !comfyOutputDir) {
console.error("Please define SERVER1_COMFY_BASE_URL and SERVER1_COMFY_OUTPUT_DIR in your .env file");
process.exit(1);
}
const comfyInputDir = comfyOutputDir.replace("output", "input");
if (!fs.existsSync(comfyInputDir)) {
fs.mkdirSync(comfyInputDir, { recursive: true });
}
async function combineImages() {
while (true) {
try {
const girlImages = fs.readdirSync(girlDir).filter(file => /\.(jpg|jpeg|png)$/i.test(file));
const monsterImages = fs.readdirSync(monsterDir).filter(file => /\.(jpg|jpeg|png)$/i.test(file));
if (girlImages.length === 0 || monsterImages.length === 0) {
console.log('Input directories are empty. Waiting...');
await new Promise(resolve => setTimeout(resolve, 5000));
continue;
}
const randomGirlImage = girlImages[Math.floor(Math.random() * girlImages.length)];
const randomMonsterImage = monsterImages[Math.floor(Math.random() * monsterImages.length)];
const image1Path = path.join(girlDir, randomGirlImage);
const image2Path = path.join(monsterDir, randomMonsterImage);
// Copy files to comfy input directory
const destImage1Path = path.join(comfyInputDir, randomGirlImage);
const destImage2Path = path.join(comfyInputDir, randomMonsterImage);
fs.copyFileSync(image1Path, destImage1Path);
fs.copyFileSync(image2Path, destImage2Path);
console.log(`Combining ${randomGirlImage} and ${randomMonsterImage}`);
const generatedFilePath = await convertImageWithFile(prompt, randomGirlImage, randomMonsterImage, comfyBaseUrl!, comfyOutputDir!);
if (generatedFilePath && fs.existsSync(generatedFilePath)) {
const timestamp = new Date().getTime();
const newFileName = `combined_${timestamp}.png`;
const newFilePath = path.join(outputDir, newFileName);
fs.renameSync(generatedFilePath, newFilePath);
console.log(`Renamed generated file to ${newFilePath}`);
} else {
console.log("Failed to generate or find the image file.");
}
} catch (error) {
console.error('An error occurred:', error);
}
// Wait for a bit before the next iteration
await new Promise(resolve => setTimeout(resolve, 5000));
}
}
combineImages();

View File

@ -52,7 +52,7 @@ async function generatePhotos() {
try {
await generateImage(
`realistic photo of woman, wavy long brown hair, fullbody shot, ${scene.imagePrompt.location},${scene.imagePrompt.angle},${scene.imagePrompt.lighting},${scene.imagePrompt.outfit}`,
`Scary realistic photo, ${scene.imagePrompt.location},${scene.imagePrompt.angle},${scene.imagePrompt.lighting},${scene.imagePrompt.outfit}`,
faceFilePath,
scene.baseImagePath,
imgFileName,

View File

@ -7,7 +7,7 @@ const promptInstructions = `
Video prompt: No slowmotion, Be creative and generate gengle action scene.
`;
6
const inputDir = path.resolve(process.cwd(), 'input');
const inputDir = path.resolve(process.cwd(), 'input/static');
const outputFilePath = path.resolve(process.cwd(), 'src/musicspot_generator/v2/scenes.json');
interface Scene {

View File

@ -7,7 +7,7 @@ import dotenv from 'dotenv';
dotenv.config();
const inputFolderPath = path.join(__dirname, '..', '..', '..', 'input');
const inputFolderPath = path.join(__dirname, '..', '..', '..', 'input/static');
const generatedFolderPath = path.join(__dirname, '..', '..', '..', 'generated');
async function processImages() {

View File

@ -13,8 +13,8 @@ const PINS_TO_COLLECT = 5;
// Hard-coded user prompt
const HARDCODED_USER_PROMPT = process.env.HARDCODED_USER_PROMPT || `
Generate 20 keywords for photos of a girl in scary scene for music video for haloween. All keywords should containe girl in a scene.
Example output : ["a girl in grave yard,"a girl in scary forest","",... and 20 items in array]
Generate 20 keywords for photos of a ghotst or monster from all over the world. "Cute Japanese yokai" is mandatory, also add "Realistic photo cute" keyword to all genearated keywords first.
Example output : ["Cute Japanese yokai","Realistic photo Cute ghost","Realistic photo cute monster","Realistic photo cute haloween monster","Realistic photo cute haloween ghost"... and 20 items in array]
`;
async function getPinUrlsFromPinterest(keyword: string, scrollCount = SCROLL_SEARCH, limit = PINS_TO_COLLECT): Promise<string[]> {

File diff suppressed because it is too large Load Diff