yaoqifa commited on
Commit
b193095
·
verified ·
1 Parent(s): 3c211bd

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +465 -466
static/index.html CHANGED
@@ -1,467 +1,466 @@
1
- <!DOCTYPE html>
2
- <html lang="zh-CN">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Imagen Generator</title>
7
- <style>
8
- :root {
9
- --bg-color: #0b0f19;
10
- --card-color: #1a1f2e;
11
- --text-color: #e2e8f0;
12
- --accent-color: #3b82f6;
13
- --input-bg: #2d3748;
14
- --danger-color: #ef4444;
15
- --success-color: #10b981;
16
- }
17
- body {
18
- font-family: 'Segoe UI', system-ui, sans-serif;
19
- background-color: var(--bg-color);
20
- color: var(--text-color);
21
- margin: 0;
22
- padding: 20px;
23
- display: flex;
24
- justify-content: center;
25
- }
26
- .container {
27
- width: 100%;
28
- max-width: 1000px;
29
- display: grid;
30
- grid-template-columns: 350px 1fr;
31
- gap: 20px;
32
- }
33
- .card {
34
- background-color: var(--card-color);
35
- padding: 20px;
36
- border-radius: 12px;
37
- box-shadow: 0 4px 6px rgba(0,0,0,0.3);
38
- }
39
- h1 { margin-top: 0; font-size: 1.5rem; color: var(--accent-color); }
40
- .form-group { margin-bottom: 15px; }
41
- label { display: block; margin-bottom: 5px; font-size: 0.9rem; color: #a0aec0; }
42
- input, select, textarea {
43
- width: 100%;
44
- padding: 10px;
45
- background-color: var(--input-bg);
46
- border: 1px solid #4a5568;
47
- border-radius: 6px;
48
- color: white;
49
- box-sizing: border-box;
50
- font-size: 0.95rem;
51
- }
52
- input:focus, select:focus, textarea:focus {
53
- outline: none;
54
- border-color: var(--accent-color);
55
- }
56
-
57
- /* --- 修正样式:支持多图预览 --- */
58
- .file-upload-wrapper {
59
- position: relative;
60
- border: 2px dashed #4a5568;
61
- border-radius: 6px;
62
- padding: 20px;
63
- text-align: center;
64
- cursor: pointer;
65
- transition: border-color 0.3s;
66
- }
67
- .file-upload-wrapper:hover {
68
- border-color: var(--accent-color);
69
- }
70
- #init_image_input {
71
- position: absolute;
72
- top: 0; left: 0; width: 100%; height: 100%;
73
- opacity: 0;
74
- cursor: pointer;
75
- }
76
- .upload-placeholder { color: #a0aec0; pointer-events: none; }
77
-
78
- .preview-container {
79
- display: none;
80
- margin-top: 10px;
81
- position: relative;
82
- flex-wrap: wrap;
83
- gap: 8px;
84
- }
85
-
86
- /* 缩略图样式 */
87
- .thumb-wrapper {
88
- position: relative;
89
- width: 80px;
90
- height: 80px;
91
- }
92
- .thumb-img {
93
- width: 100%;
94
- height: 100%;
95
- object-fit: cover;
96
- border-radius: 6px;
97
- border: 1px solid #4a5568;
98
- }
99
-
100
- .clear-preview-btn {
101
- position: absolute;
102
- top: -10px;
103
- right: -10px;
104
- background: var(--danger-color);
105
- color: white;
106
- border: none;
107
- border-radius: 50%;
108
- width: 24px;
109
- height: 24px;
110
- cursor: pointer;
111
- font-weight: bold;
112
- line-height: 24px;
113
- text-align: center;
114
- padding: 0;
115
- z-index: 10;
116
- }
117
- /* --------------------------------- */
118
-
119
- button {
120
- width: 100%;
121
- padding: 12px;
122
- background-color: var(--accent-color);
123
- color: white;
124
- border: none;
125
- border-radius: 6px;
126
- font-size: 1rem;
127
- cursor: pointer;
128
- transition: all 0.3s;
129
- font-weight: bold;
130
- opacity: 1;
131
- }
132
- button:hover:not(:disabled) {
133
- background-color: #2563eb;
134
- transform: translateY(-1px);
135
- }
136
- button:disabled {
137
- background-color: #4a5568;
138
- cursor: not-allowed;
139
- opacity: 0.6;
140
- }
141
-
142
- .result-area {
143
- display: flex;
144
- flex-direction: column;
145
- align-items: center;
146
- justify-content: center;
147
- min-height: 400px;
148
- border: 2px dashed #4a5568;
149
- border-radius: 12px;
150
- position: relative;
151
- margin-top: 20px;
152
- }
153
- #result-img {
154
- max-width: 100%;
155
- max-height: 600px;
156
- border-radius: 8px;
157
- display: none;
158
- box-shadow: 0 4px 15px rgba(0,0,0,0.5);
159
- }
160
- .loader {
161
- border: 4px solid #f3f3f3;
162
- border-top: 4px solid var(--accent-color);
163
- border-radius: 50%;
164
- width: 40px;
165
- height: 40px;
166
- animation: spin 1s linear infinite;
167
- display: none;
168
- }
169
- .download-btn {
170
- margin-top: 15px;
171
- background-color: var(--success-color);
172
- width: auto;
173
- padding: 8px 20px;
174
- display: none;
175
- text-decoration: none;
176
- color: white;
177
- border-radius: 6px;
178
- }
179
- @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
180
-
181
- .disclaimer-box {
182
- margin-bottom: 15px;
183
- padding: 12px;
184
- background-color: rgba(239, 68, 68, 0.1);
185
- border: 1px solid rgba(239, 68, 68, 0.3);
186
- border-radius: 6px;
187
- font-size: 0.85rem;
188
- color: #cbd5e1;
189
- line-height: 1.5;
190
- }
191
- .disclaimer-box strong { color: var(--danger-color); display: block; margin-bottom: 5px; }
192
-
193
- .checkbox-wrapper {
194
- display: flex;
195
- align-items: center;
196
- margin-bottom: 15px;
197
- padding: 5px 0;
198
- cursor: pointer;
199
- }
200
- .checkbox-wrapper input[type="checkbox"] {
201
- width: 18px;
202
- height: 18px;
203
- margin-right: 10px;
204
- cursor: pointer;
205
- accent-color: var(--accent-color);
206
- }
207
- .checkbox-wrapper label {
208
- display: inline;
209
- margin: 0;
210
- font-size: 0.95rem;
211
- color: #e2e8f0;
212
- cursor: pointer;
213
- }
214
-
215
- @media (max-width: 768px) {
216
- .container { grid-template-columns: 1fr; }
217
- }
218
- </style>
219
- </head>
220
- <body>
221
-
222
- <div class="container">
223
- <div class="card">
224
- <h1>Imagen Generator</h1>
225
-
226
- <div class="form-group">
227
- <label>API Key</label>
228
- <input type="password" id="api_key" placeholder="sk-...">
229
- </div>
230
-
231
- <div class="form-group">
232
- <label>模型名称</label>
233
- <select id="model">
234
- <option value="nano-banana">nano-banana</option>
235
- <option value="nano-banana-pro">nano-banana-pro</option>
236
- <option value="grok-imagine-1.0">grok-imagine-1.0</option>
237
- <option value="gemini-2.5-flash-image">gemini-2.5-flash-image</option>
238
- <option value="gemini-3-pro-image">gemini-3-pro-image</option>
239
- <option value="gemini-3-pro-image-preview">gemini-3-pro-image-preview</option>
240
- </select>
241
- </div>
242
-
243
- <div class="form-group">
244
- <label>画面比例</label>
245
- <select id="ratio">
246
- <option value="16:9 (1080p/4K)">16:9 (1080p/4K 宽屏)</option>
247
- <option value="1:1 (正方形)">1:1 (正方形)</option>
248
- <option value="9:16 (手机壁纸)">9:16 (手机壁纸)</option>
249
- <option value="4:3 (标准照片)">4:3 (标准照片)</option>
250
- <option value="3:4 (竖向照片)">3:4 (竖向照片)</option>
251
- <option value="21:9 (电影感)">21:9 (电影感)</option>
252
- <option value="2:3 (艺术照)">2:3 (艺术照)</option>
253
- </select>
254
- </div>
255
-
256
- <div class="form-group">
257
- <label>清晰度等级</label>
258
- <select id="scale">
259
- <option value="1k">1k (标准)</option>
260
- <option value="2k">2k (高清)</option>
261
- <option value="4k">4k (超清 Pro)</option>
262
- </select>
263
- </div>
264
-
265
- <div class="form-group">
266
- <label>输出格式</label>
267
- <select id="format">
268
- <option value="png">PNG</option>
269
- <option value="jpg">JPG</option>
270
- </select>
271
- </div>
272
- </div>
273
-
274
- <div class="card">
275
- <div class="form-group">
276
- <label>提示词 (Prompt)</label>
277
- <textarea id="prompt" rows="4" placeholder="描述你想要的画面..."></textarea>
278
- </div>
279
-
280
- <div class="form-group">
281
- <label>参考图 (支持多选,Chat模型可理解多图)</label>
282
- <div class="file-upload-wrapper" id="upload-box">
283
- <span class="upload-placeholder" id="upload-text">点击或拖拽上传图片 (支持多选)</span>
284
- <!-- 增加了 multiple 属性 -->
285
- <input type="file" id="init_image_input" accept="image/jpeg, image/png" multiple>
286
- </div>
287
- <div class="preview-container" id="preview-container">
288
- <button class="clear-preview-btn" onclick="clearImagePreview()">×</button>
289
- <!-- 动态插入缩略图 -->
290
- </div>
291
- </div>
292
- <div class="disclaimer-box">
293
- <strong>⚠️ 免责���明 (Disclaimer)</strong>
294
- 本工具仅供个人学习与技术研究使用。严禁生成色情、暴力、政治敏感等违法内容。用户生成的任何内容纯属个人行为,法律后果由用户自行承担。
295
- </div>
296
-
297
- <div class="checkbox-wrapper">
298
- <input type="checkbox" id="agree_chk" onchange="toggleSubmitButton()">
299
- <label for="agree_chk">我已知晓并承诺合规使用</label>
300
- </div>
301
-
302
- <button onclick="generateImage()" id="gen-btn" disabled>🚫 请先勾选免责声明</button>
303
-
304
- <div class="result-area" id="result-area">
305
- <div class="loader" id="loader"></div>
306
- <img id="result-img" alt="Generated Image" />
307
- <a id="download-link" class="download-btn" href="#" download="image.png">下载图片</a>
308
- <p id="status-text" style="color: #a0aec0; margin-top: 10px;">等待生成...</p>
309
- </div>
310
- </div>
311
- </div>
312
-
313
- <script>
314
- let initImagesList = []; // 改为数组存储多张图片
315
-
316
- // 处理图片上传
317
- const fileInput = document.getElementById('init_image_input');
318
- const previewContainer = document.getElementById('preview-container');
319
- const uploadBox = document.getElementById('upload-box');
320
- const uploadText = document.getElementById('upload-text');
321
-
322
- fileInput.addEventListener('change', async function(e) {
323
- const files = Array.from(e.target.files);
324
- if (!files.length) return;
325
-
326
- // 清空旧数据(或者你可以选择追加,这里选择覆盖逻辑)
327
- initImagesList = [];
328
- // 移除除了清除按钮外的所有子元素
329
- while (previewContainer.children.length > 1) {
330
- previewContainer.removeChild(previewContainer.lastChild);
331
- }
332
-
333
- const readPromises = files.map(file => {
334
- return new Promise((resolve) => {
335
- if (file.size > 10 * 1024 * 1024) {
336
- console.warn(`文件 ${file.name} 太大,已跳过`);
337
- resolve(null);
338
- return;
339
- }
340
- const reader = new FileReader();
341
- reader.onload = function(event) {
342
- resolve({
343
- name: file.name,
344
- data: event.target.result
345
- });
346
- };
347
- reader.readAsDataURL(file);
348
- });
349
- });
350
-
351
- const results = await Promise.all(readPromises);
352
-
353
- results.forEach(res => {
354
- if (res) {
355
- initImagesList.push(res.data);
356
-
357
- // 创建缩略图元素
358
- const div = document.createElement('div');
359
- div.className = 'thumb-wrapper';
360
- const img = document.createElement('img');
361
- img.className = 'thumb-img';
362
- img.src = res.data;
363
- div.appendChild(img);
364
- previewContainer.appendChild(div);
365
- }
366
- });
367
-
368
- if (initImagesList.length > 0) {
369
- previewContainer.style.display = 'flex';
370
- uploadBox.style.display = 'none';
371
- }
372
- });
373
-
374
- function clearImagePreview() {
375
- fileInput.value = '';
376
- initImagesList = [];
377
- // 清空预览DOM
378
- while (previewContainer.children.length > 1) {
379
- previewContainer.removeChild(previewContainer.lastChild);
380
- }
381
- previewContainer.style.display = 'none';
382
- uploadBox.style.display = 'block';
383
- }
384
-
385
- function toggleSubmitButton() {
386
- const checkbox = document.getElementById('agree_chk');
387
- const btn = document.getElementById('gen-btn');
388
- if (checkbox.checked) {
389
- btn.disabled = false;
390
- btn.innerText = "🚀 开始生成";
391
- } else {
392
- btn.disabled = true;
393
- btn.innerText = "🚫 请先勾选免责声明";
394
- }
395
- }
396
-
397
- async function generateImage() {
398
- const apiKey = document.getElementById('api_key').value;
399
- const prompt = document.getElementById('prompt').value;
400
- const checkbox = document.getElementById('agree_chk');
401
-
402
- if (!checkbox.checked) { alert("请先勾选免责声明!"); return; }
403
- if (!apiKey) { alert("请输入 API Key"); return; }
404
- if (!prompt) { alert("请输入提示词"); return; }
405
-
406
- const btn = document.getElementById('gen-btn');
407
- const loader = document.getElementById('loader');
408
- const img = document.getElementById('result-img');
409
- const downloadBtn = document.getElementById('download-link');
410
- const statusText = document.getElementById('status-text');
411
-
412
- btn.disabled = true;
413
- btn.innerText = "生成中...";
414
- loader.style.display = 'block';
415
- img.style.display = 'none';
416
- downloadBtn.style.display = 'none';
417
- statusText.innerText = "正在请求 API...";
418
-
419
- const payload = {
420
- api_key: apiKey,
421
- model: document.getElementById('model').value,
422
- prompt: prompt,
423
- ratio: document.getElementById('ratio').value,
424
- scale: document.getElementById('scale').value,
425
- format: document.getElementById('format').value,
426
- init_images: initImagesList // 发送数组
427
- };
428
-
429
- try {
430
- const response = await fetch('/api/generate', {
431
- method: 'POST',
432
- headers: { 'Content-Type': 'application/json' },
433
- body: JSON.stringify(payload)
434
- });
435
-
436
- const data = await response.json();
437
-
438
- if (data.status === 'success') {
439
- img.src = `data:image/${payload.format === 'jpg' ? 'jpeg' : 'png'};base64,${data.image_base64}`;
440
- img.style.display = 'block';
441
- downloadBtn.href = img.src;
442
- downloadBtn.download = `generated_image.${payload.format}`;
443
- downloadBtn.style.display = 'inline-block';
444
- downloadBtn.innerText = "下载图片";
445
- statusText.innerText = "";
446
- } else {
447
- statusText.innerText = "生成失败: " + data.message;
448
- alert("错误: " + data.message);
449
- }
450
- } catch (error) {
451
- console.error(error);
452
- statusText.innerText = "网络请求失败";
453
- alert("网络请求失败,请检查控制台");
454
- } finally {
455
- if (document.getElementById('agree_chk').checked) {
456
- btn.disabled = false;
457
- btn.innerText = "🚀 开始生成";
458
- } else {
459
- btn.innerText = "🚫 请先勾选免责声明";
460
- }
461
- loader.style.display = 'none';
462
- }
463
- }
464
- </script>
465
-
466
- </body>
467
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Imagen Generator</title>
7
+ <style>
8
+ :root {
9
+ --bg-color: #0b0f19;
10
+ --card-color: #1a1f2e;
11
+ --text-color: #e2e8f0;
12
+ --accent-color: #3b82f6;
13
+ --input-bg: #2d3748;
14
+ --danger-color: #ef4444;
15
+ --success-color: #10b981;
16
+ }
17
+ body {
18
+ font-family: 'Segoe UI', system-ui, sans-serif;
19
+ background-color: var(--bg-color);
20
+ color: var(--text-color);
21
+ margin: 0;
22
+ padding: 20px;
23
+ display: flex;
24
+ justify-content: center;
25
+ }
26
+ .container {
27
+ width: 100%;
28
+ max-width: 1000px;
29
+ display: grid;
30
+ grid-template-columns: 350px 1fr;
31
+ gap: 20px;
32
+ }
33
+ .card {
34
+ background-color: var(--card-color);
35
+ padding: 20px;
36
+ border-radius: 12px;
37
+ box-shadow: 0 4px 6px rgba(0,0,0,0.3);
38
+ }
39
+ h1 { margin-top: 0; font-size: 1.5rem; color: var(--accent-color); }
40
+ .form-group { margin-bottom: 15px; }
41
+ label { display: block; margin-bottom: 5px; font-size: 0.9rem; color: #a0aec0; }
42
+ input, select, textarea {
43
+ width: 100%;
44
+ padding: 10px;
45
+ background-color: var(--input-bg);
46
+ border: 1px solid #4a5568;
47
+ border-radius: 6px;
48
+ color: white;
49
+ box-sizing: border-box;
50
+ font-size: 0.95rem;
51
+ }
52
+ input:focus, select:focus, textarea:focus {
53
+ outline: none;
54
+ border-color: var(--accent-color);
55
+ }
56
+
57
+ /* --- 修正样式:支持多图预览 --- */
58
+ .file-upload-wrapper {
59
+ position: relative;
60
+ border: 2px dashed #4a5568;
61
+ border-radius: 6px;
62
+ padding: 20px;
63
+ text-align: center;
64
+ cursor: pointer;
65
+ transition: border-color 0.3s;
66
+ }
67
+ .file-upload-wrapper:hover {
68
+ border-color: var(--accent-color);
69
+ }
70
+ #init_image_input {
71
+ position: absolute;
72
+ top: 0; left: 0; width: 100%; height: 100%;
73
+ opacity: 0;
74
+ cursor: pointer;
75
+ }
76
+ .upload-placeholder { color: #a0aec0; pointer-events: none; }
77
+
78
+ .preview-container {
79
+ display: none;
80
+ margin-top: 10px;
81
+ position: relative;
82
+ flex-wrap: wrap;
83
+ gap: 8px;
84
+ }
85
+
86
+ /* 缩略图样式 */
87
+ .thumb-wrapper {
88
+ position: relative;
89
+ width: 80px;
90
+ height: 80px;
91
+ }
92
+ .thumb-img {
93
+ width: 100%;
94
+ height: 100%;
95
+ object-fit: cover;
96
+ border-radius: 6px;
97
+ border: 1px solid #4a5568;
98
+ }
99
+
100
+ .clear-preview-btn {
101
+ position: absolute;
102
+ top: -10px;
103
+ right: -10px;
104
+ background: var(--danger-color);
105
+ color: white;
106
+ border: none;
107
+ border-radius: 50%;
108
+ width: 24px;
109
+ height: 24px;
110
+ cursor: pointer;
111
+ font-weight: bold;
112
+ line-height: 24px;
113
+ text-align: center;
114
+ padding: 0;
115
+ z-index: 10;
116
+ }
117
+ /* --------------------------------- */
118
+
119
+ button {
120
+ width: 100%;
121
+ padding: 12px;
122
+ background-color: var(--accent-color);
123
+ color: white;
124
+ border: none;
125
+ border-radius: 6px;
126
+ font-size: 1rem;
127
+ cursor: pointer;
128
+ transition: all 0.3s;
129
+ font-weight: bold;
130
+ opacity: 1;
131
+ }
132
+ button:hover:not(:disabled) {
133
+ background-color: #2563eb;
134
+ transform: translateY(-1px);
135
+ }
136
+ button:disabled {
137
+ background-color: #4a5568;
138
+ cursor: not-allowed;
139
+ opacity: 0.6;
140
+ }
141
+
142
+ .result-area {
143
+ display: flex;
144
+ flex-direction: column;
145
+ align-items: center;
146
+ justify-content: center;
147
+ min-height: 400px;
148
+ border: 2px dashed #4a5568;
149
+ border-radius: 12px;
150
+ position: relative;
151
+ margin-top: 20px;
152
+ }
153
+ #result-img {
154
+ max-width: 100%;
155
+ max-height: 600px;
156
+ border-radius: 8px;
157
+ display: none;
158
+ box-shadow: 0 4px 15px rgba(0,0,0,0.5);
159
+ }
160
+ .loader {
161
+ border: 4px solid #f3f3f3;
162
+ border-top: 4px solid var(--accent-color);
163
+ border-radius: 50%;
164
+ width: 40px;
165
+ height: 40px;
166
+ animation: spin 1s linear infinite;
167
+ display: none;
168
+ }
169
+ .download-btn {
170
+ margin-top: 15px;
171
+ background-color: var(--success-color);
172
+ width: auto;
173
+ padding: 8px 20px;
174
+ display: none;
175
+ text-decoration: none;
176
+ color: white;
177
+ border-radius: 6px;
178
+ }
179
+ @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
180
+
181
+ .disclaimer-box {
182
+ margin-bottom: 15px;
183
+ padding: 12px;
184
+ background-color: rgba(239, 68, 68, 0.1);
185
+ border: 1px solid rgba(239, 68, 68, 0.3);
186
+ border-radius: 6px;
187
+ font-size: 0.85rem;
188
+ color: #cbd5e1;
189
+ line-height: 1.5;
190
+ }
191
+ .disclaimer-box strong { color: var(--danger-color); display: block; margin-bottom: 5px; }
192
+
193
+ .checkbox-wrapper {
194
+ display: flex;
195
+ align-items: center;
196
+ margin-bottom: 15px;
197
+ padding: 5px 0;
198
+ cursor: pointer;
199
+ }
200
+ .checkbox-wrapper input[type="checkbox"] {
201
+ width: 18px;
202
+ height: 18px;
203
+ margin-right: 10px;
204
+ cursor: pointer;
205
+ accent-color: var(--accent-color);
206
+ }
207
+ .checkbox-wrapper label {
208
+ display: inline;
209
+ margin: 0;
210
+ font-size: 0.95rem;
211
+ color: #e2e8f0;
212
+ cursor: pointer;
213
+ }
214
+
215
+ @media (max-width: 768px) {
216
+ .container { grid-template-columns: 1fr; }
217
+ }
218
+ </style>
219
+ </head>
220
+ <body>
221
+
222
+ <div class="container">
223
+ <div class="card">
224
+ <h1>Imagen Generator</h1>
225
+
226
+ <div class="form-group">
227
+ <label>API Key</label>
228
+ <input type="password" id="api_key" placeholder="sk-...">
229
+ </div>
230
+
231
+ <div class="form-group">
232
+ <label>模型名称</label>
233
+ <select id="model">
234
+ <option value="nano-banana">nano-banana(0.1)</option>
235
+ <option value="nano-banana-pro">nano-banana-pro(0.15)</option>
236
+ <option value="grok-imagine-1.0">grok-imagine-1.0(0.08)</option>
237
+ <option value="gemini-3-pro-image-preview">gemini-3-pro-image-preview(0.35)</option>
238
+ <option value="gemini-3.1-flash-image-preview">gemini-3.1-flash-image-preview(0.5)</option>
239
+ </select>
240
+ </div>
241
+
242
+ <div class="form-group">
243
+ <label>画面比例</label>
244
+ <select id="ratio">
245
+ <option value="16:9 (1080p/4K)">16:9 (1080p/4K 宽屏)</option>
246
+ <option value="1:1 (正方形)">1:1 (正方形)</option>
247
+ <option value="9:16 (手机壁纸)">9:16 (手机壁纸)</option>
248
+ <option value="4:3 (标准照片)">4:3 (标准照片)</option>
249
+ <option value="3:4 (竖向照片)">3:4 (竖向照片)</option>
250
+ <option value="21:9 (电影感)">21:9 (电影感)</option>
251
+ <option value="2:3 (艺术照)">2:3 (艺术照)</option>
252
+ </select>
253
+ </div>
254
+
255
+ <div class="form-group">
256
+ <label>清晰度等级</label>
257
+ <select id="scale">
258
+ <option value="1k">1k (标准)</option>
259
+ <option value="2k">2k (高清)</option>
260
+ <option value="4k">4k (超清 Pro)</option>
261
+ </select>
262
+ </div>
263
+
264
+ <div class="form-group">
265
+ <label>输出格式</label>
266
+ <select id="format">
267
+ <option value="png">PNG</option>
268
+ <option value="jpg">JPG</option>
269
+ </select>
270
+ </div>
271
+ </div>
272
+
273
+ <div class="card">
274
+ <div class="form-group">
275
+ <label>提示词 (Prompt)</label>
276
+ <textarea id="prompt" rows="4" placeholder="描述你想要的画面..."></textarea>
277
+ </div>
278
+
279
+ <div class="form-group">
280
+ <label>参考图 (支持多选,Chat模型可理解多图)</label>
281
+ <div class="file-upload-wrapper" id="upload-box">
282
+ <span class="upload-placeholder" id="upload-text">点击或拖拽上传图片 (支持多选)</span>
283
+ <!-- 增加了 multiple 属性 -->
284
+ <input type="file" id="init_image_input" accept="image/jpeg, image/png" multiple>
285
+ </div>
286
+ <div class="preview-container" id="preview-container">
287
+ <button class="clear-preview-btn" onclick="clearImagePreview()">×</button>
288
+ <!-- 动态插入缩略图 -->
289
+ </div>
290
+ </div>
291
+ <div class="disclaimer-box">
292
+ <strong>⚠️ 免责声明 (Disclaimer)</strong>
293
+ 本工具仅供个人学习与技术研究使用。严禁生成色情、暴力、政治敏感等违法内容。用户生成的任何内容纯属个人行为,法律后果由用户自行承担。
294
+ </div>
295
+
296
+ <div class="checkbox-wrapper">
297
+ <input type="checkbox" id="agree_chk" onchange="toggleSubmitButton()">
298
+ <label for="agree_chk">我已知晓并承诺合规使用</label>
299
+ </div>
300
+
301
+ <button onclick="generateImage()" id="gen-btn" disabled>🚫 请先勾选免责声明</button>
302
+
303
+ <div class="result-area" id="result-area">
304
+ <div class="loader" id="loader"></div>
305
+ <img id="result-img" alt="Generated Image" />
306
+ <a id="download-link" class="download-btn" href="#" download="image.png">下载图片</a>
307
+ <p id="status-text" style="color: #a0aec0; margin-top: 10px;">等待生成...</p>
308
+ </div>
309
+ </div>
310
+ </div>
311
+
312
+ <script>
313
+ let initImagesList = []; // 改为数组存储多张图片
314
+
315
+ // 处理图片上传
316
+ const fileInput = document.getElementById('init_image_input');
317
+ const previewContainer = document.getElementById('preview-container');
318
+ const uploadBox = document.getElementById('upload-box');
319
+ const uploadText = document.getElementById('upload-text');
320
+
321
+ fileInput.addEventListener('change', async function(e) {
322
+ const files = Array.from(e.target.files);
323
+ if (!files.length) return;
324
+
325
+ // 清空旧数据(或者你可以选择追加,这里选择覆盖逻辑)
326
+ initImagesList = [];
327
+ // 移除除了清除按钮外的所有子元素
328
+ while (previewContainer.children.length > 1) {
329
+ previewContainer.removeChild(previewContainer.lastChild);
330
+ }
331
+
332
+ const readPromises = files.map(file => {
333
+ return new Promise((resolve) => {
334
+ if (file.size > 10 * 1024 * 1024) {
335
+ console.warn(`文件 ${file.name} 太大,已跳过`);
336
+ resolve(null);
337
+ return;
338
+ }
339
+ const reader = new FileReader();
340
+ reader.onload = function(event) {
341
+ resolve({
342
+ name: file.name,
343
+ data: event.target.result
344
+ });
345
+ };
346
+ reader.readAsDataURL(file);
347
+ });
348
+ });
349
+
350
+ const results = await Promise.all(readPromises);
351
+
352
+ results.forEach(res => {
353
+ if (res) {
354
+ initImagesList.push(res.data);
355
+
356
+ // 创建缩略图元素
357
+ const div = document.createElement('div');
358
+ div.className = 'thumb-wrapper';
359
+ const img = document.createElement('img');
360
+ img.className = 'thumb-img';
361
+ img.src = res.data;
362
+ div.appendChild(img);
363
+ previewContainer.appendChild(div);
364
+ }
365
+ });
366
+
367
+ if (initImagesList.length > 0) {
368
+ previewContainer.style.display = 'flex';
369
+ uploadBox.style.display = 'none';
370
+ }
371
+ });
372
+
373
+ function clearImagePreview() {
374
+ fileInput.value = '';
375
+ initImagesList = [];
376
+ // 清空预览DOM
377
+ while (previewContainer.children.length > 1) {
378
+ previewContainer.removeChild(previewContainer.lastChild);
379
+ }
380
+ previewContainer.style.display = 'none';
381
+ uploadBox.style.display = 'block';
382
+ }
383
+
384
+ function toggleSubmitButton() {
385
+ const checkbox = document.getElementById('agree_chk');
386
+ const btn = document.getElementById('gen-btn');
387
+ if (checkbox.checked) {
388
+ btn.disabled = false;
389
+ btn.innerText = "🚀 开始生成";
390
+ } else {
391
+ btn.disabled = true;
392
+ btn.innerText = "🚫 请先勾选免责声明";
393
+ }
394
+ }
395
+
396
+ async function generateImage() {
397
+ const apiKey = document.getElementById('api_key').value;
398
+ const prompt = document.getElementById('prompt').value;
399
+ const checkbox = document.getElementById('agree_chk');
400
+
401
+ if (!checkbox.checked) { alert("请先勾选免责声明!"); return; }
402
+ if (!apiKey) { alert("请输入 API Key"); return; }
403
+ if (!prompt) { alert("请输入提示词"); return; }
404
+
405
+ const btn = document.getElementById('gen-btn');
406
+ const loader = document.getElementById('loader');
407
+ const img = document.getElementById('result-img');
408
+ const downloadBtn = document.getElementById('download-link');
409
+ const statusText = document.getElementById('status-text');
410
+
411
+ btn.disabled = true;
412
+ btn.innerText = "生成中...";
413
+ loader.style.display = 'block';
414
+ img.style.display = 'none';
415
+ downloadBtn.style.display = 'none';
416
+ statusText.innerText = "正在请求 API...";
417
+
418
+ const payload = {
419
+ api_key: apiKey,
420
+ model: document.getElementById('model').value,
421
+ prompt: prompt,
422
+ ratio: document.getElementById('ratio').value,
423
+ scale: document.getElementById('scale').value,
424
+ format: document.getElementById('format').value,
425
+ init_images: initImagesList // 发送数组
426
+ };
427
+
428
+ try {
429
+ const response = await fetch('/api/generate', {
430
+ method: 'POST',
431
+ headers: { 'Content-Type': 'application/json' },
432
+ body: JSON.stringify(payload)
433
+ });
434
+
435
+ const data = await response.json();
436
+
437
+ if (data.status === 'success') {
438
+ img.src = `data:image/${payload.format === 'jpg' ? 'jpeg' : 'png'};base64,${data.image_base64}`;
439
+ img.style.display = 'block';
440
+ downloadBtn.href = img.src;
441
+ downloadBtn.download = `generated_image.${payload.format}`;
442
+ downloadBtn.style.display = 'inline-block';
443
+ downloadBtn.innerText = "下载图片";
444
+ statusText.innerText = "";
445
+ } else {
446
+ statusText.innerText = "生成失败: " + data.message;
447
+ alert("错误: " + data.message);
448
+ }
449
+ } catch (error) {
450
+ console.error(error);
451
+ statusText.innerText = "网络请求失败";
452
+ alert("网络请求失败,请检查控制台");
453
+ } finally {
454
+ if (document.getElementById('agree_chk').checked) {
455
+ btn.disabled = false;
456
+ btn.innerText = "🚀 开始生成";
457
+ } else {
458
+ btn.innerText = "🚫 请先勾选免责声明";
459
+ }
460
+ loader.style.display = 'none';
461
+ }
462
+ }
463
+ </script>
464
+
465
+ </body>
 
466
  </html>