yaoqifa commited on
Commit
ab2b652
·
verified ·
1 Parent(s): d081f14

Upload index.html

Browse files
Files changed (1) hide show
  1. static/index.html +346 -182
static/index.html CHANGED
@@ -3,7 +3,7 @@
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;
@@ -34,49 +34,87 @@
34
  background-color: var(--card-color);
35
  padding: 20px;
36
  border-radius: 12px;
37
- box-shadow: 0 10px 25px rgba(0,0,0,0.3);
38
- height: fit-content;
39
  }
 
40
  .form-group { margin-bottom: 15px; }
41
- label { display: block; margin-bottom: 8px; font-size: 0.9rem; font-weight: 500; 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: 8px;
48
  color: white;
49
- font-size: 0.95rem;
50
  box-sizing: border-box;
 
 
 
 
 
51
  }
52
- textarea { resize: vertical; min-height: 80px; }
53
 
54
- /* 多图预览样式 */
55
  .file-upload-wrapper {
56
  position: relative;
57
  border: 2px dashed #4a5568;
58
- border-radius: 8px;
59
  padding: 20px;
60
  text-align: center;
61
  cursor: pointer;
62
- transition: all 0.3s;
 
 
 
63
  }
64
- .file-upload-wrapper:hover { border-color: var(--accent-color); background: #242c3d; }
65
- #init_image_input { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
66
- .preview-grid {
 
 
 
 
 
 
67
  display: none;
68
- grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
69
- gap: 10px;
70
  margin-top: 10px;
 
 
 
71
  }
72
- .preview-item {
73
- width: 60px; height: 60px;
74
- border-radius: 4px;
75
- overflow: hidden;
76
- border: 1px solid #4a5568;
77
  position: relative;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  }
79
- .preview-item img { width: 100%; height: 100%; object-fit: cover; }
80
 
81
  button {
82
  width: 100%;
@@ -84,220 +122,346 @@
84
  background-color: var(--accent-color);
85
  color: white;
86
  border: none;
87
- border-radius: 8px;
88
- font-weight: 600;
89
  cursor: pointer;
90
- transition: opacity 0.2s;
 
 
91
  }
92
- button:disabled { background-color: #4a5568; cursor: not-allowed; }
 
 
 
 
 
 
 
 
 
93
  .result-area {
94
- background-color: var(--card-color);
95
- border-radius: 12px;
96
  display: flex;
97
  flex-direction: column;
98
  align-items: center;
99
  justify-content: center;
100
- min-height: 500px;
101
- border: 2px dashed #2d3748;
 
102
  position: relative;
 
 
 
 
 
 
 
 
103
  }
104
- #result-img { max-width: 100%; max-height: 700px; border-radius: 8px; display: none; }
105
  .loader {
106
  border: 4px solid #f3f3f3;
107
  border-top: 4px solid var(--accent-color);
108
  border-radius: 50%;
109
- width: 40px; height: 40px;
 
110
  animation: spin 1s linear infinite;
111
  display: none;
112
  }
113
- @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
114
  .download-btn {
115
  margin-top: 15px;
116
  background-color: var(--success-color);
 
 
117
  display: none;
118
  text-decoration: none;
119
- text-align: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  }
121
- @media (max-width: 768px) { .container { grid-template-columns: 1fr; } }
122
  </style>
123
  </head>
124
  <body>
125
- <div class="container">
126
- <div class="card">
127
- <h2 style="margin-top:0; font-size:1.2rem; color:white">参数配置</h2>
128
- <div class="form-group">
129
- <label>API Key</label>
130
- <input type="password" id="api_key" placeholder="输入 API Key">
131
- </div>
132
- <div class="form-group">
133
- <label>生成模型</label>
134
- <select id="model">
135
- <option value="gemini-exp-1206">Gemini Exp 1206 (支持多图)</option>
136
- <option value="gemini-2.0-flash-exp">Gemini 2.0 Flash (支持多图)</option>
137
- <option value="grok-2-vision-1212">Grok 2 Vision (支持多图)</option>
138
- <option value="nano-banana">Nano Banana (单图)</option>
139
- </select>
140
- </div>
141
- <div class="form-group">
142
- <label>画布比例</label>
143
- <select id="ratio">
144
- <option value="1:1">1:1 Square</option>
145
- <option value="16:9">16:9 Cinematic</option>
146
- <option value="9:16">9:16 Portrait</option>
147
- </select>
148
- </div>
149
- <div class="form-group">
150
- <label>分辨率级别</label>
151
- <select id="scale">
152
- <option value="1k">1K (Standard)</option>
153
- <option value="2k">2K (HD)</option>
154
- <option value="4k">4K (Ultra)</option>
155
- </select>
156
- </div>
157
- <div class="form-group">
158
- <label>输出格式</label>
159
- <select id="format">
160
- <option value="webp">WebP (推荐)</option>
161
- <option value="png">PNG (无损)</option>
162
- <option value="jpg">JPG (兼容)</option>
163
- </select>
164
- </div>
165
- <hr style="border:0.5px solid #2d3748; margin: 20px 0;">
166
- <div style="font-size: 0.8rem; color: #718096;">
167
- <label style="display:flex; align-items:center; gap:8px; cursor:pointer;">
168
- <input type="checkbox" id="agree_chk" style="width:auto"> 我已阅读并同意免责声明
169
- </label>
170
- </div>
171
  </div>
172
 
173
- <div class="card">
174
- <div class="form-group">
175
- <label>提示词 (Prompt)</label>
176
- <textarea id="prompt" placeholder="描述你想要生成的画面内容..."></textarea>
177
- </div>
 
 
 
 
 
 
178
 
179
- <div class="form-group">
180
- <label>参考图片 (支持多张)</label>
181
- <div class="file-upload-wrapper">
182
- <span id="upload-hint">点击或拖拽上传图片 (多选)</span>
183
- <input type="file" id="init_image_input" accept="image/*" multiple>
184
- </div>
185
- <div class="preview-grid" id="preview-grid"></div>
186
- <button id="clear-imgs" style="display:none; margin-top:10px; background:#4a5568; padding:5px; font-size:0.8rem">清空全部图片</button>
187
- </div>
 
 
 
188
 
189
- <button id="gen-btn" disabled>🚀 开始生成</button>
 
 
 
 
 
 
 
190
 
191
- <div class="result-area">
192
- <div class="loader" id="loader"></div>
193
- <img id="result-img" alt="生成的图片">
194
- <div id="status-text" style="color:#718096; margin-top:10px">等待输入指令...</div>
195
- <a id="download-btn" class="download-btn">下载图片</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  </div>
198
  </div>
 
199
 
200
- <script>
201
- let initImagesArray = []; // 存储多图 Base64
202
 
203
- // 免责声明逻辑
204
- document.getElementById('agree_chk').addEventListener('change', function(e) {
205
- document.getElementById('gen-btn').disabled = !e.target.checked;
206
- });
 
207
 
208
- // 多图上传处理
209
- const fileInput = document.getElementById('init_image_input');
210
- const previewGrid = document.getElementById('preview-grid');
211
- const clearBtn = document.getElementById('clear-imgs');
212
 
213
- fileInput.addEventListener('change', async function(e) {
214
- const files = Array.from(e.target.files);
215
- for (const file of files) {
216
- const base64 = await readFile(file);
217
- initImagesArray.push(base64);
218
-
219
- const div = document.createElement('div');
220
- div.className = 'preview-item';
221
- div.innerHTML = `<img src="${base64}">`;
222
- previewGrid.appendChild(div);
223
- }
224
- if (initImagesArray.length > 0) {
225
- previewGrid.style.display = 'grid';
226
- clearBtn.style.display = 'block';
227
- }
228
- });
229
 
230
- function readFile(file) {
231
  return new Promise((resolve) => {
 
 
 
 
 
232
  const reader = new FileReader();
233
- reader.onload = (e) => resolve(e.target.result);
 
 
 
 
 
234
  reader.readAsDataURL(file);
235
  });
236
- }
237
 
238
- clearBtn.onclick = () => {
239
- initImagesArray = [];
240
- previewGrid.innerHTML = '';
241
- previewGrid.style.display = 'none';
242
- clearBtn.style.display = 'none';
243
- fileInput.value = '';
244
- };
 
 
 
 
 
 
 
 
 
245
 
246
- // 生成逻辑
247
- async function generateImage() {
248
- const btn = document.getElementById('gen-btn');
249
- const loader = document.getElementById('loader');
250
- const img = document.getElementById('result-img');
251
- const statusText = document.getElementById('status-text');
252
- const downloadBtn = document.getElementById('download-btn');
253
 
254
- const apiKey = document.getElementById('api_key').value;
255
- if (!apiKey) return alert("请输入 API Key");
 
 
 
 
 
 
 
 
256
 
 
 
 
 
 
 
 
257
  btn.disabled = true;
258
- btn.innerText = "⏳ 正在生成...";
259
- loader.style.display = 'block';
260
- img.style.display = 'none';
261
- downloadBtn.style.display = 'none';
262
- statusText.innerText = "连接服务器中...";
263
 
264
- const payload = {
265
- api_key: apiKey,
266
- model: document.getElementById('model').value,
267
- prompt: document.getElementById('prompt').value,
268
- ratio: document.getElementById('ratio').value,
269
- scale: document.getElementById('scale').value,
270
- format: document.getElementById('format').value,
271
- init_images: initImagesArray // 发送列表
272
- };
273
 
274
- try {
275
- const response = await fetch('/api/generate', {
276
- method: 'POST',
277
- headers: { 'Content-Type': 'application/json' },
278
- body: JSON.stringify(payload)
279
- });
280
- const data = await response.json();
281
- if (data.status === 'success') {
282
- img.src = `data:image/png;base64,${data.image_base64}`;
283
- img.style.display = 'block';
284
- downloadBtn.href = img.src;
285
- downloadBtn.download = `imagen_${Date.now()}.png`;
286
- downloadBtn.style.display = 'block';
287
- statusText.innerText = "生成成功!";
288
- } else {
289
- statusText.innerText = "错误: " + data.message;
290
- }
291
- } catch (error) {
292
- statusText.innerText = "网络连接失败";
293
- } finally {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  btn.disabled = false;
295
  btn.innerText = "🚀 开始生成";
296
- loader.style.display = 'none';
 
297
  }
 
298
  }
 
 
299
 
300
- document.getElementById('gen-btn').onclick = generateImage;
301
- </script>
302
  </body>
303
  </html>
 
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;
 
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%;
 
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>