File size: 5,868 Bytes
0aee795
 
de4a1e3
 
b6de60c
 
 
21f0344
 
 
 
 
 
 
 
de4a1e3
 
 
21f0344
 
 
de4a1e3
21f0344
de4a1e3
21f0344
de4a1e3
21f0344
de4a1e3
21f0344
 
de4a1e3
21f0344
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a2814c1
b6de60c
21f0344
 
 
b6de60c
 
21f0344
b6de60c
 
 
 
 
 
a2814c1
b6de60c
21f0344
de4a1e3
21f0344
b6de60c
 
 
 
 
 
 
 
 
 
 
de4a1e3
 
21f0344
 
 
de4a1e3
21f0344
 
 
de4a1e3
21f0344
 
 
 
 
 
de4a1e3
 
21f0344
 
 
 
 
 
de4a1e3
21f0344
 
 
 
de4a1e3
21f0344
 
 
 
 
 
de4a1e3
 
21f0344
 
a2814c1
de4a1e3
21f0344
b6de60c
21f0344
de4a1e3
 
21f0344
 
b6de60c
de4a1e3
21f0344
b6de60c
de4a1e3
 
 
 
 
21f0344
de4a1e3
21f0344
 
 
 
 
 
 
 
 
 
 
de4a1e3
 
 
 
 
 
 
 
 
a2814c1
de4a1e3
21f0344
b6de60c
 
 
 
 
 
 
21f0344
 
 
 
 
 
 
de4a1e3
 
 
b6de60c
 
 
 
 
 
 
 
 
de4a1e3
 
 
 
 
 
 
 
 
 
 
 
 
0aee795
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>DALL·E Mini - 4 Image Generator</title>
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet"/>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
  <style>
    :root {
      --bg-color: #121212;
      --card-color: #1e1e1e;
      --text-color: #f0f0f0;
      --accent-color: #4ade80;
    }

    body {
      margin: 0;
      background: var(--bg-color);
      color: var(--text-color);
      font-family: 'Inter', sans-serif;
    }

    .container {
      max-width: 960px;
      margin: auto;
      padding: 2rem;
    }

    h1 {
      text-align: center;
      font-size: 2rem;
      margin-bottom: 0.5rem;
    }

    p {
      text-align: center;
      font-size: 1rem;
      color: #ccc;
    }

    .input-area {
      display: flex;
      flex-direction: column;
      gap: 1rem;
      margin: 2rem 0;
      align-items: center;
    }

    input[type="text"] {
      padding: 0.8rem 1rem;
      border: none;
      border-radius: 8px;
      width: 100%;
      max-width: 600px;
      font-size: 1rem;
      background: #2a2a2a;
      color: var(--text-color);
    }

    button {
      padding: 0.8rem 1.5rem;
      background: var(--accent-color);
      border: none;
      border-radius: 8px;
      font-weight: 600;
      color: #000;
      cursor: pointer;
      transition: 0.3s ease;
    }

    button:hover {
      background: #22c55e;
    }

    #gallery {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
      gap: 1.5rem;
      margin-top: 2rem;
    }

    .image-card {
      background: var(--card-color);
      border-radius: 10px;
      padding: 1rem;
      text-align: center;
    }

    .image-card img {
      width: 100%;
      aspect-ratio: 16 / 9;
      border-radius: 8px;
      object-fit: cover;
    }

    .image-card button {
      margin-top: 0.8rem;
      width: 100%;
      background: #3b82f6;
      color: white;
    }

    .image-card button:hover {
      background: #2563eb;
    }

    #screenshot {
      display: none;
      margin: 2rem auto;
      background: #3b82f6;
      color: white;
    }

    #screenshot:hover {
      background: #2563eb;
    }

    .loader {
      text-align: center;
      font-size: 1rem;
      color: #999;
      margin-top: 2rem;
    }

    footer {
      margin-top: 3rem;
      text-align: center;
      font-size: 0.85rem;
      color: #888;
    }

    a {
      color: var(--accent-color);
      text-decoration: none;
    }

    @media (max-width: 500px) {
      input[type="text"] {
        width: 90%;
      }
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>DALL·E Mini by <a href="https://www.craiyon.com/" target="_blank">Craiyon</a></h1>
    <p>Generate 4 AI images (YouTube-ready size) and download them</p>

    <div class="input-area">
      <input id="prompt" type="text" placeholder="E.g. astronaut riding a unicorn in space" />
      <button onclick="runPrompt()">Generate Images</button>
    </div>

    <div id="gallery"></div>
    <div class="loader" id="loader"></div>
    <button id="screenshot" onclick="captureScreenshot()">Download All as Screenshot</button>

    <footer>
      Built by <a href="https://twitter.com/borisdayma" target="_blank">Boris Dayma</a> • Powered by <a href="https://www.craiyon.com/" target="_blank">Craiyon</a>
    </footer>
  </div>

  <script>
    async function runPrompt() {
      const prompt = document.getElementById("prompt").value.trim();
      const gallery = document.getElementById("gallery");
      const loader = document.getElementById("loader");
      const screenshotBtn = document.getElementById("screenshot");

      gallery.innerHTML = "";
      loader.textContent = "Generating images... Please wait.";
      screenshotBtn.style.display = "none";

      if (!prompt) {
        loader.textContent = "Please enter a prompt.";
        return;
      }

      try {
        const res = await fetch("https://bf.dallemini.ai/generate", {
          method: "POST",
          headers: { "Content-Type": "application/json" },
          body: JSON.stringify({ prompt })
        });

        const data = await res.json();
        const images = (data.images || []).slice(0, 4);

        if (images.length > 0) {
          gallery.innerHTML = images.map((img, i) => `
            <div class="image-card">
              <img src="data:image/png;base64,${img}" id="img-${i}" />
              <button onclick="downloadImage('${img}', 'image-${i + 1}.png')">Download</button>
            </div>
          `).join("");

          screenshotBtn.style.display = "block";
          loader.textContent = "";
        } else {
          loader.textContent = "No images returned. Try a different prompt.";
        }
      } catch (error) {
        loader.textContent = "Error: Server busy or unreachable. Try again later.";
      }
    }

    function downloadImage(base64, filename) {
      const a = document.createElement("a");
      a.href = "data:image/png;base64," + base64;
      a.download = filename;
      document.body.appendChild(a);
      a.click();
      document.body.removeChild(a);
    }

    function captureScreenshot() {
      html2canvas(document.getElementById("gallery")).then(canvas => {
        const image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
        const a = document.createElement("a");
        const now = new Date();
        const filename = `dallemini_${now.toISOString().replace(/[:T]/g, "-").split(".")[0]}.png`;
        a.setAttribute("download", filename);
        a.setAttribute("href", image);
        a.click();
      });
    }
  </script>
</body>
</html>