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

Upload index.html

Browse files
Files changed (1) hide show
  1. static/index.html +276 -127
static/index.html CHANGED
@@ -3,152 +3,301 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Imagen Multi-Image</title>
7
  <style>
8
- :root { --bg: #0b0f19; --card: #1a1f2e; --text: #e2e8f0; --accent: #3b82f6; --input: #2d3748; }
9
- body { font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); padding: 20px; margin: 0; display: flex; justify-content: center; }
10
- .container { width: 100%; max-width: 1000px; display: grid; grid-template-columns: 350px 1fr; gap: 20px; }
11
- .card { background: var(--card); padding: 20px; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.3); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  .form-group { margin-bottom: 15px; }
13
- label { display: block; margin-bottom: 5px; font-size: 0.85rem; color: #a0aec0; }
14
- input, select, textarea { width: 100%; padding: 10px; background: var(--input); border: 1px solid #4a5568; border-radius: 6px; color: white; box-sizing: border-box; }
 
 
 
 
 
 
 
 
 
 
15
 
16
- /* 多图上传样式 */
17
- .upload-box { border: 2px dashed #4a5568; border-radius: 6px; padding: 20px; text-align: center; cursor: pointer; position: relative; }
18
- .upload-box:hover { border-color: var(--accent); }
 
 
 
 
 
 
 
 
19
  #init_image_input { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
20
- #preview-container { display: none; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
21
- .thumb-box { position: relative; width: 60px; height: 60px; }
22
- .thumb-box img { width: 100%; height: 100%; object-fit: cover; border-radius: 4px; border: 1px solid #4a5568; }
23
-
24
- button { width: 100%; padding: 12px; background: var(--accent); color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; }
25
- button:disabled { background: #4a5568; cursor: not-allowed; }
26
- .result-area { margin-top: 20px; border: 2px dashed #4a5568; border-radius: 12px; min-height: 300px; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; }
27
- #result-img { max-width: 100%; display: none; }
28
- .loader { border: 4px solid #f3f3f3; border-top: 4px solid var(--accent); border-radius: 50%; width: 30px; height: 30px; animation: spin 1s linear infinite; display: none; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
 
 
 
 
 
 
 
30
  @media (max-width: 768px) { .container { grid-template-columns: 1fr; } }
31
  </style>
32
  </head>
33
  <body>
34
- <div class="container">
35
- <div class="card">
36
- <h3>设置</h3>
37
- <div class="form-group"><label>API Key</label><input type="password" id="api_key"></div>
38
- <div class="form-group">
39
- <label>模型</label>
40
- <select id="model">
41
- <option value="gemini-3-pro-image">gemini-3-pro-image</option>
42
- <option value="grok-imagine-1.0">grok-imagine-1.0</option>
43
- <option value="nano-banana">nano-banana (单图)</option>
44
- </select>
45
- </div>
46
- <div class="form-group">
47
- <label>比例</label>
48
- <select id="ratio">
49
- <option value="1:1">1:1</option>
50
- <option value="16:9">16:9</option>
51
- <option value="9:16">9:16</option>
52
- </select>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  </div>
54
- <div class="form-group">
55
- <label>清晰度</label>
56
- <select id="scale"><option value="1k">1k</option><option value="2k">2k</option><option value="4k">4k</option></select>
57
- </div>
58
- </div>
59
 
60
- <div class="card">
61
- <div class="form-group"><label>提示词</label><textarea id="prompt" rows="3"></textarea></div>
62
- <div class="form-group">
63
- <label>参考图 (可多选)</label>
64
- <div class="upload-box">
65
- <span style="color:#a0aec0">点击��传多张图片</span>
66
- <input type="file" id="init_image_input" accept="image/*" multiple> </div>
67
- <div id="preview-container"></div> <button id="clear-btn" style="display:none; margin-top:8px; background:#ef4444; padding:5px; font-size:12px">清空</button>
68
- </div>
69
-
70
- <button onclick="generateImage()" id="gen-btn">🚀 开始生成</button>
71
 
72
- <div class="result-area">
73
- <div class="loader" id="loader"></div>
74
- <img id="result-img">
75
- <p id="status-text" style="color:#a0aec0; font-size:14px">等待指令...</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  </div>
77
  </div>
78
- </div>
79
-
80
- <script>
81
- let imagesBase64 = []; // 存储多图数组
82
-
83
- document.getElementById('init_image_input').addEventListener('change', async function(e) {
84
- const files = Array.from(e.target.files);
85
- const container = document.getElementById('preview-container');
86
- for (const file of files) {
87
- const reader = new FileReader();
88
- reader.onload = (ev) => {
89
- imagesBase64.push(ev.target.result); //
 
 
 
 
 
 
 
 
90
  const div = document.createElement('div');
91
- div.className = 'thumb-box';
92
- div.innerHTML = `<img src="${ev.target.result}">`;
93
- container.appendChild(div);
94
- };
95
- reader.readAsDataURL(file);
 
 
 
 
 
 
 
 
 
 
 
96
  }
97
- container.style.display = 'flex';
98
- document.getElementById('clear-btn').style.display = 'block';
99
- });
100
-
101
- document.getElementById('clear-btn').onclick = () => {
102
- imagesBase64 = [];
103
- document.getElementById('preview-container').innerHTML = '';
104
- document.getElementById('preview-container').style.display = 'none';
105
- document.getElementById('clear-btn').style.display = 'none';
106
- document.getElementById('init_image_input').value = '';
107
- };
108
-
109
- async function generateImage() {
110
- const btn = document.getElementById('gen-btn');
111
- const loader = document.getElementById('loader');
112
- const img = document.getElementById('result-img');
113
- const status = document.getElementById('status-text');
114
-
115
- btn.disabled = true;
116
- loader.style.display = 'block';
117
- img.style.display = 'none';
118
- status.innerText = "生成中...";
119
-
120
- const payload = {
121
- api_key: document.getElementById('api_key').value,
122
- model: document.getElementById('model').value,
123
- prompt: document.getElementById('prompt').value,
124
- ratio: document.getElementById('ratio').value,
125
- scale: document.getElementById('scale').value,
126
- format: 'png',
127
- init_images: imagesBase64 // 发送数组
128
  };
129
 
130
- try {
131
- const res = await fetch('/api/generate', {
132
- method: 'POST',
133
- headers: { 'Content-Type': 'application/json' },
134
- body: JSON.stringify(payload)
135
- });
136
- const data = await res.json();
137
- if (data.status === 'success') {
138
- img.src = "data:image/png;base64," + data.image_base64;
139
- img.style.display = 'block';
140
- status.innerText = "生成成功";
141
- } else {
142
- alert("失败: " + data.message);
143
- status.innerText = "生成失败";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  }
145
- } catch (e) {
146
- alert("网络错误");
147
- } finally {
148
- btn.disabled = false;
149
- loader.style.display = 'none';
150
  }
151
- }
152
- </script>
 
153
  </body>
154
  </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;
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 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%;
83
+ padding: 12px;
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>