Iot / scripts /seed-more.js
veltrixcode's picture
Upload 74 files
64fa001 verified
Raw History Blame
7.47 kB
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();
});