// Global configuration const API_BASE_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' ? 'http://localhost:7860' : `http://${window.location.hostname}:7860`; // Form submission handler document.getElementById('generationForm').addEventListener('submit', async (e) => { e.preventDefault(); const formData = new FormData(e.target); const data = Object.fromEntries(formData); // Show loading state const submitButton = e.target.querySelector('button[type="submit"]'); const originalText = submitButton.innerHTML; submitButton.innerHTML = 'Generating...'; feather.replace(); try { // Simulate API call to Swarm UI const response = await generateImage(data); // Display results displayGeneratedImage(response); // Show results section document.getElementById('results').classList.remove('hidden'); } catch (error) { console.error('Generation failed:', error); alert('Failed to generate image. Please check if Swarm UI is running.'); } finally { // Restore button state submitButton.innerHTML = originalText; feather.replace(); } }); // Mock image generation function (replace with actual Swarm UI API call) async function generateImage(parameters) { // This is a mock implementation - replace with actual API call console.log('Generation parameters:', parameters); // Simulate API delay await new Promise(resolve => setTimeout(resolve, 2000)); // Return mock response with placeholder image return { image_url: `http://static.photos/abstract/640x360/${Math.floor(Math.random() * 1000)}`, parameters: parameters }; } // Display generated image function displayGeneratedImage(response) { const container = document.getElementById('generatedImage'); container.innerHTML = `