| async function generateAd() { | |
| const prompt = document.getElementById("promptInput").value; | |
| const status = document.getElementById("status"); | |
| const outputImage = document.getElementById("outputImage"); | |
| status.textContent = "Generating..."; | |
| outputImage.src = ""; | |
| const response = await fetch("https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0", { | |
| method: "POST", | |
| headers: { | |
| "Authorization": "Bearer YOUR_HF_TOKEN", | |
| "Content-Type": "application/json" | |
| }, | |
| body: JSON.stringify({ inputs: prompt }) | |
| }); | |
| if (!response.ok) { | |
| status.textContent = "Error generating image."; | |
| return; | |
| } | |
| const blob = await response.blob(); | |
| const imageUrl = URL.createObjectURL(blob); | |
| outputImage.src = imageUrl; | |
| status.textContent = ""; | |
| } | |