-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
710 lines (628 loc) · 24 KB
/
index.html
File metadata and controls
710 lines (628 loc) · 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
104
105
106
107
108
109
110
111
112
113
114
115
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
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI 图像生成器</title>
<link rel="stylesheet" href="fonts.css">
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--primary-color: #4f46e5;
--primary-hover: #4338ca;
--primary-light: rgba(79, 70, 229, 0.1);
--bg-color: #f8fafc;
--sidebar-bg: #ffffff;
--text-color: #1e293b;
--text-light: #64748b;
--border-color: #e2e8f0;
--shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
--shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
--shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
--radius-md: 12px;
--radius-sm: 8px;
--radius-lg: 16px;
}
body {
font-family: 'Inter', sans-serif;
background: var(--bg-color);
color: var(--text-color);
min-height: 100vh;
display: flex;
}
.sidebar {
width: 340px;
padding: 24px;
background: var(--sidebar-bg);
border-right: none;
box-shadow: var(--shadow-lg);
height: 100vh;
overflow-y: auto;
position: fixed;
z-index: 100;
}
.main-content {
flex: 1;
padding: 24px;
margin-left: 340px;
display: flex;
flex-direction: column;
gap: 24px;
}
.control-group {
margin-bottom: 24px;
background: white;
padding: 16px;
border-radius: var(--radius-md);
box-shadow: var(--shadow-sm);
border: 1px solid var(--border-color);
transition: all 0.3s ease;
}
.control-group:hover {
box-shadow: var(--shadow-md);
transform: translateY(-2px);
}
.control-group h3 {
margin-bottom: 12px;
color: var(--text-color);
font-size: 0.9rem;
font-weight: 600;
}
label {
display: block;
margin-bottom: 8px;
font-size: 0.85rem;
color: #64748b;
font-weight: 500;
}
select, input, textarea {
width: 100%;
padding: 10px 12px;
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
font-size: 0.9rem;
transition: all 0.2s;
color: var(--text-color);
}
select:focus, input:focus, textarea:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.image-size-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 12px;
}
.image-size-option {
aspect-ratio: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: white;
border: 2px solid var(--border-color);
border-radius: var(--radius-sm);
cursor: pointer;
transition: all 0.2s;
padding: 12px;
}
.image-size-option.active {
border-color: var(--primary-color);
background: rgba(99, 102, 241, 0.05);
}
.image-size-option:hover {
border-color: var(--primary-color);
}
.image-size-option .aspect-ratio {
width: 32px;
height: 32px;
border: 2px solid currentColor;
margin-bottom: 8px;
opacity: 0.6;
}
.image-size-option span {
font-size: 0.8rem;
font-weight: 500;
}
.image-preview {
flex: 1;
background: linear-gradient(135deg, #fff, #f8fafc);
box-shadow: var(--shadow-lg);
border-radius: var(--radius-md);
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
min-height: 400px;
transition: all 0.3s ease;
position: relative;
}
.image-preview:hover {
transform: translateY(-2px);
box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
}
.image-preview img {
max-width: 100%;
max-height: 100%;
object-fit: contain;
transition: all 0.3s ease;
}
.loading-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(5px);
display: none;
align-items: center;
justify-content: center;
flex-direction: column;
gap: 16px;
}
.loading-overlay.active {
display: flex;
}
.spinner {
width: 50px;
height: 50px;
border: 4px solid #f3f3f3;
border-top: 4px solid var(--primary-color);
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.prompt-container {
background: white;
border-radius: var(--radius-md);
padding: 24px;
box-shadow: var(--shadow-md);
}
.tag-container {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 16px;
}
.tag {
background: var(--primary-light);
color: var(--primary-color);
font-weight: 600;
border: 1px solid transparent;
padding: 6px 12px;
border-radius: 20px;
font-size: 0.85rem;
cursor: pointer;
transition: all 0.2s ease;
}
.tag:hover {
background: var(--primary-color);
color: white;
transform: translateY(-2px);
}
.prompt-input {
display: flex;
gap: 12px;
}
.prompt-input input {
flex: 1;
padding: 12px 16px;
border: 2px solid var(--border-color);
border-radius: var(--radius-md);
font-size: 0.95rem;
transition: all 0.3s ease;
box-shadow: var(--shadow-sm);
}
.prompt-input input:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 4px var(--primary-light);
}
.prompt-input button {
padding: 12px 24px;
background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
color: white;
border: none;
border-radius: var(--radius-md);
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 8px;
box-shadow: var(--shadow-md);
}
.prompt-input button:hover {
transform: translateY(-2px);
box-shadow: var(--shadow-lg);
}
.prompt-input button:active {
transform: translateY(0);
}
/* Slider styling */
.slider-container {
display: flex;
flex-direction: column;
gap: 8px;
}
.slider-value {
font-size: 0.85rem;
color: #64748b;
text-align: right;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 8px;
background: linear-gradient(to right, var(--primary-light), var(--primary-color));
outline: none;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
width: 24px;
height: 24px;
background: white;
border: 2px solid var(--primary-color);
box-shadow: var(--shadow-md);
transition: all 0.2s ease;
}
.slider::-webkit-slider-thumb:hover {
transform: scale(1.1);
}
.slider::-moz-range-thumb {
width: 24px;
height: 24px;
background: white;
border: 2px solid var(--primary-color);
box-shadow: var(--shadow-md);
transition: all 0.2s ease;
}
.slider::-moz-range-thumb:hover {
transform: scale(1.1);
}
/* Responsive design */
@media (max-width: 1024px) {
.sidebar {
width: 300px;
transform: translateX(-100%);
transition: transform 0.3s ease;
}
.sidebar.active {
transform: translateX(0);
}
.main-content {
margin-left: 0;
padding: 16px;
}
.menu-toggle {
display: block;
position: fixed;
top: 20px;
left: 20px;
z-index: 1000;
background: var(--primary-color);
color: white;
padding: 8px;
border-radius: var(--radius-sm);
cursor: pointer;
}
}
@media (max-width: 768px) {
body {
flex-direction: column;
}
.sidebar {
width: 100%;
height: auto;
position: relative;
}
.main-content {
margin-left: 0;
}
}
/* 添加加载动画样式 */
@keyframes float {
0% { transform: translateY(0px); }
50% { transform: translateY(-10px); }
100% { transform: translateY(0px); }
}
.float-animation {
animation: float 3s ease-in-out infinite;
}
/* 添加工具提示样式 */
[data-tooltip] {
position: relative;
}
[data-tooltip]:before {
content: attr(data-tooltip);
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
padding: 8px 12px;
background: var(--text-color);
color: white;
font-size: 0.75rem;
border-radius: var(--radius-sm);
white-space: nowrap;
opacity: 0;
visibility: hidden;
transition: all 0.2s ease;
}
[data-tooltip]:hover:before {
opacity: 1;
visibility: visible;
transform: translateX(-50%) translateY(-8px);
}
/* 添加深色模式支持 */
@media (prefers-color-scheme: dark) {
:root {
--bg-color: #0f172a;
--sidebar-bg: #1e293b;
--text-color: #f8fafc;
--text-light: #cbd5e1;
--border-color: #334155;
}
.glass-effect {
background: rgba(30, 41, 59, 0.7);
}
.image-preview {
background: linear-gradient(135deg, #1e293b, #0f172a);
}
.tag {
background: rgba(79, 70, 229, 0.2);
}
}
</style>
</head>
<body>
<button class="menu-toggle glass-effect" id="menuToggle">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M3 12h18M3 6h18M3 18h18"/>
</svg>
</button>
<div class="sidebar">
<div class="control-group">
<h3>模型选择</h3>
<select id="model">
<option value="Pro/black-forest-labs/FLUX.1-schnell">FLUX.1-schnell (Pro)</option>
<option value="black-forest-labs/FLUX.1-schnell">FLUX.1-schnell (Black Forest)</option>
<option value="black-forest-labs/FLUX.1-dev">FLUX.1-dev (Black Forest)</option>
<option value="stabilityai/stable-diffusion-3-5-large">stable-diffusion-3-5-large</option>
<option value="stabilityai/stable-diffusion-3-5-large-turbo">stable-diffusion-3-5-large-turbo</option>
<option value="stabilityai/stable-diffusion-3-medium">stable-diffusion-3-medium</option>
<option value="stabilityai/stable-diffusion-xl-base-1.0">stable-diffusion-xl-base-1.0</option>
<option value="stabilityai/stable-diffusion-2-1">stable-diffusion-2-1</option>
</select>
</div>
<div class="control-group">
<h3>图像尺寸</h3>
<div class="image-size-grid">
<div class="image-size-option" data-ratio="1:1">
<div class="aspect-ratio"></div>
<span>1:1</span>
</div>
<div class="image-size-option" data-ratio="1:2">
<div class="aspect-ratio"></div>
<span>1:2</span>
</div>
<div class="image-size-option" data-ratio="3:2">
<div class="aspect-ratio"></div>
<span>3:2</span>
</div>
<div class="image-size-option" data-ratio="3:4">
<div class="aspect-ratio"></div>
<span>3:4</span>
</div>
<div class="image-size-option" data-ratio="16:9">
<div class="aspect-ratio"></div>
<span>16:9</span>
</div>
<div class="image-size-option" data-ratio="9:16">
<div class="aspect-ratio"></div>
<span>9:16</span>
</div>
</div>
</div>
<div class="control-group">
<h3>生成参数</h3>
<div class="slider-container">
<label for="number-images">生成数量</label>
<input type="number" id="number-images" value="1" min="1" max="4">
</div>
<div class="slider-container">
<label for="seed">随机种子</label>
<input type="number" id="seed">
</div>
<div class="slider-container">
<label for="inference-steps">推理步数</label>
<input type="range" id="inference-steps" class="slider" min="1" max="50" value="25">
<div class="slider-value" id="inference-steps-value">25</div>
</div>
<div class="slider-container">
<label for="guidance-scale">引导系数</label>
<input type="range" id="guidance-scale" class="slider" min="1" max="20" step="0.1" value="7.5">
<div class="slider-value" id="guidance-scale-value">7.5</div>
</div>
</div>
<div class="control-group">
<h3>高级选项</h3>
<label for="negative-prompt">反向提示词</label>
<textarea id="negative-prompt" rows="4" placeholder="输入不想在图像中出现的元素..."></textarea>
<label for="prompt-enhancement">提示词增强</label>
<select id="prompt-enhancement">
<option value="default">默认</option>
<option value="enhanced">增强</option>
</select>
</div>
</div>
<div class="main-content">
<div class="image-preview">
<img style="display: none;" alt="生成的图像预览">
<div class="loading-overlay">
<div class="spinner"></div>
<p>正在生成图像...</p>
</div>
</div>
<div class="prompt-container">
<div class="tag-container">
<span class="tag">细节特写</span>
<span class="tag">夸张视角</span>
<span class="tag">电影光效</span>
<span class="tag">写实风格</span>
<span class="tag">梦幻氛围</span>
<span class="tag">自然光线</span>
</div>
<div class="prompt-input">
<input type="text" id="prompt" placeholder="描述你想创建的图像...">
<button id="generate">
<span>生成图像</span>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 5v14M19 12l-7 7-7-7"/>
</svg>
</button>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// 示例图片数组 - 使用本地图片
const sampleImages = [
'/img/sample1.jpg',
'/img/sample2.jpg',
'/img/sample3.jpg',
'/img/sample4.jpg'
];
// 随机选择一张图片
const randomIndex = Math.floor(Math.random() * sampleImages.length);
const previewImg = document.querySelector('.image-preview img');
previewImg.style.display = 'block';
previewImg.style.opacity = '0';
previewImg.src = sampleImages[randomIndex];
// 添加加载完成的渐入效果
previewImg.onload = function() {
previewImg.style.opacity = '1';
};
// Slider value updates
const sliders = document.querySelectorAll('.slider');
sliders.forEach(slider => {
const valueDisplay = document.getElementById(`${slider.id}-value`);
slider.addEventListener('input', () => {
valueDisplay.textContent = slider.value;
});
});
// Image size selection
const imageSizeOptions = document.querySelectorAll('.image-size-option');
imageSizeOptions.forEach(option => {
option.addEventListener('click', function() {
imageSizeOptions.forEach(opt => opt.classList.remove('active'));
this.classList.add('active');
});
});
// Generate button click handler
document.getElementById('generate').addEventListener('click', async function() {
const loadingOverlay = document.querySelector('.loading-overlay');
loadingOverlay.classList.add('active');
try {
// 获取所有参数
const prompt = document.getElementById('prompt').value;
const negative_prompt = document.getElementById('negative-prompt').value;
const model = document.getElementById('model').value;
const batch_size = document.getElementById('number-images').value;
const seed = document.getElementById('seed').value;
const num_inference_steps = document.getElementById('inference-steps').value;
const guidance_scale = document.getElementById('guidance-scale').value;
const prompt_enhancement = document.getElementById('prompt-enhancement').value === 'enhanced';
const selectedSize = document.querySelector('.image-size-option.active');
const image_size = selectedSize ? getImageSize(selectedSize.dataset.ratio) : "1024x1024";
const response = await fetch('http://localhost:3000/generate-image', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
prompt,
negative_prompt,
image_size,
batch_size,
seed,
num_inference_steps,
guidance_scale,
prompt_enhancement,
model
})
});
const data = await response.json();
if (data.error) {
throw new Error(data.error);
}
if (data.images && data.images.length > 0) {
const previewImg = document.querySelector('.image-preview img');
previewImg.style.opacity = '0';
previewImg.style.display = 'block';
setTimeout(() => {
previewImg.src = data.images[0];
previewImg.style.opacity = '1';
}, 300);
}
} catch (error) {
console.error('错误:', error);
alert('生成图像失败: ' + error.message);
} finally {
loadingOverlay.classList.remove('active');
}
});
// Tag click handler
const tags = document.querySelectorAll('.tag');
tags.forEach(tag => {
tag.addEventListener('click', function() {
const promptInput = document.getElementById('prompt');
promptInput.value = promptInput.value + (promptInput.value ? ', ' : '') + this.textContent;
});
});
// 添加菜单切换功能
const menuToggle = document.getElementById('menuToggle');
const sidebar = document.querySelector('.sidebar');
menuToggle.addEventListener('click', () => {
sidebar.classList.toggle('active');
});
// 添加图片预览悬浮动画
const imagePreview = document.querySelector('.image-preview');
imagePreview.classList.add('float-animation');
// 添加工具提示
const controls = document.querySelectorAll('.control-group h3');
controls.forEach(control => {
control.setAttribute('data-tooltip', '点击查看详细说明');
});
// 添加平滑滚动
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
});
function getImageSize(ratio) {
const ratios = {
'1:1': '1024x1024',
'1:2': '512x1024',
'3:2': '768x512',
'3:4': '768x1024',
'16:9': '1024x576',
'9:16': '576x1024'
};
return ratios[ratio] || '1024x1024';
}
</script>
</body>
</html>