File size: 11,323 Bytes
2bc4341
6aa6107
 
 
 
 
 
 
 
2bc4341
6aa6107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2bc4341
 
6aa6107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2bc4341
03dd1b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
029704a
f1e309c
029704a
 
 
 
 
 
 
f1e309c
 
 
029704a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1e309c
 
 
 
029704a
f1e309c
 
 
 
029704a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1e309c
 
 
 
 
03dd1b5
 
 
f1e309c
03dd1b5
 
 
 
 
 
 
 
 
 
 
2bc4341
 
 
 
 
 
 
 
6aa6107
 
03dd1b5
6aa6107
 
 
 
 
03dd1b5
 
 
 
 
ff787c8
 
 
 
 
2bc4341
6aa6107
 
 
 
 
2bc4341
03dd1b5
 
 
 
 
 
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253

// AI Generation Manager
class AIGenerationManager {
    constructor() {
        if (!localStorage.getItem('generationHistory')) {
            localStorage.setItem('generationHistory', JSON.stringify([]));
        }
        this.favoriteGenerations = JSON.parse(localStorage.getItem('favoriteGenerations') || '[]');
    }

    saveGeneration(prompt, images, metadata = {}) {
        const history = JSON.parse(localStorage.getItem('generationHistory'));
        history.unshift({
            prompt,
            images,
            metadata: {
                model: metadata.model || 'stable-diffusion-v2',
                style: metadata.style || 'default',
                timestamp: new Date().toISOString(),
                favorite: false
            }
        });
        localStorage.setItem('generationHistory', JSON.stringify(history));
    }

    addFeedback(id, feedback) {
        const history = JSON.parse(localStorage.getItem('generationHistory'));
        const item = history.find(item => item.id === id);
        if (item) {
            item.feedback = feedback;
            localStorage.setItem('generationHistory', JSON.stringify(history));
        }
    }

    toggleFavorite(id) {
        const history = JSON.parse(localStorage.getItem('generationHistory'));
        const item = history.find(item => item.id === id);
        if (item) {
            item.metadata.favorite = !item.metadata.favorite;
            localStorage.setItem('generationHistory', JSON.stringify(history));
            return item.metadata.favorite;
        }
        return false;
    }

    getHistory() {
        return JSON.parse(localStorage.getItem('generationHistory'));
    }

    getFavorites() {
        return this.getHistory().filter(item => item.metadata.favorite);
    }
}

const aiManager = new AIGenerationManager();
document.addEventListener('DOMContentLoaded', async function() {
    // Load AI models from API (simulated)
    async function loadAIModels() {
        // In a real app, this would fetch from your API
        return new Promise(resolve => {
            setTimeout(() => {
                resolve([
                    { id: 'stable-diffusion-v2', name: 'Stable Diffusion v2', description: 'Best for general purpose generations' },
                    { id: 'dall-e-3', name: 'DALL-E 3', description: 'Best for creative and artistic generations' },
                    { id: 'midjourney-v5', name: 'Midjourney v5', description: 'Best for photorealistic images' }
                ]);
            }, 500);
        });
    }

    // Initialize AI models dropdown
    if (document.querySelector('#ai-model')) {
        const models = await loadAIModels();
        const modelSelect = document.querySelector('#ai-model');
        models.forEach(model => {
            const option = document.createElement('option');
            option.value = model.id;
            option.textContent = model.name;
            modelSelect.appendChild(option);
        });
    }
// Initialize file upload functionality
    const uploadArea = document.querySelector('.border-dashed');
    const fileInput = document.querySelector('input[type="file"]');
    
    uploadArea.addEventListener('click', () => fileInput.click());
    
    uploadArea.addEventListener('dragover', (e) => {
        e.preventDefault();
        uploadArea.classList.add('border-primary', 'bg-gray-700/50');
    });
    
    uploadArea.addEventListener('dragleave', () => {
        uploadArea.classList.remove('border-primary', 'bg-gray-700/50');
    });
    
    uploadArea.addEventListener('drop', (e) => {
        e.preventDefault();
        uploadArea.classList.remove('border-primary', 'bg-gray-700/50');
        if (e.dataTransfer.files.length) {
            fileInput.files = e.dataTransfer.files;
            handleFileUpload(e.dataTransfer.files[0]);
        }
    });
    
    fileInput.addEventListener('change', () => {
        if (fileInput.files.length) {
            handleFileUpload(fileInput.files[0]);
        }
    });
});

function handleFileUpload(file) {
    // In a real app, you would handle the file upload here
    console.log('File selected:', file.name);
    
    // Preview the image
    const reader = new FileReader();
    reader.onload = function(e) {
        const uploadArea = document.querySelector('.border-dashed');
        uploadArea.innerHTML = `
            <img src="${e.target.result}" class="max-h-48 mx-auto rounded-md" alt="Preview">
            <p class="text-sm text-gray-300 mt-2">${file.name}</p>
        `;
    };
    reader.readAsDataURL(file);
}
// Creative random prompt generator with more variety
const promptTemplates = [
    "{color} {mood} {subject} in {environment} with {style} style, {lighting} lighting, {perspective} view",
    "{adjective} {subject} in {timeOfDay} with {colorScheme} colors, {artStyle} style",
    "{artStyle} of {subject} in {worldType}, {mood} atmosphere, {weather} weather",
    "{perspective} view of {subject} with {lighting} lighting, {artStyle} style",
    "{subject} in {location}, {timePeriod} {style} style, {mood} atmosphere",
    "A {adjective} {subject} {action} in {environment}, {artStyle} style",
    "{subject} {action} during {timeOfDay} in {location}, {style} style"
];

