File size: 4,749 Bytes
9ab908b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ec2d5f
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!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>