scott / index.html
D0pamineaddicted's picture
Create index.html
9ab908b verified
Raw History Blame Contribute Delete
4.75 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Static AI Image Generator</title>
<script src="https://jsdelivr.net"></script>
</head>
<body class="bg-gray-900 text-gray-100 min-h-screen flex flex-col justify-between font-sans">
<!-- Header -->
<header class="p-4 bg-gray-800 border-b border-gray-700 shadow-md flex justify-between items-center">
<h1 class="text-xl font-bold text-indigo-400">🎨 Free AI Image Generator</h1>
<span class="text-xs bg-indigo-500/20 text-indigo-400 px-2 py-1 rounded-full font-mono">FLUX Engine</span>
</header>
<!-- Main Workspace -->
<main class="flex-1 max-w-4xl w-full mx-auto p-6 flex flex-col items-center justify-center gap-6">
<!-- Image Render Canvas -->
<div id="canvas-container" class="w-full aspect-square max-w-md bg-gray-800 rounded-2xl border-2 border-dashed border-gray-700 flex flex-col items-center justify-center overflow-hidden relative shadow-2xl">
<div id="placeholder-text" class="text-center p-6 text-gray-500">
<p class="text-5xl mb-2">🖼️</p>
<p class="text-sm">Your generated artwork will appear here</p>
</div>
<img id="output-image" class="hidden w-full h-full object-contain" alt="AI Generated Output">
<!-- Loading Spinner -->
<div id="spinner" class="hidden absolute inset-0 bg-gray-900/80 flex flex-col items-center justify-center gap-3">
<div class="w-12 h-12 border-4 border-indigo-500 border-t-transparent rounded-full animate-spin"></div>
<p class="text-indigo-400 text-sm font-medium animate-pulse">Generating your masterpiece...</p>
</div>
</div>
<!-- Prompt Entry Box -->
<form id="generator-form" class="w-full max-w-xl bg-gray-800 p-4 rounded-xl border border-gray-700 shadow-lg flex gap-2">
<input id="prompt-input" type="text" placeholder="A futuristic neon city cyber-punk street portrait..." required
class="flex-1 bg-gray-700 border border-gray-600 rounded-lg px-4 py-3 text-white placeholder-gray-400 focus:outline-none focus:border-indigo-500 transition-colors">
<button type="submit" class="bg-indigo-600 hover:bg-indigo-700 active:bg-indigo-800 px-6 py-3 rounded-lg font-semibold tracking-wide transition-colors whitespace-nowrap shadow-md">
Generate
</button>
</form>
</main>
<!-- Footer -->
<footer class="p-3 text-center text-xs text-gray-600 border-t border-gray-800 bg-gray-950">
Powered by Hugging Face Inference API & Black Forest Labs
</footer>
<!-- Logic Script -->
<script>
const form = document.getElementById('generator-form');
const promptInput = document.getElementById('prompt-input');
const outputImage = document.getElementById('output-image');
const placeholderText = document.getElementById('placeholder-text');
const spinner = document.getElementById('spinner');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const promptValue = promptInput.value.trim();
if (!promptValue) return;
// Trigger visual UI loading states
spinner.classList.remove('hidden');
outputImage.classList.add('hidden');
placeholderText.classList.add('hidden');
try {
// Fetch directly from the free public endpoint
const response = await fetch(
"https://huggingface.co",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ inputs: promptValue }),
}
);
if (!response.ok) throw new Error("API Limit reached or service busy.");
// Convert incoming binary image stream into a displayable browser blob
const blob = await response.blob();
const objectURL = URL.createObjectURL(blob);
outputImage.src = objectURL;
outputImage.classList.remove('hidden');
} catch (error) {
alert("Generation Failed: " + error.message + "\nTry adding an HF access token inside your request headers if rate-limited.");
placeholderText.classList.remove('hidden');
} finally {
spinner.classList.add('hidden');
}
});
</script>
</body>
</html>