// HuggingFace API Configuration const HF_API_KEY = 'YOUR_HF_API_KEY'; const SFW_MODELS = { 'Stable Diffusion XL': 'stabilityai/stable-diffusion-xl-base-1.0', 'DreamShaper XL': 'lykon/dreamshaper-xl', 'Anime XL': 'cagliostrolab/animagine-xl-3.0', 'Cyberpunk Anime': 'DGSpitzer/Cyberpunk-Anime-Diffusion', 'Realistic Vision': 'SG161222/Realistic_Vision_V5.1', 'Juggernaut XL': 'stabilityai/stable-diffusion-xl-base-1.0', 'Epic Realism': 'epicrealism/epicrealism-natural-sin', 'Pixel Art': 'nerijs/pixel-art-xl' }; const NSFW_MODELS = { 'Erotica XL': 'gsdf/Counterfeit-V3.0', 'Hentai XL': 'nitrosocke/henmixReal', 'Adult XL': 'gsdf/Erotica', 'NSFW Anime': 'cagliostro/hentai-diffusion', 'Lewd Realism': 'gsdf/lewd-diffusion', 'Boudoir': 'gsdf/boudoir-diffusion', 'Kinky Art': 'gsdf/kinky-diffusion' }; let currentModel = SFW_MODELS['Stable Diffusion XL']; let isNSFW = false; // DOM Elements const promptInput = document.querySelector('textarea'); const styleSelect = document.querySelector('select:nth-of-type(1)'); const modelSelect = document.querySelector('select:nth-of-type(2)'); const generateBtn = document.querySelector('button'); const previewBox = document.querySelector('.aspect-square'); const gallerySection = document.getElementById('gallery'); const nsfwToggle = document.createElement('div'); // Initialize NSFW Toggle function initNSFWToggle() { nsfwToggle.className = 'flex items-center gap-2 mb-4'; nsfwToggle.innerHTML = ` Content Filter `; document.querySelector('#generate .space-y-4').prepend(nsfwToggle); nsfwToggle.querySelector('input').addEventListener('change', toggleNSFW); } // Toggle NSFW/SFW mode function toggleNSFW(e) { isNSFW = e.target.checked; updateModelOptions(); nsfwToggle.querySelector('span:last-child').textContent = isNSFW ? 'NSFW' : 'SFW'; } // Update model options based on SFW/NSFW mode function updateModelOptions() { modelSelect.innerHTML = ''; const models = isNSFW ? NSFW_MODELS : SFW_MODELS; for (const [name, modelId] of Object.entries(models)) { const option = document.createElement('option'); option.value = modelId; option.textContent = name; if (modelId === currentModel) option.selected = true; modelSelect.appendChild(option); } } // Enhanced image generation with error handling and model status checks async function generateImage() { const prompt = promptInput.value.trim(); if (!prompt) { showToast('Please enter a prompt', 'error'); return; } generateBtn.disabled = true; generateBtn.innerHTML = ' Weaving Pixels...'; feather.replace(); try { // First check if model is loaded const modelStatus = await fetch(`https://api-inference.huggingface.co/status/${currentModel}`, { headers: { 'Authorization': `Bearer ${HF_API_KEY}` } }); if (!modelStatus.ok) throw new Error('Model status check failed'); const statusData = await modelStatus.json(); if (statusData.loaded !== true) { showToast('Model is loading, please wait...', 'warning'); return; } // Generate image const response = await fetch(`https://api-inference.huggingface.co/models/${currentModel}`, { method: 'POST', headers: { 'Authorization': `Bearer ${HF_API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ inputs: prompt, parameters: { width: 1024, height: 1024, num_inference_steps: 50, guidance_scale: 7.5 }, options: { wait_for_model: true } }) }); if (!response.ok) { const error = await response.json(); throw new Error(error.error || 'Generation failed'); } const imageBlob = await response.blob(); const imageUrl = URL.createObjectURL(imageBlob); // Update preview previewBox.innerHTML = `
${prompt}