File size: 6,351 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

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();
    });