yaoqifa commited on
Commit
f2d2aa6
·
verified ·
1 Parent(s): c10de4e

Upload index.html

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