Spaces:
Sleeping
Sleeping
File size: 7,472 Bytes
64fa001 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
const fs = require('fs');
const path = require('path');
// Load .env manually since dotenv might not be installed
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"];
// 10 Realistic Indian Users (Same as seed-data.js)
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" },
{ email: "zara.khan.design@gmail.com" },
{ email: "ishaan.k99@outlook.com" },
{ email: "priya.malhotra@yahoo.com" },
{ email: "rohan.verma@gmail.com" },
{ email: "sanya.kapoor@hotmail.com" }
];
// 30 Fresh Unique Prompts (3 per user)
const PROMPTS = [
// Aarav (Mix of Tech & Nature)
"A solar-powered eco-city floating on the ocean, green technology, utopia, aerial view",
"Close-up of a mechanical beetle with gemstone eyes, intricate clockwork details",
"A lone astronaut standing on a purple sand dune, gazing at double moons",
// Diya (Artistic & Soft)
"A glasshouse filled with bioluminescent giant mushrooms, night time, magical atmosphere",
"Portrait of a woman wearing a dress made of flowing water, surreal fashion",
"A cozy reading nook inside a hollowed-out ancient tree, warm lantern light",
// Vihaan (Bold & dynamic)
"A cyberpunk samurai riding a neon motorcycle, rainy tokyo street background",
"A massive stone golem sleeping in a mountain range, covered in moss and trees",
"Abstract visualization of sound waves, vibrant neon colors against black",
// Ananya (Pattern & Texture)
"Intricate mosaic floor design with gold and turquoise tiles, geometric patterns",
"A macro shot of a peacock feather, iridescent colors, high detail",
"A vintage library with floating books, magical realism style",
// Arjun (Fantasy & Epic)
"A phoenix rising from ashes, dramatic fire effects, cinematic lighting",
"A hidden temple in the jungle, overgrown with vines, waterfalls cascading down",
"A fleet of steampunk airships in the clouds, brass and copper textures",
// Zara (Fashion & Modern)
"Futuristic runway fashion, holographic fabric, avant-garde style",
"A modern architectural glass building reflecting a sunset, sleek lines",
"A stylized portrait of a cat wearing diamond jewelry, luxury art",
// Ishaan (Playful & Retro)
"A 90s vaporwave aesthetic landscape, grid floor, palm trees, pink sun",
"A cute robot watering plants in a greenhouse, pixar style render",
"A delicious tower of colorful macarons, food photography",
// Priya (Traditional & Cosmic)
"A mandala made of stars and galaxies, cosmic spiritual art",
"A traditional Indian dancer silhouette against a giant moon",
"A serene lake reflecting the aurora borealis, winter landscape",
// Rohan (Render & 3D)
"Low poly 3D island with a volcano and palm trees, isometric view",
"A futuristic helmet design, glossy white and orange, sci-fi concept",
"A liquid chrome sphere reflecting a distorted city, abstract 3D art",
// Sanya (Nature & Portrait)
"Double exposure of a tiger and a dense jungle, black and white",
"A field of sunflowers at golden hour, warm and sunny vibe",
"A portrait of a girl with butterfly wings, fantasy concept art"
];
async function generateImage(prompt, model) {
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, 30)}..." 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: 1024,
height: 1024,
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 Additional Seeding (3 images/user)...");
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; // Skip 3 prompts to keep alignment
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 imageUrl = await generateImage(prompt, model);
if (imageUrl) {
await prisma.generation.create({
data: {
prompt: prompt,
model: model,
width: 1024,
height: 1024,
imageUrl: imageUrl,
userId: user.id,
isPublic: true,
createdAt: new Date()
}
});
console.log(`Saved generation: "${prompt.slice(0, 20)}..."`);
} else {
console.log(`Failed generation: "${prompt.slice(0, 20)}..."`);
}
// 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();
});
|