File size: 873 Bytes
fd72d0b | 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 |
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 = "";
}
|