yaoqifa commited on
Commit
fa7695d
·
verified ·
1 Parent(s): b010930

Create static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +264 -0
static/index.html ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
15
+ body {
16
+ font-family: 'Segoe UI', system-ui, sans-serif;
17
+ background-color: var(--bg-color);
18
+ color: var(--text-color);
19
+ margin: 0;
20
+ padding: 20px;
21
+ display: flex;
22
+ justify-content: center;
23
+ }
24
+ .container {
25
+ width: 100%;
26
+ max-width: 1000px;
27
+ display: grid;
28
+ grid-template-columns: 350px 1fr;
29
+ gap: 20px;
30
+ }
31
+ .card {
32
+ background-color: var(--card-color);
33
+ padding: 20px;
34
+ border-radius: 12px;
35
+ box-shadow: 0 4px 6px rgba(0,0,0,0.3);
36
+ }
37
+ h1 { margin-top: 0; font-size: 1.5rem; color: var(--accent-color); }
38
+ .form-group { margin-bottom: 15px; }
39
+ label { display: block; margin-bottom: 5px; font-size: 0.9rem; color: #a0aec0; }
40
+ input, select, textarea {
41
+ width: 100%;
42
+ padding: 10px;
43
+ background-color: var(--input-bg);
44
+ border: 1px solid #4a5568;
45
+ border-radius: 6px;
46
+ color: white;
47
+ box-sizing: border-box;
48
+ font-size: 0.95rem;
49
+ }
50
+ input:focus, select:focus, textarea:focus {
51
+ outline: none;
52
+ border-color: var(--accent-color);
53
+ }
54
+ button {
55
+ width: 100%;
56
+ padding: 12px;
57
+ background-color: var(--accent-color);
58
+ color: white;
59
+ border: none;
60
+ border-radius: 6px;
61
+ font-size: 1rem;
62
+ cursor: pointer;
63
+ transition: background 0.2s;
64
+ font-weight: bold;
65
+ }
66
+ button:hover { background-color: #2563eb; }
67
+ button:disabled { background-color: #4a5568; cursor: not-allowed; }
68
+
69
+ /* 图片展示区 */
70
+ .result-area {
71
+ display: flex;
72
+ flex-direction: column;
73
+ align-items: center;
74
+ justify-content: center;
75
+ min-height: 400px;
76
+ border: 2px dashed #4a5568;
77
+ border-radius: 12px;
78
+ position: relative;
79
+ }
80
+ #result-img {
81
+ max-width: 100%;
82
+ max-height: 600px;
83
+ border-radius: 8px;
84
+ display: none;
85
+ box-shadow: 0 4px 15px rgba(0,0,0,0.5);
86
+ }
87
+ .loader {
88
+ border: 4px solid #f3f3f3;
89
+ border-top: 4px solid var(--accent-color);
90
+ border-radius: 50%;
91
+ width: 40px;
92
+ height: 40px;
93
+ animation: spin 1s linear infinite;
94
+ display: none;
95
+ }
96
+ .download-btn {
97
+ margin-top: 15px;
98
+ background-color: #10b981;
99
+ width: auto;
100
+ padding: 8px 20px;
101
+ display: none;
102
+ }
103
+ @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
104
+
105
+ @media (max-width: 768px) {
106
+ .container { grid-template-columns: 1fr; }
107
+ }
108
+ </style>
109
+ </head>
110
+ <body>
111
+
112
+ <div class="container">
113
+ <!-- 左侧设置栏 -->
114
+ <div class="card">
115
+ <h1>Imagen</h1>
116
+
117
+ <div class="form-group">
118
+ <label>API Key</label>
119
+ <input type="password" id="api_key" placeholder="sk-...">
120
+ </div>
121
+
122
+ <div class="form-group">
123
+ <label>模型名称</label>
124
+ <select id="model">
125
+ <option value="nano-banana">nano-banana</option>
126
+ <option value="nano-banana-pro">nano-banana-pro</option>
127
+ <option value="nano-banana-pro-4k">nano-banana-pro-4k</option>
128
+ <option value="gemini-2.5-flash-image">gemini-2.5-flash-image</option>
129
+ <option value="gemini-3-pro-image">gemini-3-pro-image</option>
130
+ <option value="gemini-3-pro-image-preview">gemini-3-pro-image-preview</option>
131
+ </select>
132
+ </div>
133
+
134
+ <div class="form-group">
135
+ <label>基础比例</label>
136
+ <select id="ratio" onchange="toggleCustomSize()">
137
+ <option value="16:9 (1080p Full HD)">16:9 (1080p Full HD)</option>
138
+ <option value="1:1 (SDXL标准 1024)">1:1 (SDXL标准 1024)</option>
139
+ <option value="16:9 (SDXL标准 768p)">16:9 (SDXL标准 768p)</option>
140
+ <option value="9:16 (手机竖屏)">9:16 (手机竖屏)</option>
141
+ <option value="4:3 (标准)">4:3 (标准)</option>
142
+ <option value="21:9 (宽屏)">21:9 (宽屏)</option>
143
+ <option value="custom">自定��� (Custom)</option>
144
+ </select>
145
+ </div>
146
+
147
+ <div class="form-group" id="custom-size-group" style="display: none;">
148
+ <label>手动分辨率 (WxH)</label>
149
+ <input type="text" id="custom_size" value="1920x1080">
150
+ </div>
151
+
152
+ <div class="form-group">
153
+ <label>清晰度</label>
154
+ <select id="scale">
155
+ <option value="1k">1k</option>
156
+ <option value="2k">2k</option>
157
+ <option value="4k">4k (配合 Pro 模型)</option>
158
+ </select>
159
+ </div>
160
+
161
+ <div class="form-group">
162
+ <label>输出格式</label>
163
+ <select id="format">
164
+ <option value="png">PNG</option>
165
+ <option value="jpg">JPG</option>
166
+ </select>
167
+ </div>
168
+ </div>
169
+
170
+ <!-- 右侧展示栏 -->
171
+ <div class="card">
172
+ <div class="form-group">
173
+ <label>提示词 (Prompt)</label>
174
+ <textarea id="prompt" rows="4" placeholder="描述你想要的画面..."></textarea>
175
+ </div>
176
+
177
+ <button onclick="generateImage()" id="gen-btn">🚀 开始生成</button>
178
+
179
+ <div class="result-area" id="result-area">
180
+ <div class="loader" id="loader"></div>
181
+ <img id="result-img" alt="Generated Image" />
182
+ <a id="download-link" class="download-btn" href="#" download="image.png">下载图片</a>
183
+ <p id="status-text" style="color: #a0aec0; margin-top: 10px;">等待生成...</p>
184
+ </div>
185
+ </div>
186
+ </div>
187
+
188
+ <script>
189
+ function toggleCustomSize() {
190
+ const ratio = document.getElementById('ratio').value;
191
+ const customGroup = document.getElementById('custom-size-group');
192
+ customGroup.style.display = ratio === 'custom' ? 'block' : 'none';
193
+ }
194
+
195
+ async function generateImage() {
196
+ const apiKey = document.getElementById('api_key').value;
197
+ const prompt = document.getElementById('prompt').value;
198
+
199
+ if (!apiKey) { alert("请输入 API Key"); return; }
200
+ if (!prompt) { alert("请输入提示词"); return; }
201
+
202
+ const btn = document.getElementById('gen-btn');
203
+ const loader = document.getElementById('loader');
204
+ const img = document.getElementById('result-img');
205
+ const downloadBtn = document.getElementById('download-link');
206
+ const statusText = document.getElementById('status-text');
207
+
208
+ // UI 状态更新
209
+ btn.disabled = true;
210
+ btn.innerText = "生成中...";
211
+ loader.style.display = 'block';
212
+ img.style.display = 'none';
213
+ downloadBtn.style.display = 'none';
214
+ statusText.innerText = "正在请求 API...";
215
+
216
+ const payload = {
217
+ api_key: apiKey,
218
+ model: document.getElementById('model').value,
219
+ prompt: prompt,
220
+ ratio: document.getElementById('ratio').value,
221
+ scale: document.getElementById('scale').value,
222
+ custom_size: document.getElementById('custom_size').value,
223
+ format: document.getElementById('format').value
224
+ };
225
+
226
+ try {
227
+ const response = await fetch('/api/generate', {
228
+ method: 'POST',
229
+ headers: { 'Content-Type': 'application/json' },
230
+ body: JSON.stringify(payload)
231
+ });
232
+
233
+ const data = await response.json();
234
+
235
+ if (data.status === 'success') {
236
+ // 显示图片
237
+ img.src = `data:image/${payload.format === 'jpg' ? 'jpeg' : 'png'};base64,${data.image_base64}`;
238
+ img.style.display = 'block';
239
+
240
+ // 设置下载链接
241
+ downloadBtn.href = img.src;
242
+ downloadBtn.download = `generated_image.${payload.format}`;
243
+ downloadBtn.style.display = 'inline-block';
244
+ downloadBtn.innerText = "下载图片";
245
+
246
+ statusText.innerText = "";
247
+ } else {
248
+ statusText.innerText = "生成失败: " + data.message;
249
+ alert("错误: " + data.message);
250
+ }
251
+ } catch (error) {
252
+ console.error(error);
253
+ statusText.innerText = "网络请求失败";
254
+ alert("网络请求失败,请检查控制台");
255
+ } finally {
256
+ btn.disabled = false;
257
+ btn.innerText = "🚀 开始生成";
258
+ loader.style.display = 'none';
259
+ }
260
+ }
261
+ </script>
262
+
263
+ </body>
264
+ </html>