const fs = require('fs'); const path = require('path'); // Load .env manually try { const envPath = path.resolve(__dirname, '../.env'); if (fs.existsSync(envPath)) { const envConfig = fs.readFileSync(envPath, 'utf8'); envConfig.split('\n').forEach(line => { line = line.trim(); if (!line || line.startsWith('#')) return; const [key, ...valueParts] = line.split('='); if (key && valueParts.length > 0) { let value = valueParts.join('=').trim(); if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) { value = value.slice(1, -1); } if (!process.env[key.trim()]) { process.env[key.trim()] = value; } } }); console.log("Loaded .env file"); } } catch (e) { console.warn("Could not load .env file:", e.message); } const { PrismaClient } = require('@prisma/client'); const prisma = new PrismaClient(); // Configuration const WORKER_URL = process.env.CLOUDFLARE_WORKER_URL || "https://wild-art-dca7.veltrix620.workers.dev"; const MODELS = ["flux-klein", "flux-klein-4b", "flux-dev"]; // Target First 5 Users const USERS = [ { email: "aarav.patel@gmail.com" }, { email: "diya.sharma88@outlook.com" }, { email: "vihaan.singh@yahoo.com" }, { email: "ananya.g@hotmail.com" }, { email: "arjun.reddy@gmail.com" } ]; // Aspect Ratios const RATIOS = [ { label: "16:9", width: 1024, height: 576 }, { label: "9:16", width: 576, height: 1024 }, { label: "4:3", width: 1024, height: 768 }, { label: "3:4", width: 768, height: 1024 }, { label: "1:1", width: 1024, height: 1024 } ]; // 15 FRESH Unique Prompts (Batch 2) const PROMPTS = [ // Aarav (Futuristic) "A transparent smartphone with holographic display, floating user interface, tech realism", "A sleek bullet train speeding through a snowy mountain pass, motion blur, 8k", "A cyberpunk street cat with neon collar, rainy alleyway reflection, cinematic", // Diya (Artistic) "A portrait of a girl where her hair turns into a flock of birds, surrealism, double exposure", "A miniature world inside a lightbulb, tiny house and forest, magical lighting", "A giant whale flying in the sky above the clouds, dreamlike fantasy art", // Vihaan (Action/Bold) "A knight facing a giant lava monster in a volcano, epic scale, dynamic lighting", "A futuristic formula 1 car, wide angle shot, sparks flying, aggressive stance", "A detailed skull made of melting gold and black liquid, high contrast 3d render", // Ananya (Abstract/Texture) "Close up of colorful ink dropping into water, swirling smoke effect, macro photography", "A geometric origami animal series, lion made of paper folds, studio lighting", "Liquid mercury flowing over black rocks, realistic texture render", // Arjun (Landscape/Epic) "A lost city underwater, sunlight filtering through the ocean surface, ancient ruins", "A cabin in the woods during aurora borealis, cozy warm light, winter night", "A post-apocalyptic overgrown city, nature taking back skyscrapers, last of us vibe" ]; async function generateImage(prompt, model, width, height) { const workerUrl = WORKER_URL.endsWith("/") ? WORKER_URL.slice(0, -1) : WORKER_URL; const endpoint = model; const url = `${workerUrl}/${endpoint}`; try { console.log(`Generating: "${prompt.slice(0, 20)}..." [${width}x${height}] with ${model}`); const response = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ prompt, negative_prompt: "blurry, low quality, bad anatomy, text, watermark", width, height, steps: 30 }), }); if (!response.ok) { console.error(`Failed to generate: ${response.status} ${response.statusText}`); return null; } const result = await response.json(); if (result.success && result.url) { return result.url; } else { console.error("API returned success:false or no URL"); return null; } } catch (error) { console.error("Generation error:", error.message); return null; } } async function main() { console.log("🌱 Starting Aspect Ratio Seeding (Batch 2)..."); let promptIndex = 0; for (const userData of USERS) { // 1. Find User const user = await prisma.user.findUnique({ where: { email: userData.email } }); if (!user) { console.log(`User ${userData.email} not found. Skipping.`); promptIndex += 3; continue; } console.log(`\nProcessing ${user.name}...`); // 2. Generate 3 Images const userPrompts = PROMPTS.slice(promptIndex, promptIndex + 3); promptIndex += 3; for (const prompt of userPrompts) { const model = MODELS[Math.floor(Math.random() * MODELS.length)]; const ratio = RATIOS[Math.floor(Math.random() * RATIOS.length)]; const imageUrl = await generateImage(prompt, model, ratio.width, ratio.height); if (imageUrl) { await prisma.generation.create({ data: { prompt: prompt, model: model, width: ratio.width, height: ratio.height, imageUrl: imageUrl, userId: user.id, isPublic: true, createdAt: new Date() } }); console.log(`Saved generation (${ratio.label})`); } else { console.log(`Failed generation`); } // Small delay await new Promise(r => setTimeout(r, 1000)); } } console.log("\nāœ… Seeding Complete!"); } main() .catch(e => { console.error(e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });