Upload index.html
Browse files- 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 |
-
|
| 9 |
-
|
| 10 |
-
--
|
| 11 |
-
--
|
| 12 |
-
--
|
| 13 |
-
--
|
| 14 |
-
--
|
| 15 |
-
--
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
color: var(--
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
border
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
border:
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
cursor: pointer;
|
| 66 |
-
transition:
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
height:
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
width:
|
| 111 |
-
padding:
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
border-radius: 6px;
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
margin-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
<
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
<
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
<
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
</
|
| 238 |
-
|
| 239 |
-
<
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>
|