Upload index.html
Browse files- static/index.html +76 -342
static/index.html
CHANGED
|
@@ -3,418 +3,152 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Imagen
|
| 7 |
<style>
|
| 8 |
-
:root {
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 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.
|
| 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 |
-
.
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 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 |
-
width: fit-content;
|
| 83 |
-
}
|
| 84 |
-
#preview-img {
|
| 85 |
-
max-width: 100%;
|
| 86 |
-
max-height: 200px;
|
| 87 |
-
border-radius: 6px;
|
| 88 |
-
border: 1px solid #4a5568;
|
| 89 |
-
}
|
| 90 |
-
.clear-preview-btn {
|
| 91 |
-
position: absolute;
|
| 92 |
-
top: -10px;
|
| 93 |
-
right: -10px;
|
| 94 |
-
background: var(--danger-color);
|
| 95 |
-
color: white;
|
| 96 |
-
border: none;
|
| 97 |
-
border-radius: 50%;
|
| 98 |
-
width: 24px;
|
| 99 |
-
height: 24px;
|
| 100 |
-
cursor: pointer;
|
| 101 |
-
font-weight: bold;
|
| 102 |
-
line-height: 24px;
|
| 103 |
-
text-align: center;
|
| 104 |
-
padding: 0;
|
| 105 |
-
}
|
| 106 |
-
/* --------------------------------- */
|
| 107 |
-
|
| 108 |
-
button {
|
| 109 |
-
width: 100%;
|
| 110 |
-
padding: 12px;
|
| 111 |
-
background-color: var(--accent-color);
|
| 112 |
-
color: white;
|
| 113 |
-
border: none;
|
| 114 |
-
border-radius: 6px;
|
| 115 |
-
font-size: 1rem;
|
| 116 |
-
cursor: pointer;
|
| 117 |
-
transition: all 0.3s;
|
| 118 |
-
font-weight: bold;
|
| 119 |
-
opacity: 1;
|
| 120 |
-
}
|
| 121 |
-
button:hover:not(:disabled) {
|
| 122 |
-
background-color: #2563eb;
|
| 123 |
-
transform: translateY(-1px);
|
| 124 |
-
}
|
| 125 |
-
button:disabled {
|
| 126 |
-
background-color: #4a5568;
|
| 127 |
-
cursor: not-allowed;
|
| 128 |
-
opacity: 0.6;
|
| 129 |
-
}
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
min-height: 400px;
|
| 137 |
-
border: 2px dashed #4a5568;
|
| 138 |
-
border-radius: 12px;
|
| 139 |
-
position: relative;
|
| 140 |
-
margin-top: 20px;
|
| 141 |
-
}
|
| 142 |
-
#result-img {
|
| 143 |
-
max-width: 100%;
|
| 144 |
-
max-height: 600px;
|
| 145 |
-
border-radius: 8px;
|
| 146 |
-
display: none;
|
| 147 |
-
box-shadow: 0 4px 15px rgba(0,0,0,0.5);
|
| 148 |
-
}
|
| 149 |
-
.loader {
|
| 150 |
-
border: 4px solid #f3f3f3;
|
| 151 |
-
border-top: 4px solid var(--accent-color);
|
| 152 |
-
border-radius: 50%;
|
| 153 |
-
width: 40px;
|
| 154 |
-
height: 40px;
|
| 155 |
-
animation: spin 1s linear infinite;
|
| 156 |
-
display: none;
|
| 157 |
-
}
|
| 158 |
-
.download-btn {
|
| 159 |
-
margin-top: 15px;
|
| 160 |
-
background-color: var(--success-color);
|
| 161 |
-
width: auto;
|
| 162 |
-
padding: 8px 20px;
|
| 163 |
-
display: none;
|
| 164 |
-
text-decoration: none;
|
| 165 |
-
color: white;
|
| 166 |
-
border-radius: 6px;
|
| 167 |
-
}
|
| 168 |
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
|
| 169 |
-
|
| 170 |
-
.disclaimer-box {
|
| 171 |
-
margin-bottom: 15px;
|
| 172 |
-
padding: 12px;
|
| 173 |
-
background-color: rgba(239, 68, 68, 0.1);
|
| 174 |
-
border: 1px solid rgba(239, 68, 68, 0.3);
|
| 175 |
-
border-radius: 6px;
|
| 176 |
-
font-size: 0.85rem;
|
| 177 |
-
color: #cbd5e1;
|
| 178 |
-
line-height: 1.5;
|
| 179 |
-
}
|
| 180 |
-
.disclaimer-box strong { color: var(--danger-color); display: block; margin-bottom: 5px; }
|
| 181 |
-
|
| 182 |
-
.checkbox-wrapper {
|
| 183 |
-
display: flex;
|
| 184 |
-
align-items: center;
|
| 185 |
-
margin-bottom: 15px;
|
| 186 |
-
padding: 5px 0;
|
| 187 |
-
cursor: pointer;
|
| 188 |
-
}
|
| 189 |
-
.checkbox-wrapper input[type="checkbox"] {
|
| 190 |
-
width: 18px;
|
| 191 |
-
height: 18px;
|
| 192 |
-
margin-right: 10px;
|
| 193 |
-
cursor: pointer;
|
| 194 |
-
accent-color: var(--accent-color);
|
| 195 |
-
}
|
| 196 |
-
.checkbox-wrapper label {
|
| 197 |
-
display: inline;
|
| 198 |
-
margin: 0;
|
| 199 |
-
font-size: 0.95rem;
|
| 200 |
-
color: #e2e8f0;
|
| 201 |
-
cursor: pointer;
|
| 202 |
-
}
|
| 203 |
-
|
| 204 |
-
@media (max-width: 768px) {
|
| 205 |
-
.container { grid-template-columns: 1fr; }
|
| 206 |
-
}
|
| 207 |
</style>
|
| 208 |
</head>
|
| 209 |
<body>
|
| 210 |
-
|
| 211 |
<div class="container">
|
| 212 |
<div class="card">
|
| 213 |
-
<
|
| 214 |
-
|
| 215 |
<div class="form-group">
|
| 216 |
-
<label>
|
| 217 |
-
<input type="password" id="api_key" placeholder="sk-...">
|
| 218 |
-
</div>
|
| 219 |
-
|
| 220 |
-
<div class="form-group">
|
| 221 |
-
<label>模型名称</label>
|
| 222 |
<select id="model">
|
| 223 |
-
<option value="nano-banana">nano-banana</option>
|
| 224 |
-
<option value="nano-banana-pro">nano-banana-pro</option>
|
| 225 |
-
<option value="grok-imagine-1.0">grok-imagine-1.0</option>
|
| 226 |
-
<option value="gemini-2.5-flash-image">gemini-2.5-flash-image</option>
|
| 227 |
<option value="gemini-3-pro-image">gemini-3-pro-image</option>
|
| 228 |
-
<option value="
|
|
|
|
| 229 |
</select>
|
| 230 |
</div>
|
| 231 |
-
|
| 232 |
<div class="form-group">
|
| 233 |
-
<label>
|
| 234 |
<select id="ratio">
|
| 235 |
-
<option value="
|
| 236 |
-
<option value="
|
| 237 |
-
<option value="9:16
|
| 238 |
-
<option value="4:3 (标准照片)">4:3 (标准照片)</option>
|
| 239 |
-
<option value="3:4 (竖向照片)">3:4 (竖向照片)</option>
|
| 240 |
-
<option value="21:9 (电影感)">21:9 (电影感)</option>
|
| 241 |
-
<option value="2:3 (艺术照)">2:3 (艺术照)</option>
|
| 242 |
-
</select>
|
| 243 |
-
</div>
|
| 244 |
-
|
| 245 |
-
<div class="form-group">
|
| 246 |
-
<label>清晰度等级</label>
|
| 247 |
-
<select id="scale">
|
| 248 |
-
<option value="1k">1k (标准)</option>
|
| 249 |
-
<option value="2k">2k (高清)</option>
|
| 250 |
-
<option value="4k">4k (超清 Pro)</option>
|
| 251 |
</select>
|
| 252 |
</div>
|
| 253 |
-
|
| 254 |
<div class="form-group">
|
| 255 |
-
<label>
|
| 256 |
-
<select id="
|
| 257 |
-
<option value="png">PNG</option>
|
| 258 |
-
<option value="jpg">JPG</option>
|
| 259 |
-
</select>
|
| 260 |
</div>
|
| 261 |
</div>
|
| 262 |
|
| 263 |
<div class="card">
|
|
|
|
| 264 |
<div class="form-group">
|
| 265 |
-
<label>
|
| 266 |
-
<
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
<label>参考图 (图生图,可选)</label>
|
| 271 |
-
<div class="file-upload-wrapper" id="upload-box">
|
| 272 |
-
<span class="upload-placeholder">点击或拖拽上传图片 (支持 JPG/PNG)</span>
|
| 273 |
-
<input type="file" id="init_image_input" accept="image/jpeg, image/png">
|
| 274 |
-
</div>
|
| 275 |
-
<div class="preview-container" id="preview-container">
|
| 276 |
-
<img id="preview-img" alt="Preview">
|
| 277 |
-
<button class="clear-preview-btn" onclick="clearImagePreview()">×</button>
|
| 278 |
-
</div>
|
| 279 |
-
</div>
|
| 280 |
-
<div class="disclaimer-box">
|
| 281 |
-
<strong>⚠️ 免责声明 (Disclaimer)</strong>
|
| 282 |
-
本工具仅供个人学习与技术研究使用。严禁生成色情、暴力、政治敏感等违法内容。用户生成的任何内容纯属个人行为,法律后果由用户自行承担。
|
| 283 |
-
</div>
|
| 284 |
-
|
| 285 |
-
<div class="checkbox-wrapper">
|
| 286 |
-
<input type="checkbox" id="agree_chk" onchange="toggleSubmitButton()">
|
| 287 |
-
<label for="agree_chk">我已知晓并承诺合规使用</label>
|
| 288 |
</div>
|
| 289 |
|
| 290 |
-
<button onclick="generateImage()" id="gen-btn"
|
| 291 |
|
| 292 |
-
<div class="result-area"
|
| 293 |
<div class="loader" id="loader"></div>
|
| 294 |
-
<img id="result-img"
|
| 295 |
-
<
|
| 296 |
-
<p id="status-text" style="color: #a0aec0; margin-top: 10px;">等待生成...</p>
|
| 297 |
</div>
|
| 298 |
</div>
|
| 299 |
</div>
|
| 300 |
|
| 301 |
<script>
|
| 302 |
-
let
|
| 303 |
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
const uploadBox = document.getElementById('upload-box');
|
| 309 |
-
|
| 310 |
-
fileInput.addEventListener('change', function(e) {
|
| 311 |
-
const file = e.target.files[0];
|
| 312 |
-
if (file) {
|
| 313 |
-
if (file.size > 10 * 1024 * 1024) { // 稍微放宽前端限制,后端会压缩
|
| 314 |
-
alert("图片太大,请上传小于 10MB 的图片");
|
| 315 |
-
this.value = '';
|
| 316 |
-
return;
|
| 317 |
-
}
|
| 318 |
-
|
| 319 |
const reader = new FileReader();
|
| 320 |
-
reader.onload =
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
|
|
|
| 325 |
};
|
| 326 |
reader.readAsDataURL(file);
|
| 327 |
}
|
|
|
|
|
|
|
| 328 |
});
|
| 329 |
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
}
|
| 337 |
-
|
| 338 |
-
function toggleSubmitButton() {
|
| 339 |
-
const checkbox = document.getElementById('agree_chk');
|
| 340 |
-
const btn = document.getElementById('gen-btn');
|
| 341 |
-
if (checkbox.checked) {
|
| 342 |
-
btn.disabled = false;
|
| 343 |
-
btn.innerText = "🚀 开始生成";
|
| 344 |
-
} else {
|
| 345 |
-
btn.disabled = true;
|
| 346 |
-
btn.innerText = "🚫 请先勾选免责声明";
|
| 347 |
-
}
|
| 348 |
-
}
|
| 349 |
|
| 350 |
async function generateImage() {
|
| 351 |
-
const apiKey = document.getElementById('api_key').value;
|
| 352 |
-
const prompt = document.getElementById('prompt').value;
|
| 353 |
-
const checkbox = document.getElementById('agree_chk');
|
| 354 |
-
|
| 355 |
-
if (!checkbox.checked) { alert("请先勾选免责声明!"); return; }
|
| 356 |
-
if (!apiKey) { alert("请输入 API Key"); return; }
|
| 357 |
-
if (!prompt) { alert("请输入提示词"); return; }
|
| 358 |
-
|
| 359 |
const btn = document.getElementById('gen-btn');
|
| 360 |
const loader = document.getElementById('loader');
|
| 361 |
const img = document.getElementById('result-img');
|
| 362 |
-
const
|
| 363 |
-
const statusText = document.getElementById('status-text');
|
| 364 |
|
| 365 |
btn.disabled = true;
|
| 366 |
-
btn.innerText = "生成中...";
|
| 367 |
loader.style.display = 'block';
|
| 368 |
img.style.display = 'none';
|
| 369 |
-
|
| 370 |
-
statusText.innerText = "正在请求 API...";
|
| 371 |
|
| 372 |
const payload = {
|
| 373 |
-
api_key:
|
| 374 |
model: document.getElementById('model').value,
|
| 375 |
-
prompt: prompt,
|
| 376 |
ratio: document.getElementById('ratio').value,
|
| 377 |
scale: document.getElementById('scale').value,
|
| 378 |
-
format:
|
| 379 |
-
|
| 380 |
};
|
| 381 |
|
| 382 |
try {
|
| 383 |
-
const
|
| 384 |
method: 'POST',
|
| 385 |
headers: { 'Content-Type': 'application/json' },
|
| 386 |
body: JSON.stringify(payload)
|
| 387 |
});
|
| 388 |
-
|
| 389 |
-
const data = await response.json();
|
| 390 |
-
|
| 391 |
if (data.status === 'success') {
|
| 392 |
-
img.src =
|
| 393 |
img.style.display = 'block';
|
| 394 |
-
|
| 395 |
-
downloadBtn.download = `generated_image.${payload.format}`;
|
| 396 |
-
downloadBtn.style.display = 'inline-block';
|
| 397 |
-
downloadBtn.innerText = "下载图片";
|
| 398 |
-
statusText.innerText = "";
|
| 399 |
} else {
|
| 400 |
-
|
| 401 |
-
|
| 402 |
}
|
| 403 |
-
} catch (
|
| 404 |
-
|
| 405 |
-
statusText.innerText = "网络请求失败";
|
| 406 |
-
alert("网络请求失败,请检查控制台");
|
| 407 |
} finally {
|
| 408 |
-
|
| 409 |
-
btn.disabled = false;
|
| 410 |
-
btn.innerText = "🚀 开始生成";
|
| 411 |
-
} else {
|
| 412 |
-
btn.innerText = "🚫 请先勾选免责声明";
|
| 413 |
-
}
|
| 414 |
loader.style.display = 'none';
|
| 415 |
}
|
| 416 |
}
|
| 417 |
</script>
|
| 418 |
-
|
| 419 |
</body>
|
| 420 |
</html>
|
|
|
|
| 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>
|