const promptWords = {
    subject: ["dragon", "castle", "forest", "robot", "spaceship", "samurai", "wizard", "city", "ocean", "beast", 
              "knight", "unicorn", "cyborg", "mermaid", "phoenix", "dinosaur", "alien", "ghost", "angel", "demon"],
    mood: ["mystical", "dramatic", "serene", "chaotic", "moody", "whimsical", "dark", "light", "surreal", 
           "epic", "romantic", "ominous", "joyful", "melancholic", "energetic", "peaceful"],
    environment: ["misty mountains", "cyberpunk alley", "ancient ruins", "crystal caves", "floating islands",
                 "underground city", "magical library", "space station", "enchanted forest", "haunted mansion"],
    color: ["red", "blue", "golden", "silver", "purple", "emerald", "rainbow", "pastel", "neon", "monochrome"],
    adjective: ["glowing", "ethereal", "futuristic", "ancient", "majestic", "tiny", "gigantic", "mysterious",
               "legendary", "forgotten", "hidden", "celestial", "mechanical", "organic", "crystalline"],
    timeOfDay: ["sunrise", "midnight", "golden hour", "blue hour", "noon", "twilight", "dawn", "dusk"],
    colorScheme: ["monochromatic", "complementary", "analogous", "warm", "cool", "triadic", "tetradic"],
    artStyle: ["Painting", "Sculpture", "Digital art", "Watercolor", "Oil painting", "Charcoal sketch", 
               "Pixel art", "Anime", "Concept art", "Surrealist", "Impressionist", "Abstract"],
    worldType: ["fantasy world", "sci-fi universe", "post-apocalyptic wasteland", "alien planet", 
               "steampunk city", "dream realm", "underwater kingdom", "floating continent"],
    perspective: ["Close-up", "Wide angle", "Birds-eye", "Worms-eye", "Tilted", "Macro", "Fisheye", "Panoramic"],
    lighting: ["volumetric", "neon", "natural", "bioluminescent", "chiaroscuro", "moonlight", "sunbeams",
              "candlelight", "strobe", "firelight"],
    location: ["Paris", "Tokyo", "New York", "African savanna", "Amazon rainforest", "Himalayas", 
              "Great Barrier Reef", "Sahara Desert", "Antarctica", "Venice"],
    timePeriod: ["medieval", "Victorian", "1920s", "futuristic", "Stone age", "Renaissance", "Ancient Egypt",
                "Wild West", "Space Age", "Prehistoric"],
    style: ["photorealistic", "concept art", "character design", "editorial", "minimalist", "hyperrealistic",
           "low poly", "isometric", "line art", "graffiti"],
    weather: ["rainy", "sunny", "foggy", "stormy", "snowy", "windy", "cloudy", "aurora-filled"],
    action: ["flying", "battling", "meditating", "exploring", "dancing", "singing", "casting spells", 
            "building", "destroying", "protecting"]
};
function generateRandomPrompt() {
    const template = promptTemplates[Math.floor(Math.random() * promptTemplates.length)];
    
    let prompt = template.replace(/{([^}]+)}/g, (match, key) => {
        const words = promptWords[key];
        return words ? words[Math.floor(Math.random() * words.length)] : match;
    });

    // Add some random artistic modifiers 50% of the time
    if (Math.random() > 0.5) {
        const modifiers = [
            "trending on artstation",
            "4k resolution",
            "highly detailed",
            "intricate details",
            "cinematic lighting",
            "octane render",
            "unreal engine",
            "8k wallpaper",
            "sharp focus",
            "studio quality"
        ];
        prompt += `, ${modifiers[Math.floor(Math.random() * modifiers.length)]}`;
    }

    return prompt;
}
document.getElementById('random-prompt').addEventListener('click', function() {
    const promptInput = document.getElementById('prompt-input');
    promptInput.value = generateRandomPrompt();
    promptInput.focus();
});

// Generate button functionality
document.querySelector('.bg-gradient-to-r').addEventListener('click', function() {
// In a real app, this would call your AI generation API
    console.log('Generating images...');
    
    // Simulate loading
    const button = this;
    const originalText = button.innerHTML;
    button.innerHTML = '<i data-feather="loader" class="animate-spin w-4 h-4 mr-2"></i> Generating...';
    button.disabled = true;
    // Simulate API call
    setTimeout(() => {
        button.innerHTML = originalText;
        button.disabled = false;
        // Simulate generated images
        const generatedImages = [
            'http://static.photos/abstract/640x360/' + Math.floor(Math.random() * 100),
            'http://static.photos/abstract/640x360/' + Math.floor(Math.random() * 100)
        ];
        
        // Save to history
        const prompt = document.querySelector('textarea').value || 'Untitled generation';
        const model = document.querySelector('#ai-model').value;
        const style = document.querySelector('#style-select').value;
        
        aiManager.saveGeneration(prompt, generatedImages, {
            model,
            style
        });
// Show success message
        const success = document.createElement('div');
        success.className = 'fixed top-4 right-4 bg-green-500 text-white px-4 py-2 rounded-md shadow-lg';
        success.innerHTML = '<i data-feather="check-circle" class="w-4 h-4 inline mr-2"></i> Images generated successfully!';
        document.body.appendChild(success);
        
        // Show results section with generated images
        const resultsSection = document.getElementById('results');
        resultsSection.classList.remove('hidden');
        resultsSection.scrollIntoView({ behavior: 'smooth' });
        
        // Update the images
        const previews = document.querySelectorAll('image-preview');
        previews[0].setAttribute('src', generatedImages[0]);
        previews[0].setAttribute('ai-generated', 'true');
        previews[1].setAttribute('src', generatedImages[1]);
        previews[1].setAttribute('ai-generated', 'true');
// Refresh icons (since we added new ones)
        feather.replace();
        
        // Remove message after 3 seconds
        setTimeout(() => success.remove(), 3000);
    }, 2000);
});