prithivMLmods commited on
Commit
dcc2cd2
·
1 Parent(s): d59ea05

use gradio server (#24)

Browse files

- Migrate to gradio.Server with custom studio frontend (fa0df28ab73f842deb050255a40a2eebf76af828)

Files changed (2) hide show
  1. app.py +72 -1202
  2. index.html +1358 -0
app.py CHANGED
@@ -1,13 +1,14 @@
1
  import os
2
  import gc
3
  import gradio as gr
 
 
4
  import numpy as np
5
  import spaces
6
  import torch
7
  import random
8
  import base64
9
  import json
10
- import html as html_lib
11
  from io import BytesIO
12
  from PIL import Image
13
 
@@ -202,53 +203,27 @@ def encode_full_image(path):
202
  return ""
203
 
204
 
205
- def build_example_cards_html():
206
- cards = ""
 
207
  for i, ex in enumerate(EXAMPLES_CONFIG):
208
- thumbs_html = ""
209
- for path in ex["images"]:
210
- thumb = make_thumb_b64(path)
211
- if thumb:
212
- thumbs_html += f'<img src="{thumb}" alt="">'
213
- else:
214
- thumbs_html += '<div class="example-thumb-placeholder">Preview</div>'
215
- n = len(ex["images"])
216
- img_badge = f'{n} image{"s" if n > 1 else ""}'
217
- lora_badge = html_lib.escape(ex["lora"])
218
- prompt_short = html_lib.escape(ex["prompt"][:85])
219
- if len(ex["prompt"]) > 85:
220
- prompt_short += "…"
221
- cards += f'''<div class="example-card" data-idx="{i}">
222
- <div class="example-thumbs">{thumbs_html}</div>
223
- <div class="example-meta">
224
- <span class="example-badge">{img_badge}</span>
225
- <span class="example-lora-badge">{lora_badge}</span>
226
- </div>
227
- <div class="example-prompt-text">{prompt_short}</div>
228
- </div>'''
229
- return cards
230
-
231
-
232
- def load_example_data(idx_str):
233
- try:
234
- idx = int(float(idx_str)) if idx_str and idx_str.strip() else -1
235
- except (ValueError, TypeError):
236
- idx = -1
237
- if idx < 0 or idx >= len(EXAMPLES_CONFIG):
238
- return json.dumps({"images": [], "prompt": "", "lora": "", "names": [], "status": "error"})
239
- ex = EXAMPLES_CONFIG[idx]
240
- b64_list, names = [], []
241
- for path in ex["images"]:
242
- b64 = encode_full_image(path)
243
- if b64:
244
- b64_list.append(b64)
245
- names.append(os.path.basename(path))
246
- return json.dumps({"images": b64_list, "prompt": ex["prompt"], "lora": ex["lora"], "names": names, "status": "ok"})
247
 
248
 
249
- print("Building example thumbnails…")
250
- EXAMPLE_CARDS_HTML = build_example_cards_html()
251
- print(f"Built {len(EXAMPLES_CONFIG)} example cards.")
252
 
253
 
254
  def b64_to_pil_list(b64_json_str):
@@ -274,6 +249,12 @@ def b64_to_pil_list(b64_json_str):
274
  return pil_images
275
 
276
 
 
 
 
 
 
 
277
  def update_dimensions_on_upload(image):
278
  if image is None:
279
  return 1024, 1024
@@ -287,17 +268,26 @@ def update_dimensions_on_upload(image):
287
  return (nw // 8) * 8, (nh // 8) * 8
288
 
289
 
 
 
 
 
 
 
290
  @spaces.GPU(size="xlarge")
291
  def infer(
292
- images_b64_json,
293
- prompt,
294
- lora_adapter,
295
- seed,
296
- randomize_seed,
297
- guidance_scale,
298
- steps,
299
- progress=gr.Progress(track_tqdm=True),
300
- ):
 
 
 
301
  gc.collect()
302
  torch.cuda.empty_cache()
303
 
@@ -345,7 +335,7 @@ def infer(
345
  generator=generator,
346
  true_cfg_scale=guidance_scale,
347
  ).images[0]
348
- return result_image, seed
349
  except Exception as e:
350
  raise e
351
  finally:
@@ -353,1157 +343,37 @@ def infer(
353
  torch.cuda.empty_cache()
354
 
355
 
356
- css = r"""
357
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');
358
- *{box-sizing:border-box;margin:0;padding:0}
359
- body,.gradio-container{
360
- background:#0f0f13!important;font-family:'Inter',system-ui,-apple-system,sans-serif!important;
361
- font-size:14px!important;color:#e4e4e7!important;min-height:100vh;
362
- }
363
- .dark body,.dark .gradio-container{background:#0f0f13!important;color:#e4e4e7!important}
364
- footer{display:none!important}
365
- .hidden-input{display:none!important;height:0!important;overflow:hidden!important;margin:0!important;padding:0!important}
366
-
367
- #example-load-btn{
368
- position:absolute!important;left:-9999px!important;top:-9999px!important;
369
- width:1px!important;height:1px!important;opacity:0.01!important;
370
- pointer-events:none!important;overflow:hidden!important;
371
- }
372
- #gradio-run-btn{
373
- position:absolute;left:-9999px;top:-9999px;width:1px;height:1px;
374
- opacity:0.01;pointer-events:none;overflow:hidden;
375
- }
376
-
377
- /* ── App shell ── */
378
- .app-shell{
379
- background:#18181b;border:1px solid #27272a;border-radius:16px;
380
- margin:12px auto;max-width:1440px;overflow:hidden;
381
- box-shadow:0 25px 50px -12px rgba(0,0,0,.6),0 0 0 1px rgba(255,255,255,.03);
382
- }
383
-
384
- /* ── Header ── */
385
- .app-header{
386
- background:linear-gradient(135deg,#18181b,#1e1e24);border-bottom:1px solid #27272a;
387
- padding:14px 24px;display:flex;align-items:center;justify-content:space-between;
388
- flex-wrap:wrap;gap:12px;
389
- }
390
- .app-header-left{display:flex;align-items:center;gap:12px}
391
- .app-logo{
392
- width:38px;height:38px;background:linear-gradient(135deg,#1E90FF,#47A3FF,#7CB8FF);
393
- border-radius:11px;display:flex;align-items:center;justify-content:center;
394
- box-shadow:0 4px 12px rgba(30,144,255,.35);flex-shrink:0;
395
- }
396
- .app-logo svg{width:20px;height:20px;fill:#fff;flex-shrink:0}
397
- .app-title{
398
- font-size:18px;font-weight:800;background:linear-gradient(135deg,#e4e4e7,#a1a1aa);
399
- -webkit-background-clip:text;-webkit-text-fill-color:transparent;letter-spacing:-.3px;
400
- }
401
- .app-badge{
402
- font-size:11px;font-weight:700;padding:3px 10px;border-radius:20px;
403
- background:rgba(30,144,255,.15);color:#47A3FF;border:1px solid rgba(30,144,255,.25);letter-spacing:.3px;
404
- }
405
- .app-badge.fast{background:rgba(34,197,94,.12);color:#4ade80;border:1px solid rgba(34,197,94,.25)}
406
-
407
- /* ── GitHub button ── */
408
- .gh-btn{
409
- display:inline-flex!important;align-items:center!important;gap:7px!important;
410
- padding:7px 16px!important;border-radius:8px!important;text-decoration:none!important;
411
- font-family:'Inter',sans-serif!important;font-size:13px!important;font-weight:700!important;
412
- letter-spacing:.1px!important;background:#1E90FF!important;
413
- color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;
414
- border:1px solid rgba(255,255,255,.18)!important;
415
- box-shadow:0 2px 10px rgba(30,144,255,.45),0 1px 0 rgba(255,255,255,.1) inset!important;
416
- transition:transform .15s ease,box-shadow .15s ease,background .15s ease!important;
417
- cursor:pointer!important;flex-shrink:0!important;
418
- }
419
- .gh-btn:hover{
420
- background:#47A3FF!important;color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;
421
- transform:translateY(-1px)!important;
422
- box-shadow:0 5px 18px rgba(30,144,255,.6),0 1px 0 rgba(255,255,255,.12) inset!important;
423
- }
424
- .gh-btn:active{
425
- background:#1873CC!important;transform:translateY(0)!important;
426
- box-shadow:0 1px 5px rgba(30,144,255,.35)!important;
427
- }
428
- .gh-btn svg{fill:#ffffff!important;flex-shrink:0;width:15px!important;height:15px!important}
429
- .gh-btn span{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important}
430
-
431
- @media (prefers-color-scheme: light){
432
- .gh-btn{background:#1E90FF!important;color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;border-color:rgba(255,255,255,.18)!important}
433
- .gh-btn:hover{background:#47A3FF!important}
434
- .gh-btn svg{fill:#ffffff!important}
435
- .gh-btn span{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important}
436
- }
437
-
438
- /* ── Toolbar ── */
439
- .app-toolbar{
440
- background:#18181b;border-bottom:1px solid #27272a;padding:8px 16px;
441
- display:flex;gap:4px;align-items:center;flex-wrap:wrap;
442
- }
443
- .tb-sep{width:1px;height:28px;background:#27272a;margin:0 8px}
444
- .modern-tb-btn{
445
- display:inline-flex;align-items:center;justify-content:center;gap:6px;
446
- min-width:32px;height:34px;background:transparent;border:1px solid transparent;
447
- border-radius:8px;cursor:pointer;font-size:13px;font-weight:600;padding:0 12px;
448
- font-family:'Inter',sans-serif;color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;
449
- transition:all .15s ease;
450
- }
451
- .modern-tb-btn:hover{background:rgba(30,144,255,.15);border-color:rgba(30,144,255,.3)}
452
- .modern-tb-btn:active,.modern-tb-btn.active{background:rgba(30,144,255,.25);border-color:rgba(30,144,255,.45)}
453
- .modern-tb-btn .tb-label{font-size:13px;color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;font-weight:600}
454
- .modern-tb-btn .tb-svg{width:15px;height:15px;flex-shrink:0;color:#ffffff!important}
455
- .modern-tb-btn .tb-svg,
456
- .modern-tb-btn .tb-svg *{stroke:#ffffff!important;fill:none!important}
457
- .tb-info{font-family:'JetBrains Mono',monospace;font-size:12px;color:#71717a;padding:0 8px;display:flex;align-items:center}
458
-
459
- body:not(.dark) .modern-tb-btn,body:not(.dark) .modern-tb-btn *{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important}
460
- body:not(.dark) .modern-tb-btn .tb-svg,body:not(.dark) .modern-tb-btn .tb-svg *{stroke:#ffffff!important}
461
- .dark .modern-tb-btn,.dark .modern-tb-btn *{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important}
462
- .dark .modern-tb-btn .tb-svg,.dark .modern-tb-btn .tb-svg *{stroke:#ffffff!important}
463
- .gradio-container .modern-tb-btn,.gradio-container .modern-tb-btn *{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important}
464
- .gradio-container .modern-tb-btn .tb-svg,.gradio-container .modern-tb-btn .tb-svg *{stroke:#ffffff!important}
465
-
466
- /* ── Main layout ── */
467
- .app-main-row{display:flex;gap:0;flex:1;overflow:hidden}
468
- .app-main-left{flex:1;display:flex;flex-direction:column;min-width:0;border-right:1px solid #27272a}
469
- .app-main-right{width:440px;display:flex;flex-direction:column;flex-shrink:0;background:#18181b}
470
-
471
- /* ── Drop zone ── */
472
- #gallery-drop-zone{position:relative;background:#09090b;min-height:440px;overflow:auto}
473
- #gallery-drop-zone.drag-over{outline:2px solid #1E90FF;outline-offset:-2px;background:rgba(30,144,255,.04)}
474
-
475
- .upload-prompt-modern{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);z-index:20}
476
- .upload-click-area{
477
- display:flex;flex-direction:column;align-items:center;justify-content:center;
478
- cursor:pointer;padding:36px 52px;border:2px dashed #3f3f46;border-radius:16px;
479
- background:rgba(30,144,255,.03);transition:all .2s ease;gap:8px;
480
- }
481
- .upload-click-area:hover{background:rgba(30,144,255,.08);border-color:#1E90FF;transform:scale(1.03)}
482
- .upload-click-area:active{background:rgba(30,144,255,.12);transform:scale(.98)}
483
- .upload-click-area svg{width:80px;height:80px}
484
- .upload-main-text{color:#71717a;font-size:14px;font-weight:500;margin-top:4px}
485
- .upload-sub-text{color:#52525b;font-size:12px;text-align:center;max-width:280px;line-height:1.5}
486
-
487
- /* ── Gallery grid ── */
488
- .image-gallery-grid{
489
- display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));
490
- gap:12px;padding:16px;align-content:start;
491
- }
492
- .gallery-thumb{
493
- position:relative;aspect-ratio:1;border-radius:10px;overflow:hidden;
494
- cursor:pointer;border:2px solid #27272a;transition:all .2s ease;background:#18181b;
495
- }
496
- .gallery-thumb:hover{border-color:#3f3f46;transform:translateY(-2px);box-shadow:0 4px 12px rgba(0,0,0,.4)}
497
- .gallery-thumb.selected{border-color:#1E90FF!important;box-shadow:0 0 0 3px rgba(30,144,255,.2)}
498
- .gallery-thumb img{width:100%;height:100%;object-fit:cover}
499
- .thumb-badge{
500
- position:absolute;top:6px;left:6px;background:#1E90FF;color:#fff;
501
- padding:2px 8px;border-radius:4px;font-family:'JetBrains Mono',monospace;font-size:11px;font-weight:600;
502
- }
503
- .thumb-remove{
504
- position:absolute;top:6px;right:6px;width:24px;height:24px;background:rgba(0,0,0,.75);
505
- color:#fff;border:1px solid rgba(255,255,255,.15);border-radius:50%;cursor:pointer;
506
- display:none;align-items:center;justify-content:center;font-size:12px;transition:all .15s;line-height:1;
507
- }
508
- .gallery-thumb:hover .thumb-remove{display:flex}
509
- .thumb-remove:hover{background:#1E90FF;border-color:#1E90FF}
510
- .gallery-add-card{
511
- aspect-ratio:1;border-radius:10px;border:2px dashed #3f3f46;
512
- display:flex;flex-direction:column;align-items:center;justify-content:center;
513
- cursor:pointer;transition:all .2s ease;background:rgba(30,144,255,.03);gap:4px;
514
- }
515
- .gallery-add-card:hover{border-color:#1E90FF;background:rgba(30,144,255,.08)}
516
- .gallery-add-card .add-icon{font-size:28px;color:#71717a;font-weight:300}
517
- .gallery-add-card .add-text{font-size:12px;color:#71717a;font-weight:500}
518
-
519
- /* ── Hint bar ── */
520
- .hint-bar{
521
- background:rgba(30,144,255,.06);border-top:1px solid #27272a;border-bottom:1px solid #27272a;
522
- padding:10px 20px;font-size:13px;color:#a1a1aa;line-height:1.7;
523
- }
524
- .hint-bar b{color:#7CB8FF;font-weight:600}
525
- .hint-bar kbd{
526
- display:inline-block;padding:1px 6px;background:#27272a;border:1px solid #3f3f46;
527
- border-radius:4px;font-family:'JetBrains Mono',monospace;font-size:11px;color:#a1a1aa;
528
- }
529
-
530
- /* ── Suggestions ── */
531
- .suggestions-section{border-top:1px solid #27272a;padding:12px 16px}
532
- .suggestions-title,.examples-title{
533
- font-size:12px;font-weight:600;color:#71717a;text-transform:uppercase;
534
- letter-spacing:.8px;margin-bottom:10px;
535
- }
536
- .suggestions-wrap{display:flex;flex-wrap:wrap;gap:6px}
537
- .suggestion-chip{
538
- display:inline-flex;align-items:center;gap:4px;padding:5px 12px;
539
- background:rgba(30,144,255,.08);border:1px solid rgba(30,144,255,.2);border-radius:20px;
540
- color:#7CB8FF;font-size:12px;font-weight:500;font-family:'Inter',sans-serif;
541
- cursor:pointer;transition:all .15s;white-space:nowrap;
542
- }
543
- .suggestion-chip:hover{background:rgba(30,144,255,.15);border-color:rgba(30,144,255,.35);color:#47A3FF;transform:translateY(-1px)}
544
-
545
- /* ── Examples ── */
546
- .examples-section{border-top:1px solid #27272a;padding:12px 16px}
547
- .examples-scroll{display:flex;gap:10px;overflow-x:auto;padding-bottom:8px}
548
- .examples-scroll::-webkit-scrollbar{height:6px}
549
- .examples-scroll::-webkit-scrollbar-track{background:#09090b;border-radius:3px}
550
- .examples-scroll::-webkit-scrollbar-thumb{background:#27272a;border-radius:3px}
551
- .examples-scroll::-webkit-scrollbar-thumb:hover{background:#3f3f46}
552
- .example-card{
553
- flex-shrink:0;width:220px;background:#09090b;border:1px solid #27272a;
554
- border-radius:10px;overflow:hidden;cursor:pointer;transition:all .2s ease;
555
- }
556
- .example-card:hover{border-color:#1E90FF;transform:translateY(-2px);box-shadow:0 4px 12px rgba(30,144,255,.15)}
557
- .example-card.loading{opacity:.5;pointer-events:none}
558
- .example-thumbs{display:flex;height:110px;overflow:hidden;background:#18181b}
559
- .example-thumbs img{flex:1;object-fit:cover;min-width:0;border-bottom:1px solid #27272a}
560
- .example-thumb-placeholder{
561
- flex:1;display:flex;align-items:center;justify-content:center;
562
- background:#18181b;color:#3f3f46;font-size:11px;min-width:0;
563
- }
564
- .example-meta{padding:6px 10px 2px;display:flex;align-items:center;gap:5px;flex-wrap:wrap}
565
- .example-badge{
566
- display:inline-flex;padding:2px 7px;background:rgba(30,144,255,.1);border-radius:4px;
567
- font-size:10px;font-weight:600;color:#47A3FF;font-family:'JetBrains Mono',monospace;white-space:nowrap;
568
- }
569
- .example-lora-badge{
570
- display:inline-flex;padding:2px 7px;background:rgba(255,255,255,.06);border-radius:4px;
571
- font-size:10px;font-weight:600;color:#a1a1aa;font-family:'JetBrains Mono',monospace;
572
- white-space:nowrap;border:1px solid #27272a;max-width:130px;overflow:hidden;text-overflow:ellipsis;
573
- }
574
- .example-prompt-text{
575
- padding:4px 10px 8px;font-size:11px;color:#a1a1aa;line-height:1.4;
576
- display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
577
- }
578
-
579
- /* ── Right panel ── */
580
- .panel-card{border-bottom:1px solid #27272a}
581
- .panel-card-title{
582
- padding:12px 20px;font-size:12px;font-weight:600;color:#71717a;
583
- text-transform:uppercase;letter-spacing:.8px;border-bottom:1px solid rgba(39,39,42,.6);
584
- }
585
- .panel-card-body{padding:16px 20px;display:flex;flex-direction:column;gap:8px}
586
- .modern-label{font-size:13px;font-weight:500;color:#a1a1aa;margin-bottom:4px;display:block}
587
- .modern-textarea{
588
- width:100%;background:#09090b;border:1px solid #27272a;border-radius:8px;
589
- padding:10px 14px;font-family:'Inter',sans-serif;font-size:14px;color:#e4e4e7;
590
- resize:vertical;outline:none;min-height:42px;transition:border-color .2s;
591
- }
592
- .modern-textarea:focus{border-color:#1E90FF;box-shadow:0 0 0 3px rgba(30,144,255,.15)}
593
- .modern-textarea::placeholder{color:#3f3f46}
594
- .modern-textarea.error-flash{
595
- border-color:#ef4444!important;box-shadow:0 0 0 3px rgba(239,68,68,.2)!important;animation:shake .4s ease;
596
- }
597
- @keyframes shake{0%,100%{transform:translateX(0)}20%,60%{transform:translateX(-4px)}40%,80%{transform:translateX(4px)}}
598
-
599
- /* ── LoRA selector ── */
600
- .lora-selector-card{border-bottom:1px solid #27272a!important;background:#0f0f13!important}
601
- .lora-selector-body{padding:14px 20px!important;background:#0f0f13!important}
602
- .lora-select-label{
603
- font-size:12px!important;font-weight:600!important;
604
- color:#71717a!important;-webkit-text-fill-color:#71717a!important;
605
- text-transform:uppercase!important;letter-spacing:.8px!important;
606
- margin-bottom:8px!important;display:flex!important;align-items:center!important;
607
- gap:6px!important;font-family:'Inter',sans-serif!important;
608
- }
609
- .lora-select-label::before{
610
- content:'';display:inline-block;width:8px;height:8px;
611
- background:#1E90FF;border-radius:50%;flex-shrink:0;
612
- }
613
- .lora-native-select{
614
- width:100%!important;background:#09090b!important;
615
- border:1px solid #3f3f46!important;border-radius:8px!important;
616
- padding:9px 36px 9px 14px!important;
617
- font-family:'Inter',sans-serif!important;
618
- font-size:13px!important;font-weight:600!important;
619
- color:#e4e4e7!important;-webkit-text-fill-color:#e4e4e7!important;
620
- outline:none!important;appearance:none!important;-webkit-appearance:none!important;
621
- background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%231E90FF' d='M6 8L1 3h10z'/%3E%3C/svg%3E")!important;
622
- background-repeat:no-repeat!important;background-position:right 12px center!important;
623
- cursor:pointer!important;transition:border-color .2s!important;color-scheme:dark!important;
624
- }
625
- .lora-native-select:focus{border-color:#1E90FF!important;box-shadow:0 0 0 3px rgba(30,144,255,.15)!important}
626
- .lora-native-select option{background:#18181b!important;color:#e4e4e7!important}
627
-
628
- @media (prefers-color-scheme: light){
629
- .lora-selector-card{background:#0f0f13!important}
630
- .lora-selector-body{background:#0f0f13!important}
631
- .lora-select-label{color:#71717a!important;-webkit-text-fill-color:#71717a!important}
632
- .lora-native-select{
633
- background:#09090b!important;color:#e4e4e7!important;
634
- -webkit-text-fill-color:#e4e4e7!important;
635
- border-color:#3f3f46!important;color-scheme:dark!important;
636
- }
637
- .lora-native-select option{background:#18181b!important;color:#e4e4e7!important}
638
- }
639
-
640
- /* ── Toast ── */
641
- .toast-notification{
642
- position:fixed;top:24px;left:50%;transform:translateX(-50%) translateY(-120%);
643
- z-index:9999;padding:10px 24px;border-radius:10px;font-family:'Inter',sans-serif;
644
- font-size:14px;font-weight:600;display:flex;align-items:center;gap:8px;
645
- box-shadow:0 8px 24px rgba(0,0,0,.5);
646
- transition:transform .35s cubic-bezier(.34,1.56,.64,1),opacity .35s ease;opacity:0;pointer-events:none;
647
- }
648
- .toast-notification.visible{transform:translateX(-50%) translateY(0);opacity:1;pointer-events:auto}
649
- .toast-notification.error{background:linear-gradient(135deg,#dc2626,#b91c1c);color:#fff;border:1px solid rgba(255,255,255,.15)}
650
- .toast-notification.warning{background:linear-gradient(135deg,#d97706,#b45309);color:#fff;border:1px solid rgba(255,255,255,.15)}
651
- .toast-notification.info{background:linear-gradient(135deg,#2563eb,#1d4ed8);color:#fff;border:1px solid rgba(255,255,255,.15)}
652
- .toast-notification .toast-icon{font-size:16px;line-height:1}
653
- .toast-notification .toast-text{line-height:1.3}
654
-
655
- /* ── Run button ── */
656
- .btn-run{
657
- display:flex;align-items:center;justify-content:center;gap:8px;width:100%;
658
- background:linear-gradient(135deg,#1E90FF,#1873CC);border:none;border-radius:10px;
659
- padding:12px 24px;cursor:pointer;font-size:15px;font-weight:600;font-family:'Inter',sans-serif;
660
- color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;transition:all .2s ease;letter-spacing:-.2px;
661
- box-shadow:0 4px 16px rgba(30,144,255,.3),inset 0 1px 0 rgba(255,255,255,.1);
662
- }
663
- .btn-run:hover{
664
- background:linear-gradient(135deg,#47A3FF,#1E90FF);transform:translateY(-1px);
665
- box-shadow:0 6px 24px rgba(30,144,255,.45),inset 0 1px 0 rgba(255,255,255,.15);
666
- }
667
- .btn-run:active{transform:translateY(0);box-shadow:0 2px 8px rgba(30,144,255,.3)}
668
- .btn-run svg{width:18px;height:18px;fill:#ffffff!important}
669
- .btn-run svg path{fill:#ffffff!important}
670
- #custom-run-btn,#custom-run-btn *,#custom-run-btn span,#custom-run-btn svg,
671
- #custom-run-btn svg path,#run-btn-label,.btn-run,.btn-run *{
672
- color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;fill:#ffffff!important;
673
- }
674
- body:not(.dark) .btn-run,body:not(.dark) .btn-run *,body:not(.dark) #custom-run-btn,
675
- body:not(.dark) #custom-run-btn *{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;fill:#ffffff!important}
676
- .dark .btn-run,.dark .btn-run *,.dark #custom-run-btn,.dark #custom-run-btn *{
677
- color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;fill:#ffffff!important;
678
- }
679
- .gradio-container .btn-run,.gradio-container .btn-run *,.gradio-container #custom-run-btn,
680
- .gradio-container #custom-run-btn *{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;fill:#ffffff!important}
681
-
682
- /* ── Output ── */
683
- .output-frame{border-bottom:1px solid #27272a;display:flex;flex-direction:column;position:relative}
684
- .output-frame .out-title{
685
- padding:10px 20px;font-size:13px;font-weight:700;color:#ffffff!important;
686
- -webkit-text-fill-color:#ffffff!important;text-transform:uppercase;letter-spacing:.8px;
687
- border-bottom:1px solid rgba(39,39,42,.6);display:flex;align-items:center;justify-content:space-between;
688
- }
689
- .output-frame .out-title span{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important}
690
- .output-frame .out-body{
691
- flex:1;background:#09090b;display:flex;align-items:center;justify-content:center;
692
- overflow:hidden;min-height:240px;position:relative;
693
- }
694
- .output-frame .out-body img{max-width:100%;max-height:460px;image-rendering:auto}
695
- .output-frame .out-placeholder{color:#3f3f46;font-size:13px;text-align:center;padding:20px}
696
- .out-download-btn{
697
- display:none;align-items:center;justify-content:center;background:rgba(30,144,255,.1);
698
- border:1px solid rgba(30,144,255,.2);border-radius:6px;cursor:pointer;padding:3px 10px;
699
- font-size:11px;font-weight:500;color:#7CB8FF!important;gap:4px;height:24px;transition:all .15s;
700
- }
701
- .out-download-btn:hover{background:rgba(30,144,255,.2);border-color:rgba(30,144,255,.35);color:#ffffff!important}
702
- .out-download-btn.visible{display:inline-flex}
703
- .out-download-btn svg{width:12px;height:12px;fill:#7CB8FF}
704
- .out-download-btn:hover svg{fill:#ffffff}
705
-
706
- /* ── Loader ── */
707
- .modern-loader{
708
- display:none;position:absolute;top:0;left:0;right:0;bottom:0;background:rgba(9,9,11,.92);
709
- z-index:15;flex-direction:column;align-items:center;justify-content:center;gap:16px;backdrop-filter:blur(4px);
710
- }
711
- .modern-loader.active{display:flex}
712
- .modern-loader .loader-spinner{
713
- width:36px;height:36px;border:3px solid #27272a;border-top-color:#1E90FF;
714
- border-radius:50%;animation:spin .8s linear infinite;
715
- }
716
- @keyframes spin{to{transform:rotate(360deg)}}
717
- .modern-loader .loader-text{font-size:13px;color:#a1a1aa;font-weight:500}
718
- .loader-bar-track{width:200px;height:4px;background:#27272a;border-radius:2px;overflow:hidden}
719
- .loader-bar-fill{
720
- height:100%;background:linear-gradient(90deg,#1E90FF,#47A3FF,#1E90FF);
721
- background-size:200% 100%;animation:shimmer 1.5s ease-in-out infinite;border-radius:2px;
722
- }
723
- @keyframes shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}
724
-
725
- /* ── Settings ── */
726
- .settings-group{border:1px solid #27272a;border-radius:10px;margin:12px 16px;padding:0;overflow:hidden}
727
- .settings-group-title{
728
- font-size:12px;font-weight:600;color:#71717a;text-transform:uppercase;letter-spacing:.8px;
729
- padding:10px 16px;border-bottom:1px solid #27272a;background:rgba(24,24,27,.5);
730
- }
731
- .settings-group-body{padding:14px 16px;display:flex;flex-direction:column;gap:12px}
732
- .slider-row{display:flex;align-items:center;gap:10px;min-height:28px}
733
- .slider-row label{font-size:13px;font-weight:500;color:#a1a1aa;min-width:72px;flex-shrink:0}
734
- .slider-row input[type="range"]{
735
- flex:1;-webkit-appearance:none;appearance:none;height:6px;background:#27272a;
736
- border-radius:3px;outline:none;min-width:0;
737
- }
738
- .slider-row input[type="range"]::-webkit-slider-thumb{
739
- -webkit-appearance:none;width:16px;height:16px;background:linear-gradient(135deg,#1E90FF,#1873CC);
740
- border-radius:50%;cursor:pointer;box-shadow:0 2px 6px rgba(30,144,255,.4);transition:transform .15s;
741
- }
742
- .slider-row input[type="range"]::-webkit-slider-thumb:hover{transform:scale(1.2)}
743
- .slider-row input[type="range"]::-moz-range-thumb{
744
- width:16px;height:16px;background:linear-gradient(135deg,#1E90FF,#1873CC);
745
- border-radius:50%;cursor:pointer;border:none;box-shadow:0 2px 6px rgba(30,144,255,.4);
746
- }
747
- .slider-row .slider-val{
748
- min-width:52px;text-align:right;font-family:'JetBrains Mono',monospace;font-size:12px;
749
- font-weight:500;padding:3px 8px;background:#09090b;border:1px solid #27272a;
750
- border-radius:6px;color:#a1a1aa;flex-shrink:0;
751
- }
752
- .checkbox-row{display:flex;align-items:center;gap:8px;font-size:13px;color:#a1a1aa}
753
- .checkbox-row input[type="checkbox"]{accent-color:#1E90FF;width:16px;height:16px;cursor:pointer}
754
- .checkbox-row label{color:#a1a1aa;font-size:13px;cursor:pointer}
755
-
756
- /* ── Status bar ── */
757
- .app-statusbar{
758
- background:#18181b;border-top:1px solid #27272a;padding:6px 20px;
759
- display:flex;gap:12px;height:34px;align-items:center;font-size:12px;
760
- }
761
- .app-statusbar .sb-section{
762
- padding:0 12px;flex:1;display:flex;align-items:center;font-family:'JetBrains Mono',monospace;
763
- font-size:12px;color:#52525b;overflow:hidden;white-space:nowrap;
764
- }
765
- .app-statusbar .sb-section.sb-fixed{
766
- flex:0 0 auto;min-width:90px;text-align:center;justify-content:center;
767
- padding:3px 12px;background:rgba(30,144,255,.08);border-radius:6px;color:#47A3FF;font-weight:500;
768
- }
769
-
770
- /* ── Footer note ── */
771
- .exp-note{
772
- padding:10px 20px;font-size:12px;color:#52525b;
773
- border-top:1px solid #27272a;text-align:center;font-weight:500;
774
- background:#18181b;font-family:'Inter',sans-serif;
775
- }
776
- .exp-note a{color:#47A3FF;text-decoration:none}
777
- .exp-note a:hover{text-decoration:underline}
778
-
779
- /* ── Dark overrides ── */
780
- .dark .app-shell{background:#18181b}
781
- .dark .upload-prompt-modern{background:transparent}
782
- .dark .panel-card{background:#18181b}
783
- .dark .settings-group{background:#18181b}
784
- .dark .output-frame .out-title{color:#ffffff!important}
785
- .dark .output-frame .out-title span{color:#ffffff!important}
786
- .dark .out-download-btn{color:#7CB8FF!important}
787
- .dark .out-download-btn:hover{color:#ffffff!important}
788
-
789
- /* ── Scrollbars ── */
790
- ::-webkit-scrollbar{width:8px;height:8px}
791
- ::-webkit-scrollbar-track{background:#09090b}
792
- ::-webkit-scrollbar-thumb{background:#27272a;border-radius:4px}
793
- ::-webkit-scrollbar-thumb:hover{background:#3f3f46}
794
-
795
- /* ── Responsive ── */
796
- @media(max-width:860px){
797
- .app-main-row{flex-direction:column}
798
- .app-main-right{width:100%}
799
- .app-main-left{border-right:none;border-bottom:1px solid #27272a}
800
- }
801
- """
802
-
803
- gallery_js = r"""
804
- () => {
805
- function init() {
806
- if (window.__qwenInitDone) return;
807
-
808
- const galleryGrid = document.getElementById('image-gallery-grid');
809
- const dropZone = document.getElementById('gallery-drop-zone');
810
- const uploadPrompt = document.getElementById('upload-prompt');
811
- const uploadClick = document.getElementById('upload-click-area');
812
- const fileInput = document.getElementById('custom-file-input');
813
- const btnUpload = document.getElementById('tb-upload');
814
- const btnRemove = document.getElementById('tb-remove');
815
- const btnClear = document.getElementById('tb-clear');
816
- const promptInput = document.getElementById('custom-prompt-input');
817
- const loraSelect = document.getElementById('custom-lora-select');
818
- const runBtnEl = document.getElementById('custom-run-btn');
819
- const imgCountTb = document.getElementById('tb-image-count');
820
- const imgCountSb = document.getElementById('sb-image-count');
821
-
822
- if (!galleryGrid || !fileInput || !dropZone) { setTimeout(init, 250); return; }
823
- window.__qwenInitDone = true;
824
-
825
- let images = [];
826
- window.__uploadedImages = images;
827
- let selectedIdx = -1;
828
- let toastTimer = null;
829
-
830
- /* ── Force dark + blue styles on elements that browsers may override ── */
831
- function enforceDarkStyles() {
832
- const loraCard = document.querySelector('.lora-selector-card');
833
- const loraBody = document.querySelector('.lora-selector-body');
834
- const loraLabel = document.querySelector('.lora-select-label');
835
- const loraEl = document.getElementById('custom-lora-select');
836
- if (loraCard) { loraCard.style.setProperty('background','#0f0f13','important'); }
837
- if (loraBody) { loraBody.style.setProperty('background','#0f0f13','important'); }
838
- if (loraLabel) {
839
- loraLabel.style.setProperty('color','#71717a','important');
840
- loraLabel.style.setProperty('-webkit-text-fill-color','#71717a','important');
841
- }
842
- if (loraEl) {
843
- loraEl.style.setProperty('background-color','#09090b','important');
844
- loraEl.style.setProperty('color','#e4e4e7','important');
845
- loraEl.style.setProperty('-webkit-text-fill-color','#e4e4e7','important');
846
- loraEl.style.setProperty('border-color','#3f3f46','important');
847
- }
848
-
849
- const ghBtn = document.querySelector('.gh-btn');
850
- if (ghBtn) {
851
- ghBtn.style.setProperty('background','#1E90FF','important');
852
- ghBtn.style.setProperty('color','#ffffff','important');
853
- ghBtn.style.setProperty('-webkit-text-fill-color','#ffffff','important');
854
- ghBtn.style.setProperty('border-color','rgba(255,255,255,.18)','important');
855
- ghBtn.style.setProperty('box-shadow','0 2px 10px rgba(30,144,255,.45)','important');
856
- const svg = ghBtn.querySelector('svg');
857
- if (svg) svg.style.setProperty('fill','#ffffff','important');
858
- const span = ghBtn.querySelector('span');
859
- if (span) {
860
- span.style.setProperty('color','#ffffff','important');
861
- span.style.setProperty('-webkit-text-fill-color','#ffffff','important');
862
- }
863
- }
864
-
865
- const shell = document.querySelector('.app-shell');
866
- const header = document.querySelector('.app-header');
867
- const toolbar = document.querySelector('.app-toolbar');
868
- if (shell) shell.style.setProperty('background','#18181b','important');
869
- if (header) header.style.setProperty('background','#18181b','important');
870
- if (toolbar) toolbar.style.setProperty('background','#18181b','important');
871
- }
872
-
873
- enforceDarkStyles();
874
- setInterval(enforceDarkStyles, 1000);
875
-
876
- const ghBtn = document.querySelector('.gh-btn');
877
- if (ghBtn) {
878
- ghBtn.addEventListener('mouseenter', () => {
879
- ghBtn.style.setProperty('background','#47A3FF','important');
880
- ghBtn.style.setProperty('color','#ffffff','important');
881
- ghBtn.style.setProperty('-webkit-text-fill-color','#ffffff','important');
882
- ghBtn.style.setProperty('transform','translateY(-1px)','important');
883
- ghBtn.style.setProperty('box-shadow','0 5px 18px rgba(30,144,255,.6)','important');
884
- });
885
- ghBtn.addEventListener('mouseleave', () => {
886
- ghBtn.style.setProperty('background','#1E90FF','important');
887
- ghBtn.style.setProperty('color','#ffffff','important');
888
- ghBtn.style.setProperty('-webkit-text-fill-color','#ffffff','important');
889
- ghBtn.style.setProperty('transform','translateY(0)','important');
890
- ghBtn.style.setProperty('box-shadow','0 2px 10px rgba(30,144,255,.45)','important');
891
- });
892
- ghBtn.addEventListener('mousedown', () => {
893
- ghBtn.style.setProperty('background','#1873CC','important');
894
- ghBtn.style.setProperty('transform','translateY(0)','important');
895
- });
896
- ghBtn.addEventListener('mouseup', () => {
897
- ghBtn.style.setProperty('background','#47A3FF','important');
898
- });
899
- }
900
-
901
- function showToast(message, type) {
902
- let toast = document.getElementById('app-toast');
903
- if (!toast) {
904
- toast = document.createElement('div');
905
- toast.id = 'app-toast';
906
- toast.className = 'toast-notification';
907
- toast.innerHTML = '<span class="toast-icon"></span><span class="toast-text"></span>';
908
- document.body.appendChild(toast);
909
- }
910
- const icon = toast.querySelector('.toast-icon');
911
- const text = toast.querySelector('.toast-text');
912
- toast.className = 'toast-notification ' + (type || 'error');
913
- icon.textContent = type === 'warning' ? '\u26A0' : type === 'info' ? '\u2139' : '\u2717';
914
- text.textContent = message;
915
- if (toastTimer) clearTimeout(toastTimer);
916
- void toast.offsetWidth;
917
- toast.classList.add('visible');
918
- toastTimer = setTimeout(() => toast.classList.remove('visible'), 3500);
919
- }
920
- window.__showToast = showToast;
921
-
922
- function flashPromptError() {
923
- if (!promptInput) return;
924
- promptInput.classList.add('error-flash');
925
- promptInput.focus();
926
- setTimeout(() => promptInput.classList.remove('error-flash'), 800);
927
- }
928
-
929
- function setGradioValue(containerId, value) {
930
- const container = document.getElementById(containerId);
931
- if (!container) return;
932
- container.querySelectorAll('input, textarea').forEach(el => {
933
- if (el.type === 'file' || el.type === 'range' || el.type === 'checkbox') return;
934
- const proto = el.tagName === 'TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
935
- const ns = Object.getOwnPropertyDescriptor(proto, 'value');
936
- if (ns && ns.set) {
937
- ns.set.call(el, value);
938
- el.dispatchEvent(new Event('input', {bubbles:true, composed:true}));
939
- el.dispatchEvent(new Event('change', {bubbles:true, composed:true}));
940
- }
941
- });
942
- }
943
- window.__setGradioValue = setGradioValue;
944
-
945
- function syncImagesToGradio() {
946
- window.__uploadedImages = images;
947
- const b64Array = images.map(img => img.b64);
948
- setGradioValue('hidden-images-b64', JSON.stringify(b64Array));
949
- updateCounts();
950
- }
951
- function syncPromptToGradio() {
952
- if (promptInput) setGradioValue('prompt-gradio-input', promptInput.value);
953
- }
954
- function syncLoraToGradio() {
955
- if (!loraSelect) return;
956
- const container = document.getElementById('gradio-lora');
957
- if (!container) return;
958
- container.querySelectorAll('input').forEach(el => {
959
- const ns = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
960
- if (ns && ns.set) {
961
- ns.set.call(el, loraSelect.value);
962
- el.dispatchEvent(new Event('input', {bubbles:true, composed:true}));
963
- el.dispatchEvent(new Event('change', {bubbles:true, composed:true}));
964
- }
965
- });
966
- }
967
-
968
- function updateCounts() {
969
- const n = images.length;
970
- const txt = n > 0 ? n + ' image' + (n > 1 ? 's' : '') : 'No images';
971
- if (imgCountTb) imgCountTb.textContent = txt;
972
- if (imgCountSb) imgCountSb.textContent = n > 0 ? txt + ' uploaded' : 'No images uploaded';
973
- }
974
-
975
- function addImage(b64, name) {
976
- images.push({id: Date.now() + Math.random(), b64, name});
977
- renderGallery(); syncImagesToGradio();
978
- }
979
- window.__addImage = addImage;
980
-
981
- function removeImage(idx) {
982
- images.splice(idx, 1);
983
- if (selectedIdx === idx) selectedIdx = -1;
984
- else if (selectedIdx > idx) selectedIdx--;
985
- renderGallery(); syncImagesToGradio();
986
- }
987
-
988
- function clearAll() {
989
- images = []; window.__uploadedImages = images; selectedIdx = -1;
990
- renderGallery(); syncImagesToGradio();
991
- }
992
- window.__clearAll = clearAll;
993
-
994
- function renderGallery() {
995
- if (images.length === 0) {
996
- galleryGrid.innerHTML = ''; galleryGrid.style.display = 'none';
997
- if (uploadPrompt) uploadPrompt.style.display = '';
998
- return;
999
- }
1000
- if (uploadPrompt) uploadPrompt.style.display = 'none';
1001
- galleryGrid.style.display = 'grid';
1002
- let html = '';
1003
- images.forEach((img, i) => {
1004
- const sel = i === selectedIdx ? ' selected' : '';
1005
- html += '<div class="gallery-thumb' + sel + '" data-idx="' + i + '">'
1006
- + '<img src="' + img.b64 + '" alt="' + (img.name||'image') + '">'
1007
- + '<span class="thumb-badge">#' + (i+1) + '</span>'
1008
- + '<button class="thumb-remove" data-remove="' + i + '">\u2715</button>'
1009
- + '</div>';
1010
- });
1011
- html += '<div class="gallery-add-card" id="gallery-add-card"><span class="add-icon">+</span><span class="add-text">Add</span></div>';
1012
- galleryGrid.innerHTML = html;
1013
- galleryGrid.querySelectorAll('.gallery-thumb').forEach(thumb => {
1014
- thumb.addEventListener('click', (e) => {
1015
- if (e.target.closest('.thumb-remove')) return;
1016
- selectedIdx = (selectedIdx === parseInt(thumb.dataset.idx)) ? -1 : parseInt(thumb.dataset.idx);
1017
- renderGallery();
1018
- });
1019
- });
1020
- galleryGrid.querySelectorAll('.thumb-remove').forEach(btn => {
1021
- btn.addEventListener('click', (e) => { e.stopPropagation(); removeImage(parseInt(btn.dataset.remove)); });
1022
- });
1023
- const addCard = document.getElementById('gallery-add-card');
1024
- if (addCard) addCard.addEventListener('click', () => fileInput.click());
1025
- }
1026
-
1027
- function processFiles(files) {
1028
- Array.from(files).forEach(file => {
1029
- if (!file.type.startsWith('image/')) return;
1030
- const reader = new FileReader();
1031
- reader.onload = (e) => addImage(e.target.result, file.name);
1032
- reader.readAsDataURL(file);
1033
- });
1034
- }
1035
-
1036
- fileInput.addEventListener('change', (e) => { processFiles(e.target.files); e.target.value = ''; });
1037
- if (uploadClick) uploadClick.addEventListener('click', () => fileInput.click());
1038
- if (btnUpload) btnUpload.addEventListener('click', () => fileInput.click());
1039
- if (btnRemove) btnRemove.addEventListener('click', () => { if (selectedIdx >= 0) removeImage(selectedIdx); });
1040
- if (btnClear) btnClear.addEventListener('click', clearAll);
1041
-
1042
- dropZone.addEventListener('dragover', (e) => { e.preventDefault(); dropZone.classList.add('drag-over'); });
1043
- dropZone.addEventListener('dragleave', (e) => { e.preventDefault(); dropZone.classList.remove('drag-over'); });
1044
- dropZone.addEventListener('drop', (e) => {
1045
- e.preventDefault(); dropZone.classList.remove('drag-over');
1046
- if (e.dataTransfer.files.length) processFiles(e.dataTransfer.files);
1047
- });
1048
-
1049
- if (promptInput) promptInput.addEventListener('input', syncPromptToGradio);
1050
- if (loraSelect) loraSelect.addEventListener('change', syncLoraToGradio);
1051
-
1052
- window.__setPrompt = function(text) { if (promptInput) { promptInput.value = text; syncPromptToGradio(); } };
1053
- window.__setLora = function(lora) {
1054
- if (loraSelect) {
1055
- loraSelect.value = lora;
1056
- loraSelect.dispatchEvent(new Event('change', {bubbles:true}));
1057
- syncLoraToGradio();
1058
- }
1059
- };
1060
-
1061
- document.querySelectorAll('.example-card[data-idx]').forEach(card => {
1062
- card.addEventListener('click', () => {
1063
- const idx = card.getAttribute('data-idx');
1064
- document.querySelectorAll('.example-card.loading').forEach(c => c.classList.remove('loading'));
1065
- card.classList.add('loading');
1066
- showToast('Loading example\u2026', 'info');
1067
- setGradioValue('example-result-data', '');
1068
- setGradioValue('example-idx-input', idx);
1069
- setTimeout(() => {
1070
- const btn = document.getElementById('example-load-btn');
1071
- if (btn) { const b = btn.querySelector('button'); if (b) b.click(); else btn.click(); }
1072
- }, 150);
1073
- setTimeout(() => card.classList.remove('loading'), 12000);
1074
- });
1075
- });
1076
-
1077
- function syncSlider(customId, gradioId) {
1078
- const slider = document.getElementById(customId);
1079
- const valSpan = document.getElementById(customId + '-val');
1080
- if (!slider) return;
1081
- slider.addEventListener('input', () => {
1082
- if (valSpan) valSpan.textContent = slider.value;
1083
- const container = document.getElementById(gradioId);
1084
- if (!container) return;
1085
- container.querySelectorAll('input[type="range"],input[type="number"]').forEach(el => {
1086
- const ns = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
1087
- if (ns && ns.set) {
1088
- ns.set.call(el, slider.value);
1089
- el.dispatchEvent(new Event('input', {bubbles:true, composed:true}));
1090
- el.dispatchEvent(new Event('change', {bubbles:true, composed:true}));
1091
- }
1092
- });
1093
- });
1094
- }
1095
- syncSlider('custom-seed', 'gradio-seed');
1096
- syncSlider('custom-guidance', 'gradio-guidance');
1097
- syncSlider('custom-steps', 'gradio-steps');
1098
-
1099
- const randCheck = document.getElementById('custom-randomize');
1100
- if (randCheck) {
1101
- randCheck.addEventListener('change', () => {
1102
- const container = document.getElementById('gradio-randomize');
1103
- if (!container) return;
1104
- const cb = container.querySelector('input[type="checkbox"]');
1105
- if (cb && cb.checked !== randCheck.checked) cb.click();
1106
- });
1107
- }
1108
-
1109
- function showLoader() {
1110
- const l = document.getElementById('output-loader');
1111
- if (l) l.classList.add('active');
1112
- const sb = document.querySelector('.sb-fixed');
1113
- if (sb) sb.textContent = 'Processing\u2026';
1114
- }
1115
- function hideLoader() {
1116
- const l = document.getElementById('output-loader');
1117
- if (l) l.classList.remove('active');
1118
- const sb = document.querySelector('.sb-fixed');
1119
- if (sb) sb.textContent = 'Done';
1120
- }
1121
- window.__showLoader = showLoader;
1122
- window.__hideLoader = hideLoader;
1123
-
1124
- function validateBeforeRun() {
1125
- const promptVal = promptInput ? promptInput.value.trim() : '';
1126
- const hasImages = images.length > 0;
1127
- if (!hasImages && !promptVal) { showToast('Please upload an image and enter a prompt', 'error'); flashPromptError(); return false; }
1128
- if (!hasImages) { showToast('Please upload at least one image', 'error'); return false; }
1129
- if (!promptVal) { showToast('Please enter an edit prompt', 'warning'); flashPromptError(); return false; }
1130
- return true;
1131
- }
1132
-
1133
- window.__clickGradioRunBtn = function() {
1134
- if (!validateBeforeRun()) return;
1135
- syncPromptToGradio(); syncImagesToGradio(); syncLoraToGradio(); showLoader();
1136
- setTimeout(() => {
1137
- const gradioBtn = document.getElementById('gradio-run-btn');
1138
- if (!gradioBtn) return;
1139
- const btn = gradioBtn.querySelector('button');
1140
- if (btn) btn.click(); else gradioBtn.click();
1141
- }, 200);
1142
- };
1143
-
1144
- if (runBtnEl) runBtnEl.addEventListener('click', () => window.__clickGradioRunBtn());
1145
-
1146
- renderGallery();
1147
- updateCounts();
1148
- }
1149
- init();
1150
- }
1151
- """
1152
-
1153
- wire_outputs_js = r"""
1154
- () => {
1155
- function watchOutputs() {
1156
- const resultContainer = document.getElementById('gradio-result');
1157
- const outBody = document.getElementById('output-image-container');
1158
- const outPh = document.getElementById('output-placeholder');
1159
- const dlBtn = document.getElementById('dl-btn-output');
1160
-
1161
- if (!resultContainer || !outBody) { setTimeout(watchOutputs, 500); return; }
1162
-
1163
- if (dlBtn) {
1164
- dlBtn.addEventListener('click', (e) => {
1165
- e.stopPropagation();
1166
- const img = outBody.querySelector('img.modern-out-img');
1167
- if (img && img.src) {
1168
- const a = document.createElement('a');
1169
- a.href = img.src; a.download = 'qwen_edit_output.png';
1170
- document.body.appendChild(a); a.click(); document.body.removeChild(a);
1171
- }
1172
- });
1173
- }
1174
-
1175
- function syncImage() {
1176
- const resultImg = resultContainer.querySelector('img');
1177
- if (resultImg && resultImg.src) {
1178
- if (outPh) outPh.style.display = 'none';
1179
- let existing = outBody.querySelector('img.modern-out-img');
1180
- if (!existing) {
1181
- existing = document.createElement('img');
1182
- existing.className = 'modern-out-img';
1183
- outBody.appendChild(existing);
1184
- }
1185
- if (existing.src !== resultImg.src) {
1186
- existing.src = resultImg.src;
1187
- if (dlBtn) dlBtn.classList.add('visible');
1188
- if (window.__hideLoader) window.__hideLoader();
1189
- }
1190
- }
1191
- }
1192
- const observer = new MutationObserver(syncImage);
1193
- observer.observe(resultContainer, {childList:true, subtree:true, attributes:true, attributeFilter:['src']});
1194
- setInterval(syncImage, 800);
1195
- }
1196
- watchOutputs();
1197
-
1198
- function watchSeed() {
1199
- const seedContainer = document.getElementById('gradio-seed');
1200
- const seedSlider = document.getElementById('custom-seed');
1201
- const seedVal = document.getElementById('custom-seed-val');
1202
- if (!seedContainer || !seedSlider) { setTimeout(watchSeed, 500); return; }
1203
- function sync() {
1204
- const el = seedContainer.querySelector('input[type="range"],input[type="number"]');
1205
- if (el && el.value) { seedSlider.value = el.value; if (seedVal) seedVal.textContent = el.value; }
1206
- }
1207
- const obs = new MutationObserver(sync);
1208
- obs.observe(seedContainer, {childList:true, subtree:true, attributes:true, attributeFilter:['value']});
1209
- setInterval(sync, 1000);
1210
- }
1211
- watchSeed();
1212
-
1213
- function watchExampleResults() {
1214
- const container = document.getElementById('example-result-data');
1215
- if (!container) { setTimeout(watchExampleResults, 500); return; }
1216
- let lastProcessed = '';
1217
-
1218
- function checkResult() {
1219
- const el = container.querySelector('textarea') || container.querySelector('input');
1220
- if (!el) return;
1221
- const val = el.value;
1222
- if (!val || val === lastProcessed || val.length < 20) return;
1223
- try {
1224
- const data = JSON.parse(val);
1225
- if (data.status === 'ok' && data.images && data.images.length > 0) {
1226
- lastProcessed = val;
1227
- if (window.__clearAll) window.__clearAll();
1228
- if (window.__setPrompt && data.prompt) window.__setPrompt(data.prompt);
1229
- if (window.__setLora && data.lora) window.__setLora(data.lora);
1230
- data.images.forEach((b64, i) => {
1231
- if (b64 && window.__addImage) {
1232
- const name = (data.names && data.names[i]) ? data.names[i] : ('example_'+(i+1)+'.jpg');
1233
- window.__addImage(b64, name);
1234
- }
1235
- });
1236
- document.querySelectorAll('.example-card.loading').forEach(c => c.classList.remove('loading'));
1237
- if (window.__showToast) window.__showToast('Example loaded \u2014 ' + data.images.length + ' image(s)', 'info');
1238
- } else if (data.status === 'error') {
1239
- document.querySelectorAll('.example-card.loading').forEach(c => c.classList.remove('loading'));
1240
- if (window.__showToast) window.__showToast('Could not load example images', 'error');
1241
- }
1242
- } catch(e) { console.error('Example parse error:', e); }
1243
- }
1244
-
1245
- const obs = new MutationObserver(checkResult);
1246
- obs.observe(container, {childList:true, subtree:true, characterData:true, attributes:true});
1247
- setInterval(checkResult, 500);
1248
- }
1249
- watchExampleResults();
1250
- }
1251
- """
1252
-
1253
- # ── SVG assets (same family/style as the FireRed-Image-Edit app, recolored via CSS) ──
1254
- FIRE_LOGO_SVG = '<svg viewBox="0 0 24 24" fill="white" xmlns="http://www.w3.org/2000/svg"><path d="M12 23c-3.6 0-8-2.69-8-7.5 0-3.5 3-6.5 4.5-8 .27-.27.75-.08.75.28v2.44c0 .42.5.63.72.28C12.28 7.5 13 3 13 1c0-.42.48-.64.8-.35C18 4.5 20 9 20 12c0 5.5-3.5 11-8 11z"/></svg>'
1255
-
1256
- DOWNLOAD_SVG = '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 16l-5-5h3V4h4v7h3l-5 5z"/><path d="M20 18H4v2h16v-2z"/></svg>'
1257
-
1258
- UPLOAD_SVG = '<svg class="tb-svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>'
1259
-
1260
- REMOVE_SVG = '<svg class="tb-svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>'
1261
-
1262
- CLEAR_SVG = '<svg class="tb-svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>'
1263
-
1264
- GITHUB_SVG = '<svg width="15" height="15" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path fill="#ffffff" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>'
1265
-
1266
- LORA_OPTIONS_HTML = "\n".join(
1267
- f'<option value="{html_lib.escape(name)}">{html_lib.escape(name)}</option>'
1268
- for name in ADAPTER_NAMES
1269
- )
1270
-
1271
- # ── Gradio app ─────────────────────────────────────────────────────────────────
1272
- with gr.Blocks() as demo:
1273
-
1274
- hidden_images_b64 = gr.Textbox(value="[]", elem_id="hidden-images-b64", elem_classes="hidden-input", container=False)
1275
- prompt = gr.Textbox(value="", elem_id="prompt-gradio-input", elem_classes="hidden-input", container=False)
1276
- lora_adapter = gr.Dropdown(choices=ADAPTER_NAMES, value="Photo-to-Anime", elem_id="gradio-lora", elem_classes="hidden-input", container=False)
1277
- seed = gr.Slider(minimum=0, maximum=MAX_SEED, step=1, value=0, elem_id="gradio-seed", elem_classes="hidden-input", container=False)
1278
- randomize_seed = gr.Checkbox(value=True, elem_id="gradio-randomize", elem_classes="hidden-input", container=False)
1279
- guidance_scale = gr.Slider(minimum=1.0, maximum=10.0, step=0.1, value=1.0, elem_id="gradio-guidance", elem_classes="hidden-input", container=False)
1280
- steps = gr.Slider(minimum=1, maximum=50, step=1, value=4, elem_id="gradio-steps", elem_classes="hidden-input", container=False)
1281
- result = gr.Image(elem_id="gradio-result", elem_classes="hidden-input", container=False, format="png")
1282
-
1283
- example_idx = gr.Textbox(value="", elem_id="example-idx-input", elem_classes="hidden-input", container=False)
1284
- example_result = gr.Textbox(value="", elem_id="example-result-data", elem_classes="hidden-input", container=False)
1285
- example_load_btn = gr.Button("Load Example", elem_id="example-load-btn")
1286
-
1287
- gr.HTML(f"""
1288
- <div class="app-shell">
1289
-
1290
- <!-- Header -->
1291
- <div class="app-header">
1292
- <div class="app-header-left">
1293
- <div class="app-logo">{FIRE_LOGO_SVG}</div>
1294
- <span class="app-title">Qwen-Image-Edit</span>
1295
- <span class="app-badge">2511</span>
1296
- <span class="app-badge fast">4-Step Fast</span>
1297
- </div>
1298
-
1299
- <a href="https://github.com/PRITHIVSAKTHIUR/Qwen-Image-Edit-2511-LoRAs-Fast-Lazy-Load"
1300
- target="_blank"
1301
- class="gh-btn">
1302
- {GITHUB_SVG}
1303
- <span>GitHub</span>
1304
- </a>
1305
- </div>
1306
-
1307
- <!-- Toolbar -->
1308
- <div class="app-toolbar">
1309
- <button id="tb-upload" class="modern-tb-btn" title="Upload images">
1310
- {UPLOAD_SVG}<span class="tb-label">Upload</span>
1311
- </button>
1312
- <button id="tb-remove" class="modern-tb-btn" title="Remove selected image">
1313
- {REMOVE_SVG}<span class="tb-label">Remove</span>
1314
- </button>
1315
- <button id="tb-clear" class="modern-tb-btn" title="Clear all images">
1316
- {CLEAR_SVG}<span class="tb-label">Clear All</span>
1317
- </button>
1318
- <div class="tb-sep"></div>
1319
- <span id="tb-image-count" class="tb-info">No images</span>
1320
- </div>
1321
-
1322
- <!-- Main row -->
1323
- <div class="app-main-row">
1324
-
1325
- <!-- Left -->
1326
- <div class="app-main-left">
1327
-
1328
- <div id="gallery-drop-zone">
1329
- <div id="upload-prompt" class="upload-prompt-modern">
1330
- <div id="upload-click-area" class="upload-click-area">
1331
- <svg viewBox="0 0 80 80" fill="none" xmlns="http://www.w3.org/2000/svg">
1332
- <rect x="8" y="14" width="64" height="52" rx="6" fill="none"
1333
- stroke="#1E90FF" stroke-width="2" stroke-dasharray="4 3"/>
1334
- <polygon points="12,62 30,40 42,50 54,34 68,62"
1335
- fill="rgba(30,144,255,0.15)" stroke="#1E90FF" stroke-width="1.5"/>
1336
- <circle cx="28" cy="30" r="6"
1337
- fill="rgba(30,144,255,0.2)" stroke="#1E90FF" stroke-width="1.5"/>
1338
- </svg>
1339
- <span class="upload-main-text">Click or drag images here</span>
1340
- <span class="upload-sub-text">Supports multiple images for reference-based editing and guided manipulation</span>
1341
- </div>
1342
- </div>
1343
- <input id="custom-file-input" type="file" accept="image/*" multiple style="display:none;" />
1344
- <div id="image-gallery-grid" class="image-gallery-grid" style="display:none;"></div>
1345
- </div>
1346
-
1347
- <div class="hint-bar">
1348
- <b>Upload:</b> Click or drag images &nbsp;&middot;&nbsp;
1349
- <b>Multi-image:</b> Upload multiple for reference editing &nbsp;&middot;&nbsp;
1350
- <kbd>Remove</kbd> deletes selected &nbsp;&middot;&nbsp;
1351
- <kbd>Clear All</kbd> removes everything
1352
- </div>
1353
-
1354
- <div class="suggestions-section">
1355
- <div class="suggestions-title">Quick Prompts</div>
1356
- <div class="suggestions-wrap">
1357
- <button class="suggestion-chip" onclick="window.__setPrompt('Transform into anime.')">Anime</button>
1358
- <button class="suggestion-chip" onclick="window.__setPrompt('Convert it to black and white.')">B&amp;W</button>
1359
- <button class="suggestion-chip" onclick="window.__setPrompt('Add cinematic lighting with warm orange tones and film grain.')">Cinematic</button>
1360
- <button class="suggestion-chip" onclick="window.__setPrompt('Apply oil painting effect with visible brush strokes.')">Oil Paint</button>
1361
- <button class="suggestion-chip" onclick="window.__setPrompt('Upscale this picture to 4K resolution.')">Upscale 4K</button>
1362
- <button class="suggestion-chip" onclick="window.__setPrompt('Make it look like a watercolor painting with soft edges.')">Watercolor</button>
1363
- <button class="suggestion-chip" onclick="window.__setPrompt('Convert to detailed pencil sketch with cross-hatching and shading.')">Pencil Sketch</button>
1364
- <button class="suggestion-chip" onclick="window.__setPrompt('Apply pop art style with bold colors and halftone patterns.')">Pop Art</button>
1365
- <button class="suggestion-chip" onclick="window.__setPrompt('Apply a vintage retro film look with faded colors and light leaks.')">Vintage Retro</button>
1366
- <button class="suggestion-chip" onclick="window.__setPrompt('Add neon glow effects with vibrant colors against a dark background.')">Neon Glow</button>
1367
- <button class="suggestion-chip" onclick="window.__setPrompt('Convert to pixel art style with a retro 16-bit aesthetic.')">Pixel Art</button>
1368
- <button class="suggestion-chip" onclick="window.__setPrompt('Transform into a noir comic book style.')">Noir Comic</button>
1369
- <button class="suggestion-chip" onclick="window.__setPrompt('Transform into a hyper-realistic face portrait.')">HyperReal</button>
1370
- <button class="suggestion-chip" onclick="window.__setPrompt('Unblur and upscale.')">Unblur</button>
1371
- <button class="suggestion-chip" onclick="window.__setPrompt('Transform into Pixar-inspired 3D.')">Pixar 3D</button>
1372
- <button class="suggestion-chip" onclick="window.__setPrompt('Paint with manga tone.')">Manga Tone</button>
1373
- </div>
1374
- </div>
1375
-
1376
- <div class="examples-section">
1377
- <div class="examples-title">Quick Examples &mdash; click to load</div>
1378
- <div class="examples-scroll">
1379
- {EXAMPLE_CARDS_HTML}
1380
- </div>
1381
- </div>
1382
-
1383
- </div><!-- /left -->
1384
-
1385
- <!-- Right -->
1386
- <div class="app-main-right">
1387
-
1388
- <div class="panel-card">
1389
- <div class="panel-card-title">Edit Instruction</div>
1390
- <div class="panel-card-body">
1391
- <label class="modern-label" for="custom-prompt-input">Prompt</label>
1392
- <textarea id="custom-prompt-input" class="modern-textarea" rows="3"
1393
- placeholder="e.g., transform into anime, upscale, change lighting&hellip;"></textarea>
1394
- </div>
1395
- </div>
1396
-
1397
- <div class="lora-selector-card">
1398
- <div class="lora-selector-body">
1399
- <div class="lora-select-label">Editing Style / LoRA</div>
1400
- <select id="custom-lora-select" class="lora-native-select">
1401
- {LORA_OPTIONS_HTML}
1402
- </select>
1403
- </div>
1404
- </div>
1405
-
1406
- <div style="padding:14px 18px 6px;">
1407
- <button id="custom-run-btn" class="btn-run">
1408
- <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="18" height="18">
1409
- <path d="M12 23c-3.6 0-8-2.69-8-7.5 0-3.5 3-6.5 4.5-8 .27-.27.75-.08.75.28v2.44c0 .42.5.63.72.28C12.28 7.5 13 3 13 1c0-.42.48-.64.8-.35C18 4.5 20 9 20 12c0 5.5-3.5 11-8 11z" fill="white"/>
1410
- </svg>
1411
- <span id="run-btn-label">Edit Image</span>
1412
- </button>
1413
- </div>
1414
-
1415
- <div class="output-frame" style="flex:1">
1416
- <div class="out-title">
1417
- <span>Output</span>
1418
- <span id="dl-btn-output" class="out-download-btn" title="Download result">
1419
- {DOWNLOAD_SVG} Save
1420
- </span>
1421
- </div>
1422
- <div class="out-body" id="output-image-container">
1423
- <div class="modern-loader" id="output-loader">
1424
- <div class="loader-spinner"></div>
1425
- <div class="loader-text">Processing image&hellip;</div>
1426
- <div class="loader-bar-track"><div class="loader-bar-fill"></div></div>
1427
- </div>
1428
- <div class="out-placeholder" id="output-placeholder">Result will appear here</div>
1429
- </div>
1430
- </div>
1431
-
1432
- <div class="settings-group">
1433
- <div class="settings-group-title">Advanced Settings</div>
1434
- <div class="settings-group-body">
1435
- <div class="slider-row">
1436
- <label>Seed</label>
1437
- <input type="range" id="custom-seed" min="0" max="2147483647" step="1" value="0">
1438
- <span class="slider-val" id="custom-seed-val">0</span>
1439
- </div>
1440
- <div class="checkbox-row">
1441
- <input type="checkbox" id="custom-randomize" checked>
1442
- <label for="custom-randomize">Randomize seed</label>
1443
- </div>
1444
- <div class="slider-row">
1445
- <label>Guidance</label>
1446
- <input type="range" id="custom-guidance" min="1" max="10" step="0.1" value="1.0">
1447
- <span class="slider-val" id="custom-guidance-val">1.0</span>
1448
- </div>
1449
- <div class="slider-row">
1450
- <label>Steps</label>
1451
- <input type="range" id="custom-steps" min="1" max="50" step="1" value="4">
1452
- <span class="slider-val" id="custom-steps-val">4</span>
1453
- </div>
1454
- </div>
1455
- </div>
1456
-
1457
- </div><!-- /right -->
1458
- </div><!-- /main-row -->
1459
-
1460
- <div class="exp-note">
1461
- Experimental Space for
1462
- <a href="https://huggingface.co/Qwen/Qwen-Image-Edit-2511" target="_blank">Qwen-Image-Edit-2511</a>
1463
- &middot; LoRAs loaded lazily on first use
1464
- </div>
1465
-
1466
- <div class="app-statusbar">
1467
- <div class="sb-section" id="sb-image-count">No images uploaded</div>
1468
- <div class="sb-section sb-fixed">Ready</div>
1469
- </div>
1470
 
1471
- </div><!-- /app-shell -->
1472
- """)
1473
 
1474
- run_btn = gr.Button("Run", elem_id="gradio-run-btn")
 
 
 
1475
 
1476
- demo.load(fn=None, js=gallery_js)
1477
- demo.load(fn=None, js=wire_outputs_js)
1478
 
1479
- run_btn.click(
1480
- fn=infer,
1481
- inputs=[hidden_images_b64, prompt, lora_adapter, seed, randomize_seed, guidance_scale, steps],
1482
- outputs=[result, seed],
1483
- js=r"""(imgs, p, la, s, rs, gs, st) => {
1484
- const images = window.__uploadedImages || [];
1485
- const b64Array = images.map(img => img.b64);
1486
- const imgsJson = JSON.stringify(b64Array);
1487
- const promptEl = document.getElementById('custom-prompt-input');
1488
- const loraEl = document.getElementById('custom-lora-select');
1489
- const promptVal = promptEl ? promptEl.value : p;
1490
- const loraVal = loraEl ? loraEl.value : la;
1491
- return [imgsJson, promptVal, loraVal, s, rs, gs, st];
1492
- }""",
1493
- )
1494
 
1495
- example_load_btn.click(
1496
- fn=load_example_data,
1497
- inputs=[example_idx],
1498
- outputs=[example_result],
1499
- queue=False,
1500
- )
1501
 
1502
  if __name__ == "__main__":
1503
- demo.queue(max_size=50).launch(
1504
- css=css,
1505
- mcp_server=True,
1506
- ssr_mode=False,
1507
- show_error=True,
1508
- allowed_paths=["examples"],
1509
- )
 
1
  import os
2
  import gc
3
  import gradio as gr
4
+ from gradio import Server
5
+ from fastapi.responses import HTMLResponse
6
  import numpy as np
7
  import spaces
8
  import torch
9
  import random
10
  import base64
11
  import json
 
12
  from io import BytesIO
13
  from PIL import Image
14
 
 
203
  return ""
204
 
205
 
206
+ def build_client_config():
207
+ """Static config consumed by the frontend: LoRA list + example cards."""
208
+ examples = []
209
  for i, ex in enumerate(EXAMPLES_CONFIG):
210
+ examples.append({
211
+ "idx": i,
212
+ "thumbs": [make_thumb_b64(p) for p in ex["images"]],
213
+ "n_images": len(ex["images"]),
214
+ "lora": ex["lora"],
215
+ "prompt": ex["prompt"],
216
+ })
217
+ return {
218
+ "loras": ADAPTER_NAMES,
219
+ "default_lora": "Photo-to-Anime",
220
+ "examples": examples,
221
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
 
223
 
224
+ print("Building client config (example thumbnails)…")
225
+ CLIENT_CONFIG = build_client_config()
226
+ print(f"Built config with {len(EXAMPLES_CONFIG)} examples and {len(ADAPTER_NAMES)} LoRAs.")
227
 
228
 
229
  def b64_to_pil_list(b64_json_str):
 
249
  return pil_images
250
 
251
 
252
+ def pil_to_b64_png(image: Image.Image) -> str:
253
+ buf = BytesIO()
254
+ image.save(buf, format="PNG")
255
+ return f"data:image/png;base64,{base64.b64encode(buf.getvalue()).decode()}"
256
+
257
+
258
  def update_dimensions_on_upload(image):
259
  if image is None:
260
  return 1024, 1024
 
268
  return (nw // 8) * 8, (nh // 8) * 8
269
 
270
 
271
+ # ── Gradio Server (Server mode): FastAPI + Gradio queue/API engine ────────────
272
+ app = Server(title="Qwen-Image-Edit-2511-LoRAs-Fast")
273
+
274
+
275
+ @app.mcp.tool(name="edit_image")
276
+ @app.api(name="edit_image")
277
  @spaces.GPU(size="xlarge")
278
  def infer(
279
+ images_b64_json: str,
280
+ prompt: str,
281
+ lora_adapter: str,
282
+ seed: int,
283
+ randomize_seed: bool,
284
+ guidance_scale: float,
285
+ steps: int,
286
+ ) -> dict:
287
+ """Edit one or more images with Qwen-Image-Edit-2511 + a lazily-loaded LoRA.
288
+
289
+ Returns {"image": <base64 PNG data URL>, "seed": <seed used>}.
290
+ """
291
  gc.collect()
292
  torch.cuda.empty_cache()
293
 
 
335
  generator=generator,
336
  true_cfg_scale=guidance_scale,
337
  ).images[0]
338
+ return {"image": pil_to_b64_png(result_image), "seed": seed}
339
  except Exception as e:
340
  raise e
341
  finally:
 
343
  torch.cuda.empty_cache()
344
 
345
 
346
+ @app.api(name="load_example", queue=False)
347
+ def load_example(idx: float) -> dict:
348
+ """Return base64-encoded example images + prompt + LoRA for a given example index."""
349
+ try:
350
+ i = int(idx)
351
+ except (ValueError, TypeError):
352
+ i = -1
353
+ if i < 0 or i >= len(EXAMPLES_CONFIG):
354
+ return {"images": [], "prompt": "", "lora": "", "names": [], "status": "error"}
355
+ ex = EXAMPLES_CONFIG[i]
356
+ b64_list, names = [], []
357
+ for path in ex["images"]:
358
+ b64 = encode_full_image(path)
359
+ if b64:
360
+ b64_list.append(b64)
361
+ names.append(os.path.basename(path))
362
+ return {"images": b64_list, "prompt": ex["prompt"], "lora": ex["lora"], "names": names, "status": "ok"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
 
 
 
364
 
365
+ @app.get("/api/config")
366
+ def client_config():
367
+ """Plain FastAPI route: LoRA choices + example card data for the frontend."""
368
+ return CLIENT_CONFIG
369
 
 
 
370
 
371
+ @app.get("/", response_class=HTMLResponse)
372
+ async def homepage():
373
+ html_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "index.html")
374
+ with open(html_path, "r", encoding="utf-8") as f:
375
+ return f.read()
 
 
 
 
 
 
 
 
 
 
376
 
 
 
 
 
 
 
377
 
378
  if __name__ == "__main__":
379
+ app.launch(show_error=True, mcp_server=True)
 
 
 
 
 
 
index.html ADDED
@@ -0,0 +1,1358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Qwen Studio · Qwen-Image-Edit 2511</title>
7
+ <style>
8
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');
9
+ *{box-sizing:border-box;margin:0;padding:0}
10
+ :root{
11
+ --bg:#0a0a0c;--panel:#131316;--panel2:#0e0e11;--canvas:#08080a;
12
+ --border:#232328;--border2:#33333a;
13
+ --text:#e4e4e7;--muted:#a1a1aa;--dim:#6b6b75;--faint:#4a4a52;
14
+ --accent:#1E90FF;--accent2:#47A3FF;--accent3:#7CB8FF;
15
+ --menubar-h:48px;--statusbar-h:30px;--rail-w:52px;--inspector-w:360px;--filmstrip-h:132px;
16
+ }
17
+ html,body{height:100%}
18
+ body{
19
+ background:var(--bg);font-family:'Inter',system-ui,-apple-system,sans-serif;
20
+ font-size:13px;color:var(--text);overflow:hidden;
21
+ }
22
+
23
+ /* ══ Layout grid ══ */
24
+ .studio{
25
+ display:grid;height:100vh;
26
+ grid-template-rows:var(--menubar-h) 1fr var(--statusbar-h);
27
+ grid-template-columns:var(--rail-w) 1fr var(--inspector-w);
28
+ grid-template-areas:
29
+ "menubar menubar menubar"
30
+ "rail workspace inspector"
31
+ "statusbar statusbar statusbar";
32
+ }
33
+
34
+ /* ══ Menu bar ══ */
35
+ .menubar{
36
+ grid-area:menubar;display:flex;align-items:center;gap:14px;
37
+ background:var(--panel);border-bottom:1px solid var(--border);
38
+ padding:0 16px;z-index:50;
39
+ }
40
+ .menubar-logo{
41
+ width:28px;height:28px;background:linear-gradient(135deg,#1E90FF,#47A3FF,#7CB8FF);
42
+ border-radius:8px;display:flex;align-items:center;justify-content:center;
43
+ box-shadow:0 2px 8px rgba(30,144,255,.35);flex-shrink:0;
44
+ }
45
+ .menubar-logo svg{width:15px;height:15px;fill:#fff}
46
+ .menubar-title{font-size:14px;font-weight:700;letter-spacing:-.2px;white-space:nowrap}
47
+ .menubar-title span{color:var(--dim);font-weight:500}
48
+ .menubar-badge{
49
+ font-size:10px;font-weight:700;padding:2px 8px;border-radius:12px;
50
+ background:rgba(30,144,255,.14);color:var(--accent2);border:1px solid rgba(30,144,255,.25);
51
+ letter-spacing:.4px;white-space:nowrap;
52
+ }
53
+ .menubar-badge.fast{background:rgba(34,197,94,.12);color:#4ade80;border-color:rgba(34,197,94,.25)}
54
+ .menubar-spacer{flex:1}
55
+ .menubar-status{
56
+ display:flex;align-items:center;gap:7px;font-family:'JetBrains Mono',monospace;
57
+ font-size:11px;color:var(--dim);
58
+ }
59
+ .menubar-status .dot{width:7px;height:7px;border-radius:50%;background:#4ade80;box-shadow:0 0 6px rgba(74,222,128,.6)}
60
+ .menubar-status .dot.off{background:#f87171;box-shadow:0 0 6px rgba(248,113,113,.5)}
61
+ .gh-btn{
62
+ display:inline-flex;align-items:center;gap:6px;
63
+ padding:5px 13px;border-radius:7px;text-decoration:none;
64
+ font-size:12px;font-weight:600;background:var(--accent);color:#fff;
65
+ border:1px solid rgba(255,255,255,.15);
66
+ transition:all .15s ease;flex-shrink:0;
67
+ }
68
+ .gh-btn:hover{background:var(--accent2)}
69
+ .gh-btn svg{fill:#fff;width:13px;height:13px}
70
+
71
+ /* ══ Left icon rail ══ */
72
+ .rail{
73
+ grid-area:rail;background:var(--panel);border-right:1px solid var(--border);
74
+ display:flex;flex-direction:column;align-items:center;padding:10px 0;gap:4px;
75
+ overflow-y:auto;z-index:40;
76
+ }
77
+ .rail-btn{
78
+ width:38px;height:38px;border-radius:9px;border:1px solid transparent;
79
+ background:transparent;color:var(--dim);cursor:pointer;
80
+ display:flex;align-items:center;justify-content:center;
81
+ transition:all .15s ease;position:relative;
82
+ }
83
+ .rail-btn:hover:not(:disabled){background:rgba(30,144,255,.12);color:var(--accent3);border-color:rgba(30,144,255,.25)}
84
+ .rail-btn.active{background:rgba(30,144,255,.2);color:var(--accent2);border-color:rgba(30,144,255,.4)}
85
+ .rail-btn:disabled{opacity:.3;cursor:not-allowed}
86
+ .rail-btn svg{width:17px;height:17px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
87
+ .rail-btn svg.fill{fill:currentColor;stroke:none}
88
+ .rail-sep{width:24px;height:1px;background:var(--border);margin:6px 0}
89
+ .rail-label{
90
+ font-size:8px;font-weight:700;color:var(--faint);letter-spacing:1px;
91
+ text-transform:uppercase;margin:8px 0 2px;user-select:none;
92
+ }
93
+
94
+ /* ══ Workspace (canvas + filmstrip) ══ */
95
+ .workspace{
96
+ grid-area:workspace;display:flex;flex-direction:column;min-width:0;min-height:0;
97
+ background:var(--canvas);
98
+ }
99
+ .canvas-head{
100
+ display:flex;align-items:center;gap:10px;padding:8px 16px;
101
+ border-bottom:1px solid var(--border);background:var(--panel2);flex-shrink:0;
102
+ }
103
+ .seg-control{
104
+ display:inline-flex;background:var(--panel);border:1px solid var(--border);
105
+ border-radius:8px;padding:2px;gap:2px;
106
+ }
107
+ .seg-btn{
108
+ padding:4px 14px;font-size:11px;font-weight:600;color:var(--dim);
109
+ background:transparent;border:none;border-radius:6px;cursor:pointer;
110
+ font-family:'Inter',sans-serif;transition:all .15s;letter-spacing:.2px;
111
+ }
112
+ .seg-btn:hover:not(.active){color:var(--muted)}
113
+ .seg-btn.active{background:rgba(30,144,255,.18);color:var(--accent2)}
114
+ .canvas-meta{
115
+ font-family:'JetBrains Mono',monospace;font-size:11px;color:var(--faint);
116
+ overflow:hidden;white-space:nowrap;text-overflow:ellipsis;flex:1;
117
+ }
118
+ .canvas-actions{display:flex;align-items:center;gap:6px}
119
+ .canvas-action-btn{
120
+ display:none;align-items:center;gap:5px;background:rgba(30,144,255,.1);
121
+ border:1px solid rgba(30,144,255,.2);border-radius:6px;cursor:pointer;padding:4px 11px;
122
+ font-size:11px;font-weight:500;color:var(--accent3);height:26px;transition:all .15s;
123
+ font-family:'Inter',sans-serif;white-space:nowrap;
124
+ }
125
+ .canvas-action-btn:hover{background:rgba(30,144,255,.2);border-color:rgba(30,144,255,.35);color:#fff}
126
+ .canvas-action-btn.visible{display:inline-flex}
127
+ .canvas-action-btn.active{background:rgba(30,144,255,.3);border-color:var(--accent);color:#fff}
128
+ .canvas-action-btn svg{width:12px;height:12px;fill:currentColor}
129
+ .out-seed-chip{
130
+ display:none;font-family:'JetBrains Mono',monospace;font-size:10px;font-weight:500;
131
+ color:var(--dim);background:var(--panel);border:1px solid var(--border);
132
+ border-radius:6px;padding:4px 9px;cursor:pointer;transition:all .15s;
133
+ }
134
+ .out-seed-chip.visible{display:inline-flex}
135
+ .out-seed-chip:hover{color:var(--accent3);border-color:rgba(30,144,255,.35)}
136
+
137
+ .canvas-stage{
138
+ flex:1;position:relative;overflow:hidden;min-height:0;
139
+ display:flex;align-items:center;justify-content:center;
140
+ background:
141
+ repeating-conic-gradient(#0c0c0f 0% 25%, #08080a 0% 50%) 0 0/24px 24px;
142
+ }
143
+ .canvas-stage img.modern-out-img{
144
+ max-width:calc(100% - 48px);max-height:calc(100% - 48px);
145
+ box-shadow:0 12px 48px rgba(0,0,0,.7),0 0 0 1px var(--border);
146
+ border-radius:4px;cursor:zoom-in;image-rendering:auto;
147
+ animation:canvasIn .3s ease;
148
+ }
149
+ @keyframes canvasIn{from{opacity:0;transform:scale(.985)}to{opacity:1;transform:scale(1)}}
150
+ .canvas-placeholder{
151
+ text-align:center;color:var(--faint);user-select:none;
152
+ display:flex;flex-direction:column;align-items:center;gap:14px;padding:24px;
153
+ }
154
+ .canvas-placeholder svg{width:72px;height:72px;opacity:.5}
155
+ .canvas-placeholder .cp-title{font-size:15px;font-weight:600;color:var(--dim)}
156
+ .canvas-placeholder .cp-sub{font-size:12px;line-height:1.7;max-width:340px}
157
+ .canvas-placeholder kbd{
158
+ padding:1px 6px;background:var(--panel);border:1px solid var(--border2);
159
+ border-radius:4px;font-family:'JetBrains Mono',monospace;font-size:10px;color:var(--muted);
160
+ }
161
+
162
+ /* Compare slider */
163
+ .compare-wrap{
164
+ position:relative;max-width:calc(100% - 48px);max-height:calc(100% - 48px);overflow:hidden;
165
+ display:none;user-select:none;touch-action:none;cursor:ew-resize;
166
+ box-shadow:0 12px 48px rgba(0,0,0,.7),0 0 0 1px var(--border);border-radius:4px;
167
+ }
168
+ .compare-wrap.visible{display:block}
169
+ .compare-wrap img{display:block;max-width:100%;max-height:100%;pointer-events:none}
170
+ .compare-top{position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden}
171
+ .compare-top img{position:absolute;top:0;left:0;height:100%;width:auto;max-width:none!important;max-height:none!important}
172
+ .compare-divider{position:absolute;top:0;bottom:0;width:2px;background:#fff;box-shadow:0 0 8px rgba(0,0,0,.6);pointer-events:none}
173
+ .compare-handle{
174
+ position:absolute;top:50%;transform:translate(-50%,-50%);
175
+ width:32px;height:32px;border-radius:50%;background:#fff;
176
+ display:flex;align-items:center;justify-content:center;
177
+ box-shadow:0 2px 8px rgba(0,0,0,.5);color:#111;font-size:13px;font-weight:800;
178
+ }
179
+ .compare-label{
180
+ position:absolute;top:8px;padding:2px 8px;border-radius:4px;
181
+ background:rgba(0,0,0,.65);color:#fff;font-size:10px;font-weight:600;
182
+ font-family:'JetBrains Mono',monospace;pointer-events:none;
183
+ }
184
+ .compare-label.before{left:8px}
185
+ .compare-label.after{right:8px}
186
+
187
+ /* Loader */
188
+ .modern-loader{
189
+ display:none;position:absolute;inset:0;background:rgba(8,8,10,.9);
190
+ z-index:15;flex-direction:column;align-items:center;justify-content:center;gap:16px;backdrop-filter:blur(5px);
191
+ }
192
+ .modern-loader.active{display:flex}
193
+ .loader-spinner{
194
+ width:38px;height:38px;border:3px solid var(--border);border-top-color:var(--accent);
195
+ border-radius:50%;animation:spin .8s linear infinite;
196
+ }
197
+ @keyframes spin{to{transform:rotate(360deg)}}
198
+ .loader-text{font-size:13px;color:var(--muted);font-weight:500;text-align:center;padding:0 16px}
199
+ .loader-bar-track{width:220px;height:4px;background:var(--border);border-radius:2px;overflow:hidden}
200
+ .loader-bar-fill{
201
+ height:100%;width:100%;background:linear-gradient(90deg,#1E90FF,#47A3FF,#1E90FF);
202
+ background-size:200% 100%;animation:shimmer 1.5s ease-in-out infinite;border-radius:2px;
203
+ transition:width .3s ease;
204
+ }
205
+ .loader-bar-fill.determinate{animation:none;background:var(--accent)}
206
+ @keyframes shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}
207
+
208
+ /* ══ Filmstrip ══ */
209
+ .filmstrip{
210
+ height:var(--filmstrip-h);flex-shrink:0;background:var(--panel);
211
+ border-top:1px solid var(--border);display:flex;min-height:0;overflow:hidden;
212
+ }
213
+ .filmstrip-section{
214
+ display:flex;flex-direction:column;min-width:0;padding:8px 0 8px 14px;
215
+ }
216
+ .filmstrip-section.inputs{flex:1.2;border-right:1px solid var(--border)}
217
+ .filmstrip-section.history{flex:1}
218
+ .filmstrip-label{
219
+ font-size:9px;font-weight:700;color:var(--faint);letter-spacing:1.2px;
220
+ text-transform:uppercase;margin-bottom:6px;display:flex;align-items:center;gap:8px;
221
+ user-select:none;flex-shrink:0;
222
+ }
223
+ .filmstrip-label .count{
224
+ font-family:'JetBrains Mono',monospace;font-weight:500;color:var(--dim);
225
+ background:var(--panel2);border:1px solid var(--border);border-radius:4px;padding:0 5px;font-size:9px;
226
+ }
227
+ .filmstrip-row{
228
+ display:flex;gap:8px;overflow-x:auto;overflow-y:hidden;flex:1;
229
+ align-items:flex-start;padding-bottom:4px;padding-right:14px;
230
+ }
231
+ .filmstrip-row::-webkit-scrollbar{height:5px}
232
+ .filmstrip-row::-webkit-scrollbar-thumb{background:var(--border);border-radius:3px}
233
+ .fs-thumb{
234
+ position:relative;flex-shrink:0;width:76px;height:76px;border-radius:8px;overflow:hidden;
235
+ border:2px solid var(--border);cursor:pointer;transition:all .15s;background:var(--panel2);
236
+ animation:thumbIn .25s ease;
237
+ }
238
+ @keyframes thumbIn{from{opacity:0;transform:scale(.92)}to{opacity:1;transform:scale(1)}}
239
+ .fs-thumb:hover{border-color:var(--border2);transform:translateY(-2px)}
240
+ .fs-thumb.selected{border-color:var(--accent);box-shadow:0 0 0 2px rgba(30,144,255,.25)}
241
+ .fs-thumb img{width:100%;height:100%;object-fit:cover}
242
+ .fs-badge{
243
+ position:absolute;bottom:4px;left:4px;background:rgba(0,0,0,.75);color:#fff;
244
+ padding:1px 6px;border-radius:4px;font-family:'JetBrains Mono',monospace;font-size:9px;font-weight:600;
245
+ }
246
+ .fs-remove{
247
+ position:absolute;top:4px;right:4px;width:20px;height:20px;background:rgba(0,0,0,.8);
248
+ color:#fff;border:1px solid rgba(255,255,255,.2);border-radius:50%;cursor:pointer;
249
+ display:none;align-items:center;justify-content:center;font-size:10px;transition:all .15s;line-height:1;
250
+ }
251
+ .fs-thumb:hover .fs-remove{display:flex}
252
+ .fs-remove:hover{background:#ef4444;border-color:#ef4444}
253
+ .fs-add{
254
+ flex-shrink:0;width:76px;height:76px;border-radius:8px;border:2px dashed var(--border2);
255
+ display:flex;flex-direction:column;align-items:center;justify-content:center;
256
+ cursor:pointer;transition:all .2s;background:rgba(30,144,255,.03);gap:3px;
257
+ }
258
+ .fs-add:hover{border-color:var(--accent);background:rgba(30,144,255,.08)}
259
+ .fs-add .add-icon{font-size:22px;color:var(--dim);font-weight:300}
260
+ .fs-add .add-text{font-size:9px;color:var(--dim);font-weight:600;text-transform:uppercase;letter-spacing:.5px}
261
+ .fs-empty{
262
+ flex-shrink:0;display:flex;align-items:center;height:76px;
263
+ color:var(--faint);font-size:11px;font-style:italic;padding-right:12px;
264
+ }
265
+
266
+ /* ══ Inspector (right panel) ══ */
267
+ .inspector{
268
+ grid-area:inspector;background:var(--panel);border-left:1px solid var(--border);
269
+ display:flex;flex-direction:column;min-height:0;z-index:40;
270
+ }
271
+ .inspector-tabs{
272
+ display:flex;border-bottom:1px solid var(--border);flex-shrink:0;
273
+ }
274
+ .insp-tab{
275
+ flex:1;padding:11px 8px;font-size:11px;font-weight:700;color:var(--dim);
276
+ background:transparent;border:none;border-bottom:2px solid transparent;
277
+ cursor:pointer;font-family:'Inter',sans-serif;text-transform:uppercase;letter-spacing:.8px;
278
+ transition:all .15s;
279
+ }
280
+ .insp-tab:hover:not(.active){color:var(--muted)}
281
+ .insp-tab.active{color:var(--accent2);border-bottom-color:var(--accent)}
282
+ .insp-page{display:none;flex:1;overflow-y:auto;min-height:0;flex-direction:column}
283
+ .insp-page.active{display:flex}
284
+
285
+ .insp-section{border-bottom:1px solid var(--border);padding:14px 18px}
286
+ .insp-section-title{
287
+ font-size:10px;font-weight:700;color:var(--dim);text-transform:uppercase;
288
+ letter-spacing:1px;margin-bottom:10px;display:flex;align-items:center;justify-content:space-between;
289
+ }
290
+ .char-count{font-size:9px;font-weight:500;color:var(--faint);font-family:'JetBrains Mono',monospace;text-transform:none;letter-spacing:0}
291
+ .modern-textarea{
292
+ width:100%;background:var(--panel2);border:1px solid var(--border);border-radius:8px;
293
+ padding:10px 13px;font-family:'Inter',sans-serif;font-size:13px;color:var(--text);
294
+ resize:vertical;outline:none;min-height:64px;transition:border-color .2s;line-height:1.55;
295
+ }
296
+ .modern-textarea:focus{border-color:var(--accent);box-shadow:0 0 0 3px rgba(30,144,255,.15)}
297
+ .modern-textarea::placeholder{color:var(--faint)}
298
+ .modern-textarea.error-flash{
299
+ border-color:#ef4444!important;box-shadow:0 0 0 3px rgba(239,68,68,.2)!important;animation:shake .4s ease;
300
+ }
301
+ @keyframes shake{0%,100%{transform:translateX(0)}20%,60%{transform:translateX(-4px)}40%,80%{transform:translateX(4px)}}
302
+
303
+ .suggestions-wrap{display:flex;flex-wrap:wrap;gap:5px}
304
+ .suggestion-chip{
305
+ display:inline-flex;align-items:center;padding:4px 11px;
306
+ background:rgba(30,144,255,.07);border:1px solid rgba(30,144,255,.18);border-radius:14px;
307
+ color:var(--accent3);font-size:11px;font-weight:500;font-family:'Inter',sans-serif;
308
+ cursor:pointer;transition:all .15s;white-space:nowrap;
309
+ }
310
+ .suggestion-chip:hover{background:rgba(30,144,255,.15);border-color:rgba(30,144,255,.35);color:var(--accent2)}
311
+ .suggestion-chip.active{background:rgba(30,144,255,.25);border-color:var(--accent);color:#fff}
312
+
313
+ .lora-native-select{
314
+ width:100%;background:var(--panel2);
315
+ border:1px solid var(--border2);border-radius:8px;
316
+ padding:9px 34px 9px 13px;
317
+ font-family:'Inter',sans-serif;font-size:12px;font-weight:600;color:var(--text);
318
+ outline:none;appearance:none;-webkit-appearance:none;
319
+ background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%231E90FF' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
320
+ background-repeat:no-repeat;background-position:right 11px center;
321
+ cursor:pointer;transition:border-color .2s;color-scheme:dark;
322
+ }
323
+ .lora-native-select:focus{border-color:var(--accent);box-shadow:0 0 0 3px rgba(30,144,255,.15)}
324
+ .lora-native-select option{background:var(--panel);color:var(--text)}
325
+
326
+ .btn-run{
327
+ display:flex;align-items:center;justify-content:center;gap:8px;width:100%;
328
+ background:linear-gradient(135deg,#1E90FF,#1873CC);border:none;border-radius:9px;
329
+ padding:12px 24px;cursor:pointer;font-size:14px;font-weight:700;font-family:'Inter',sans-serif;
330
+ color:#fff;transition:all .2s ease;letter-spacing:-.2px;
331
+ box-shadow:0 4px 16px rgba(30,144,255,.3),inset 0 1px 0 rgba(255,255,255,.1);
332
+ }
333
+ .btn-run:hover:not(:disabled){
334
+ background:linear-gradient(135deg,#47A3FF,#1E90FF);transform:translateY(-1px);
335
+ box-shadow:0 6px 24px rgba(30,144,255,.45),inset 0 1px 0 rgba(255,255,255,.15);
336
+ }
337
+ .btn-run:active:not(:disabled){transform:translateY(0)}
338
+ .btn-run:disabled{opacity:.55;cursor:not-allowed}
339
+ .btn-run svg{width:16px;height:16px;fill:#fff}
340
+ .btn-cancel{
341
+ display:flex;align-items:center;justify-content:center;gap:6px;width:100%;
342
+ margin-top:8px;background:transparent;border:1px solid var(--border2);border-radius:9px;
343
+ padding:8px 24px;cursor:pointer;font-size:12px;font-weight:600;font-family:'Inter',sans-serif;
344
+ color:var(--muted);transition:all .15s;
345
+ }
346
+ .btn-cancel:hover{border-color:#ef4444;color:#ef4444;background:rgba(239,68,68,.08)}
347
+ .run-hint{
348
+ text-align:center;font-size:10px;color:var(--faint);margin-top:8px;
349
+ font-family:'JetBrains Mono',monospace;
350
+ }
351
+
352
+ .slider-row{display:flex;align-items:center;gap:9px;min-height:26px;margin-bottom:10px}
353
+ .slider-row:last-child{margin-bottom:0}
354
+ .slider-row label{font-size:12px;font-weight:500;color:var(--muted);min-width:64px;flex-shrink:0}
355
+ .slider-row input[type="range"]{
356
+ flex:1;-webkit-appearance:none;appearance:none;height:5px;background:var(--border);
357
+ border-radius:3px;outline:none;min-width:0;
358
+ }
359
+ .slider-row input[type="range"]::-webkit-slider-thumb{
360
+ -webkit-appearance:none;width:14px;height:14px;background:linear-gradient(135deg,#1E90FF,#1873CC);
361
+ border-radius:50%;cursor:pointer;box-shadow:0 2px 6px rgba(30,144,255,.4);transition:transform .15s;
362
+ }
363
+ .slider-row input[type="range"]::-webkit-slider-thumb:hover{transform:scale(1.2)}
364
+ .slider-row input[type="range"]::-moz-range-thumb{
365
+ width:14px;height:14px;background:linear-gradient(135deg,#1E90FF,#1873CC);
366
+ border-radius:50%;cursor:pointer;border:none;box-shadow:0 2px 6px rgba(30,144,255,.4);
367
+ }
368
+ .slider-val{
369
+ min-width:48px;text-align:right;font-family:'JetBrains Mono',monospace;font-size:11px;
370
+ font-weight:500;padding:2px 7px;background:var(--panel2);border:1px solid var(--border);
371
+ border-radius:5px;color:var(--muted);flex-shrink:0;
372
+ }
373
+ .dice-btn{
374
+ display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;
375
+ background:var(--panel2);border:1px solid var(--border);border-radius:5px;cursor:pointer;
376
+ color:var(--dim);transition:all .15s;flex-shrink:0;padding:0;
377
+ }
378
+ .dice-btn:hover{border-color:var(--accent);color:var(--accent3)}
379
+ .dice-btn svg{width:13px;height:13px;fill:currentColor}
380
+ .checkbox-row{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--muted);margin-bottom:10px}
381
+ .checkbox-row input[type="checkbox"]{accent-color:var(--accent);width:15px;height:15px;cursor:pointer}
382
+ .checkbox-row label{color:var(--muted);font-size:12px;cursor:pointer}
383
+
384
+ /* Examples page */
385
+ .examples-list{padding:12px 14px;display:flex;flex-direction:column;gap:10px}
386
+ .example-card{
387
+ background:var(--panel2);border:1px solid var(--border);
388
+ border-radius:10px;overflow:hidden;cursor:pointer;transition:all .2s ease;flex-shrink:0;
389
+ }
390
+ .example-card:hover{border-color:var(--accent);box-shadow:0 4px 14px rgba(30,144,255,.15)}
391
+ .example-card.loading{opacity:.5;pointer-events:none}
392
+ .example-thumbs{display:flex;height:96px;overflow:hidden;background:var(--panel)}
393
+ .example-thumbs img{flex:1;object-fit:cover;min-width:0;border-bottom:1px solid var(--border)}
394
+ .example-thumb-placeholder{
395
+ flex:1;display:flex;align-items:center;justify-content:center;
396
+ background:var(--panel);color:var(--border2);font-size:10px;min-width:0;
397
+ }
398
+ .example-meta{padding:6px 10px 2px;display:flex;align-items:center;gap:5px;flex-wrap:wrap}
399
+ .example-badge{
400
+ display:inline-flex;padding:2px 7px;background:rgba(30,144,255,.1);border-radius:4px;
401
+ font-size:9px;font-weight:600;color:var(--accent2);font-family:'JetBrains Mono',monospace;white-space:nowrap;
402
+ }
403
+ .example-lora-badge{
404
+ display:inline-flex;padding:2px 7px;background:rgba(255,255,255,.05);border-radius:4px;
405
+ font-size:9px;font-weight:600;color:var(--muted);font-family:'JetBrains Mono',monospace;
406
+ white-space:nowrap;border:1px solid var(--border);max-width:150px;overflow:hidden;text-overflow:ellipsis;
407
+ }
408
+ .example-prompt-text{
409
+ padding:4px 10px 9px;font-size:11px;color:var(--muted);line-height:1.45;
410
+ display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
411
+ }
412
+
413
+ /* ══ Status bar ══ */
414
+ .statusbar{
415
+ grid-area:statusbar;background:var(--panel);border-top:1px solid var(--border);
416
+ display:flex;align-items:center;gap:4px;padding:0 14px;font-size:11px;z-index:50;
417
+ }
418
+ .statusbar .sb-section{
419
+ padding:0 10px;display:flex;align-items:center;font-family:'JetBrains Mono',monospace;
420
+ font-size:11px;color:var(--faint);overflow:hidden;white-space:nowrap;gap:6px;
421
+ }
422
+ .statusbar .sb-right{margin-left:auto;display:flex;align-items:center;gap:10px}
423
+ .sb-pill{
424
+ padding:2px 12px;border-radius:5px;font-weight:600;font-size:10px;
425
+ background:rgba(30,144,255,.1);color:var(--accent2);
426
+ }
427
+ .sb-pill.error{background:rgba(239,68,68,.12);color:#f87171}
428
+ .sb-pill.done{background:rgba(34,197,94,.12);color:#4ade80}
429
+ .sb-link{color:var(--faint);text-decoration:none;font-family:'JetBrains Mono',monospace;font-size:10px}
430
+ .sb-link:hover{color:var(--accent3)}
431
+
432
+ /* ══ Toast ══ */
433
+ .toast-notification{
434
+ position:fixed;top:60px;left:50%;transform:translateX(-50%) translateY(-140%);
435
+ z-index:9999;padding:10px 22px;border-radius:9px;font-family:'Inter',sans-serif;
436
+ font-size:13px;font-weight:600;display:flex;align-items:center;gap:8px;
437
+ box-shadow:0 8px 24px rgba(0,0,0,.5);
438
+ transition:transform .35s cubic-bezier(.34,1.56,.64,1),opacity .35s ease;opacity:0;pointer-events:none;
439
+ }
440
+ .toast-notification.visible{transform:translateX(-50%) translateY(0);opacity:1;pointer-events:auto}
441
+ .toast-notification.error{background:linear-gradient(135deg,#dc2626,#b91c1c);color:#fff;border:1px solid rgba(255,255,255,.15)}
442
+ .toast-notification.warning{background:linear-gradient(135deg,#d97706,#b45309);color:#fff;border:1px solid rgba(255,255,255,.15)}
443
+ .toast-notification.info{background:linear-gradient(135deg,#2563eb,#1d4ed8);color:#fff;border:1px solid rgba(255,255,255,.15)}
444
+ .toast-notification .toast-icon{font-size:15px;line-height:1}
445
+
446
+ /* ══ Lightbox ══ */
447
+ .lightbox{
448
+ position:fixed;inset:0;background:rgba(0,0,0,.92);z-index:10000;
449
+ display:none;align-items:center;justify-content:center;cursor:zoom-out;
450
+ backdrop-filter:blur(6px);animation:fadeIn .2s ease;
451
+ }
452
+ .lightbox.visible{display:flex}
453
+ .lightbox img{max-width:94vw;max-height:94vh;border-radius:6px;box-shadow:0 20px 60px rgba(0,0,0,.8)}
454
+ @keyframes fadeIn{from{opacity:0}to{opacity:1}}
455
+
456
+ /* ══ Drop overlay ══ */
457
+ .drop-overlay{
458
+ position:fixed;inset:0;z-index:9000;background:rgba(8,8,10,.85);
459
+ display:none;align-items:center;justify-content:center;pointer-events:none;
460
+ backdrop-filter:blur(3px);
461
+ }
462
+ .drop-overlay.visible{display:flex}
463
+ .drop-overlay-inner{
464
+ border:3px dashed var(--accent);border-radius:22px;padding:56px 76px;
465
+ font-size:19px;font-weight:700;color:var(--accent2);background:rgba(30,144,255,.06);
466
+ }
467
+
468
+ /* ══ Scrollbars ══ */
469
+ ::-webkit-scrollbar{width:8px;height:8px}
470
+ ::-webkit-scrollbar-track{background:transparent}
471
+ ::-webkit-scrollbar-thumb{background:var(--border);border-radius:4px}
472
+ ::-webkit-scrollbar-thumb:hover{background:var(--border2)}
473
+
474
+ /* ══ Responsive ══ */
475
+ @media(max-width:960px){
476
+ body{overflow:auto}
477
+ .studio{
478
+ height:auto;min-height:100vh;
479
+ grid-template-rows:var(--menubar-h) auto auto auto var(--statusbar-h);
480
+ grid-template-columns:1fr;
481
+ grid-template-areas:"menubar" "rail" "workspace" "inspector" "statusbar";
482
+ }
483
+ .rail{flex-direction:row;justify-content:center;border-right:none;border-bottom:1px solid var(--border);padding:6px}
484
+ .rail-sep{width:1px;height:24px;margin:0 6px}
485
+ .rail-label{display:none}
486
+ .workspace{min-height:60vh}
487
+ .inspector{border-left:none;border-top:1px solid var(--border)}
488
+ }
489
+ </style>
490
+ </head>
491
+ <body>
492
+ <div class="studio">
493
+
494
+ <!-- ══ Menu bar ══ -->
495
+ <div class="menubar">
496
+ <div class="menubar-logo">
497
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 23c-3.6 0-8-2.69-8-7.5 0-3.5 3-6.5 4.5-8 .27-.27.75-.08.75.28v2.44c0 .42.5.63.72.28C12.28 7.5 13 3 13 1c0-.42.48-.64.8-.35C18 4.5 20 9 20 12c0 5.5-3.5 11-8 11z"/></svg>
498
+ </div>
499
+ <div class="menubar-title">Qwen Studio <span>/ Image-Edit 2511</span></div>
500
+ <span class="menubar-badge">2511</span>
501
+ <span class="menubar-badge fast">4-STEP FAST</span>
502
+ <div class="menubar-spacer"></div>
503
+ <div class="menubar-status"><span class="dot" id="conn-dot"></span><span id="conn-text">connecting…</span></div>
504
+ <a href="https://github.com/PRITHIVSAKTHIUR/Qwen-Image-Edit-2511-LoRAs-Fast-Lazy-Load"
505
+ target="_blank" rel="noopener" class="gh-btn">
506
+ <svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>
507
+ <span>GitHub</span>
508
+ </a>
509
+ </div>
510
+
511
+ <!-- ══ Left icon rail ══ -->
512
+ <div class="rail">
513
+ <div class="rail-label">Input</div>
514
+ <button class="rail-btn" id="tb-upload" title="Upload images">
515
+ <svg viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
516
+ </button>
517
+ <button class="rail-btn" id="tb-remove" title="Remove selected image">
518
+ <svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>
519
+ </button>
520
+ <button class="rail-btn" id="tb-clear" title="Clear all images">
521
+ <svg viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>
522
+ </button>
523
+ <div class="rail-sep"></div>
524
+ <div class="rail-label">Result</div>
525
+ <button class="rail-btn" id="compare-btn" title="Compare before / after" disabled>
526
+ <svg viewBox="0 0 24 24"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="12" y1="3" x2="12" y2="21"/></svg>
527
+ </button>
528
+ <button class="rail-btn" id="use-as-input-btn" title="Use result as input (chain edits)" disabled>
529
+ <svg viewBox="0 0 24 24"><polyline points="17 1 21 5 17 9"/><path d="M3 11V9a4 4 0 014-4h14"/><polyline points="7 23 3 19 7 15"/><path d="M21 13v2a4 4 0 01-4 4H3"/></svg>
530
+ </button>
531
+ <button class="rail-btn" id="dl-btn-output" title="Download result" disabled>
532
+ <svg viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
533
+ </button>
534
+ <button class="rail-btn" id="zoom-btn" title="Zoom result" disabled>
535
+ <svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/><line x1="11" y1="8" x2="11" y2="14"/><line x1="8" y1="11" x2="14" y2="11"/></svg>
536
+ </button>
537
+ </div>
538
+
539
+ <!-- ══ Workspace ══ -->
540
+ <div class="workspace">
541
+ <div class="canvas-head">
542
+ <div class="seg-control">
543
+ <button class="seg-btn active" id="seg-result">Result</button>
544
+ <button class="seg-btn" id="seg-input">Input</button>
545
+ </div>
546
+ <div class="canvas-meta" id="canvas-meta">No image loaded</div>
547
+ <div class="canvas-actions">
548
+ <span id="out-seed-chip" class="out-seed-chip" title="Click to copy seed"></span>
549
+ </div>
550
+ </div>
551
+
552
+ <div class="canvas-stage" id="output-image-container">
553
+ <div class="modern-loader" id="output-loader">
554
+ <div class="loader-spinner"></div>
555
+ <div class="loader-text" id="loader-text">Processing image&hellip;</div>
556
+ <div class="loader-bar-track"><div class="loader-bar-fill" id="loader-bar-fill"></div></div>
557
+ </div>
558
+
559
+ <div class="canvas-placeholder" id="output-placeholder">
560
+ <svg viewBox="0 0 80 80" fill="none" xmlns="http://www.w3.org/2000/svg">
561
+ <rect x="8" y="14" width="64" height="52" rx="6" fill="none" stroke="#33333a" stroke-width="2" stroke-dasharray="4 3"/>
562
+ <polygon points="12,62 30,40 42,50 54,34 68,62" fill="rgba(30,144,255,0.1)" stroke="#33333a" stroke-width="1.5"/>
563
+ <circle cx="28" cy="30" r="6" fill="rgba(30,144,255,0.12)" stroke="#33333a" stroke-width="1.5"/>
564
+ </svg>
565
+ <div class="cp-title">Canvas is empty</div>
566
+ <div class="cp-sub">
567
+ Drop images anywhere, paste with <kbd>⌘/Ctrl+V</kbd>, or use the rail to upload.
568
+ Then write an instruction and press <kbd>⌘/Ctrl</kbd>+<kbd>↵</kbd>.
569
+ </div>
570
+ </div>
571
+
572
+ <div class="compare-wrap" id="compare-wrap">
573
+ <img id="compare-after-img" alt="after">
574
+ <div class="compare-top" id="compare-top"><img id="compare-before-img" alt="before"></div>
575
+ <div class="compare-divider" id="compare-divider"><div class="compare-handle">⇄</div></div>
576
+ <span class="compare-label before">Before</span>
577
+ <span class="compare-label after">After</span>
578
+ </div>
579
+ </div>
580
+
581
+ <!-- Filmstrip -->
582
+ <div class="filmstrip">
583
+ <div class="filmstrip-section inputs">
584
+ <div class="filmstrip-label">Inputs <span class="count" id="tb-image-count">0</span></div>
585
+ <div class="filmstrip-row" id="image-gallery-grid"></div>
586
+ </div>
587
+ <div class="filmstrip-section history">
588
+ <div class="filmstrip-label">History <span class="count" id="history-count">0</span></div>
589
+ <div class="filmstrip-row" id="history-strip"></div>
590
+ </div>
591
+ </div>
592
+ </div>
593
+
594
+ <!-- ══ Inspector ══ -->
595
+ <div class="inspector">
596
+ <div class="inspector-tabs">
597
+ <button class="insp-tab active" id="tab-edit">Edit</button>
598
+ <button class="insp-tab" id="tab-examples">Examples</button>
599
+ </div>
600
+
601
+ <!-- Edit page -->
602
+ <div class="insp-page active" id="page-edit">
603
+ <div class="insp-section">
604
+ <div class="insp-section-title"><span>Instruction</span><span class="char-count" id="char-count">0</span></div>
605
+ <textarea id="custom-prompt-input" class="modern-textarea" rows="3"
606
+ placeholder="e.g., transform into anime, upscale, change lighting…"></textarea>
607
+ </div>
608
+
609
+ <div class="insp-section">
610
+ <div class="insp-section-title"><span>Quick Prompts</span></div>
611
+ <div class="suggestions-wrap" id="suggestions-wrap"></div>
612
+ </div>
613
+
614
+ <div class="insp-section">
615
+ <div class="insp-section-title"><span>Style / LoRA</span></div>
616
+ <select id="custom-lora-select" class="lora-native-select"></select>
617
+ </div>
618
+
619
+ <div class="insp-section">
620
+ <button id="custom-run-btn" class="btn-run">
621
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 23c-3.6 0-8-2.69-8-7.5 0-3.5 3-6.5 4.5-8 .27-.27.75-.08.75.28v2.44c0 .42.5.63.72.28C12.28 7.5 13 3 13 1c0-.42.48-.64.8-.35C18 4.5 20 9 20 12c0 5.5-3.5 11-8 11z"/></svg>
622
+ <span id="run-btn-label">Edit Image</span>
623
+ </button>
624
+ <button id="custom-cancel-btn" class="btn-cancel" style="display:none;">Cancel</button>
625
+ <div class="run-hint">⌘/Ctrl + Enter</div>
626
+ </div>
627
+
628
+ <div class="insp-section">
629
+ <div class="insp-section-title"><span>Advanced</span></div>
630
+ <div class="slider-row">
631
+ <label>Seed</label>
632
+ <input type="range" id="custom-seed" min="0" max="2147483647" step="1" value="0">
633
+ <span class="slider-val" id="custom-seed-val">0</span>
634
+ <button class="dice-btn" id="dice-btn" title="Random seed">
635
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM7.5 18c-.83 0-1.5-.67-1.5-1.5S6.67 15 7.5 15s1.5.67 1.5 1.5S8.33 18 7.5 18zm0-9C6.67 9 6 8.33 6 7.5S6.67 6 7.5 6 9 6.67 9 7.5 8.33 9 7.5 9zm4.5 4.5c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5zm4.5 4.5c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5zm0-9c-.83 0-1.5-.67-1.5-1.5S15.67 6 16.5 6s1.5.67 1.5 1.5S17.33 9 16.5 9z"/></svg>
636
+ </button>
637
+ </div>
638
+ <div class="checkbox-row">
639
+ <input type="checkbox" id="custom-randomize" checked>
640
+ <label for="custom-randomize">Randomize seed</label>
641
+ </div>
642
+ <div class="slider-row">
643
+ <label>Guidance</label>
644
+ <input type="range" id="custom-guidance" min="1" max="10" step="0.1" value="1.0">
645
+ <span class="slider-val" id="custom-guidance-val">1.0</span>
646
+ </div>
647
+ <div class="slider-row">
648
+ <label>Steps</label>
649
+ <input type="range" id="custom-steps" min="1" max="50" step="1" value="4">
650
+ <span class="slider-val" id="custom-steps-val">4</span>
651
+ </div>
652
+ </div>
653
+ </div>
654
+
655
+ <!-- Examples page -->
656
+ <div class="insp-page" id="page-examples">
657
+ <div class="examples-list" id="examples-scroll"></div>
658
+ </div>
659
+ </div>
660
+
661
+ <!-- ══ Status bar ══ -->
662
+ <div class="statusbar">
663
+ <div class="sb-section" id="sb-image-count">No inputs</div>
664
+ <div class="sb-right">
665
+ <a class="sb-link" href="https://huggingface.co/Qwen/Qwen-Image-Edit-2511" target="_blank" rel="noopener">Qwen-Image-Edit-2511</a>
666
+ <span class="sb-pill" id="sb-status">Ready</span>
667
+ </div>
668
+ </div>
669
+
670
+ </div>
671
+
672
+ <input id="custom-file-input" type="file" accept="image/*" multiple style="display:none;" />
673
+
674
+ <!-- Lightbox -->
675
+ <div class="lightbox" id="lightbox"><img id="lightbox-img" alt="zoom"></div>
676
+
677
+ <!-- Global drop overlay -->
678
+ <div class="drop-overlay" id="drop-overlay"><div class="drop-overlay-inner">Drop images to upload</div></div>
679
+
680
+ <script type="module">
681
+ import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js";
682
+
683
+ /* ── DOM refs ── */
684
+ const galleryGrid = document.getElementById('image-gallery-grid');
685
+ const fileInput = document.getElementById('custom-file-input');
686
+ const btnUpload = document.getElementById('tb-upload');
687
+ const btnRemove = document.getElementById('tb-remove');
688
+ const btnClear = document.getElementById('tb-clear');
689
+ const promptInput = document.getElementById('custom-prompt-input');
690
+ const charCount = document.getElementById('char-count');
691
+ const loraSelect = document.getElementById('custom-lora-select');
692
+ const runBtn = document.getElementById('custom-run-btn');
693
+ const runBtnLabel = document.getElementById('run-btn-label');
694
+ const cancelBtn = document.getElementById('custom-cancel-btn');
695
+ const imgCountTb = document.getElementById('tb-image-count');
696
+ const imgCountSb = document.getElementById('sb-image-count');
697
+ const sbStatus = document.getElementById('sb-status');
698
+ const loader = document.getElementById('output-loader');
699
+ const loaderText = document.getElementById('loader-text');
700
+ const loaderFill = document.getElementById('loader-bar-fill');
701
+ const outBody = document.getElementById('output-image-container');
702
+ const outPh = document.getElementById('output-placeholder');
703
+ const dlBtn = document.getElementById('dl-btn-output');
704
+ const compareBtn = document.getElementById('compare-btn');
705
+ const useAsInputBtn= document.getElementById('use-as-input-btn');
706
+ const zoomBtn = document.getElementById('zoom-btn');
707
+ const seedChip = document.getElementById('out-seed-chip');
708
+ const historyStrip = document.getElementById('history-strip');
709
+ const historyCount = document.getElementById('history-count');
710
+ const seedSlider = document.getElementById('custom-seed');
711
+ const seedVal = document.getElementById('custom-seed-val');
712
+ const lightbox = document.getElementById('lightbox');
713
+ const lightboxImg = document.getElementById('lightbox-img');
714
+ const dropOverlay = document.getElementById('drop-overlay');
715
+ const compareWrap = document.getElementById('compare-wrap');
716
+ const compareTop = document.getElementById('compare-top');
717
+ const compareDivider = document.getElementById('compare-divider');
718
+ const compareBeforeImg = document.getElementById('compare-before-img');
719
+ const compareAfterImg = document.getElementById('compare-after-img');
720
+ const canvasMeta = document.getElementById('canvas-meta');
721
+ const segResult = document.getElementById('seg-result');
722
+ const segInput = document.getElementById('seg-input');
723
+ const connDot = document.getElementById('conn-dot');
724
+ const connText = document.getElementById('conn-text');
725
+
726
+ /* ── State ── */
727
+ let images = [];
728
+ let selectedIdx = -1;
729
+ let toastTimer = null;
730
+ let running = false;
731
+ let currentJob = null;
732
+ let currentResult = null; // {b64, seed, prompt, lora, beforeB64}
733
+ let history = [];
734
+ let historyIdx = -1;
735
+ let compareMode = false;
736
+ let viewMode = 'result'; // 'result' | 'input'
737
+
738
+ const SUGGESTIONS = [
739
+ ['Anime', 'Transform into anime.'],
740
+ ['B&W', 'Convert it to black and white.'],
741
+ ['Cinematic', 'Add cinematic lighting with warm orange tones and film grain.'],
742
+ ['Oil Paint', 'Apply oil painting effect with visible brush strokes.'],
743
+ ['Upscale 4K', 'Upscale this picture to 4K resolution.'],
744
+ ['Watercolor', 'Make it look like a watercolor painting with soft edges.'],
745
+ ['Pencil Sketch', 'Convert to detailed pencil sketch with cross-hatching and shading.'],
746
+ ['Pop Art', 'Apply pop art style with bold colors and halftone patterns.'],
747
+ ['Vintage Retro', 'Apply a vintage retro film look with faded colors and light leaks.'],
748
+ ['Neon Glow', 'Add neon glow effects with vibrant colors against a dark background.'],
749
+ ['Pixel Art', 'Convert to pixel art style with a retro 16-bit aesthetic.'],
750
+ ['Noir Comic', 'Transform into a noir comic book style.'],
751
+ ['HyperReal', 'Transform into a hyper-realistic face portrait.'],
752
+ ['Unblur', 'Unblur and upscale.'],
753
+ ['Pixar 3D', 'Transform into Pixar-inspired 3D.'],
754
+ ['Manga Tone', 'Paint with manga tone.'],
755
+ ];
756
+
757
+ /* ── Toast ── */
758
+ function showToast(message, type) {
759
+ let toast = document.getElementById('app-toast');
760
+ if (!toast) {
761
+ toast = document.createElement('div');
762
+ toast.id = 'app-toast';
763
+ toast.className = 'toast-notification';
764
+ toast.innerHTML = '<span class="toast-icon"></span><span class="toast-text"></span>';
765
+ document.body.appendChild(toast);
766
+ }
767
+ const icon = toast.querySelector('.toast-icon');
768
+ const text = toast.querySelector('.toast-text');
769
+ toast.className = 'toast-notification ' + (type || 'error');
770
+ icon.textContent = type === 'warning' ? '⚠' : type === 'info' ? 'ℹ' : '✗';
771
+ text.textContent = message;
772
+ if (toastTimer) clearTimeout(toastTimer);
773
+ void toast.offsetWidth;
774
+ toast.classList.add('visible');
775
+ toastTimer = setTimeout(() => toast.classList.remove('visible'), 3500);
776
+ }
777
+
778
+ function flashPromptError() {
779
+ promptInput.classList.add('error-flash');
780
+ promptInput.focus();
781
+ setTimeout(() => promptInput.classList.remove('error-flash'), 800);
782
+ }
783
+
784
+ function setStatus(text, cls) {
785
+ sbStatus.textContent = text;
786
+ sbStatus.className = 'sb-pill' + (cls ? ' ' + cls : '');
787
+ }
788
+
789
+ /* ── View mode (Result / Input canvas) ── */
790
+ function setViewMode(mode) {
791
+ viewMode = mode;
792
+ segResult.classList.toggle('active', mode === 'result');
793
+ segInput.classList.toggle('active', mode === 'input');
794
+ renderCanvas();
795
+ }
796
+ segResult.addEventListener('click', () => setViewMode('result'));
797
+ segInput.addEventListener('click', () => setViewMode('input'));
798
+
799
+ function getCanvasImg() { return outBody.querySelector('img.modern-out-img'); }
800
+
801
+ function renderCanvas() {
802
+ exitCompareMode();
803
+ let img = getCanvasImg();
804
+ const showResult = viewMode === 'result' && currentResult;
805
+ const showInput = viewMode === 'input' && images.length > 0;
806
+
807
+ if (showResult || showInput) {
808
+ outPh.style.display = 'none';
809
+ if (!img) {
810
+ img = document.createElement('img');
811
+ img.className = 'modern-out-img';
812
+ img.addEventListener('click', () => {
813
+ if (img.src) { lightboxImg.src = img.src; lightbox.classList.add('visible'); }
814
+ });
815
+ outBody.appendChild(img);
816
+ }
817
+ img.style.display = '';
818
+ if (showResult) {
819
+ img.src = currentResult.b64;
820
+ canvasMeta.textContent = (currentResult.lora || 'result') + ' · seed ' + currentResult.seed;
821
+ } else {
822
+ const i = selectedIdx >= 0 ? selectedIdx : 0;
823
+ img.src = images[i].b64;
824
+ canvasMeta.textContent = 'input #' + (i + 1) + ' · ' + (images[i].name || 'image');
825
+ }
826
+ } else {
827
+ if (img) img.style.display = 'none';
828
+ outPh.style.display = '';
829
+ canvasMeta.textContent = images.length > 0
830
+ ? images.length + ' input' + (images.length > 1 ? 's' : '') + ' ready — run an edit'
831
+ : 'No image loaded';
832
+ }
833
+ updateRailState();
834
+ }
835
+
836
+ function updateRailState() {
837
+ const hasResult = !!currentResult;
838
+ dlBtn.disabled = !hasResult;
839
+ zoomBtn.disabled = !hasResult && images.length === 0;
840
+ useAsInputBtn.disabled = !hasResult;
841
+ compareBtn.disabled = !(hasResult && currentResult.beforeB64);
842
+ btnRemove.disabled = selectedIdx < 0;
843
+ btnClear.disabled = images.length === 0;
844
+ }
845
+
846
+ /* ── Inputs filmstrip ── */
847
+ function updateCounts() {
848
+ const n = images.length;
849
+ imgCountTb.textContent = n;
850
+ imgCountSb.textContent = n > 0 ? n + ' input' + (n > 1 ? 's' : '') + ' · ' + history.length + ' result' + (history.length === 1 ? '' : 's') : 'No inputs';
851
+ }
852
+
853
+ function addImage(b64, name) {
854
+ images.push({id: Date.now() + Math.random(), b64, name});
855
+ if (selectedIdx < 0) selectedIdx = 0;
856
+ renderFilmstrip(); updateCounts();
857
+ if (!currentResult || viewMode === 'input') renderCanvas();
858
+ }
859
+
860
+ function removeImage(idx) {
861
+ images.splice(idx, 1);
862
+ if (selectedIdx === idx) selectedIdx = images.length ? 0 : -1;
863
+ else if (selectedIdx > idx) selectedIdx--;
864
+ renderFilmstrip(); updateCounts(); renderCanvas();
865
+ }
866
+
867
+ function clearAll() {
868
+ images = []; selectedIdx = -1;
869
+ renderFilmstrip(); updateCounts(); renderCanvas();
870
+ }
871
+
872
+ function renderFilmstrip() {
873
+ galleryGrid.innerHTML = '';
874
+ if (images.length === 0) {
875
+ const empty = document.createElement('div');
876
+ empty.className = 'fs-empty';
877
+ empty.textContent = 'Drop or paste images…';
878
+ galleryGrid.appendChild(empty);
879
+ }
880
+ images.forEach((img, i) => {
881
+ const t = document.createElement('div');
882
+ t.className = 'fs-thumb' + (i === selectedIdx ? ' selected' : '');
883
+ t.innerHTML = '<img src="' + img.b64 + '" alt="">' +
884
+ '<span class="fs-badge">#' + (i + 1) + '</span>' +
885
+ '<button class="fs-remove">✕</button>';
886
+ t.addEventListener('click', (e) => {
887
+ if (e.target.closest('.fs-remove')) return;
888
+ selectedIdx = i;
889
+ renderFilmstrip();
890
+ setViewMode('input');
891
+ });
892
+ t.querySelector('.fs-remove').addEventListener('click', (e) => {
893
+ e.stopPropagation(); removeImage(i);
894
+ });
895
+ galleryGrid.appendChild(t);
896
+ });
897
+ const add = document.createElement('div');
898
+ add.className = 'fs-add';
899
+ add.innerHTML = '<span class="add-icon">+</span><span class="add-text">Add</span>';
900
+ add.addEventListener('click', () => fileInput.click());
901
+ galleryGrid.appendChild(add);
902
+ updateRailState();
903
+ }
904
+
905
+ function processFiles(files) {
906
+ let added = 0;
907
+ Array.from(files).forEach(file => {
908
+ if (!file.type.startsWith('image/')) return;
909
+ added++;
910
+ const reader = new FileReader();
911
+ reader.onload = (e) => addImage(e.target.result, file.name);
912
+ reader.readAsDataURL(file);
913
+ });
914
+ return added;
915
+ }
916
+
917
+ fileInput.addEventListener('change', (e) => { processFiles(e.target.files); e.target.value = ''; });
918
+ btnUpload.addEventListener('click', () => fileInput.click());
919
+ btnRemove.addEventListener('click', () => { if (selectedIdx >= 0) removeImage(selectedIdx); });
920
+ btnClear.addEventListener('click', clearAll);
921
+
922
+ /* ── Drop anywhere ── */
923
+ let dragDepth = 0;
924
+ window.addEventListener('dragenter', (e) => {
925
+ if (!e.dataTransfer || !Array.from(e.dataTransfer.types).includes('Files')) return;
926
+ e.preventDefault();
927
+ dragDepth++;
928
+ dropOverlay.classList.add('visible');
929
+ });
930
+ window.addEventListener('dragleave', (e) => {
931
+ if (!e.dataTransfer || !Array.from(e.dataTransfer.types).includes('Files')) return;
932
+ dragDepth = Math.max(0, dragDepth - 1);
933
+ if (dragDepth === 0) dropOverlay.classList.remove('visible');
934
+ });
935
+ window.addEventListener('dragover', (e) => { e.preventDefault(); });
936
+ window.addEventListener('drop', (e) => {
937
+ e.preventDefault();
938
+ dragDepth = 0;
939
+ dropOverlay.classList.remove('visible');
940
+ if (e.dataTransfer.files.length) {
941
+ const n = processFiles(e.dataTransfer.files);
942
+ if (n > 0) showToast('Added ' + n + ' image' + (n > 1 ? 's' : ''), 'info');
943
+ }
944
+ });
945
+
946
+ /* ── Paste ── */
947
+ document.addEventListener('paste', (e) => {
948
+ if (e.target === promptInput) return;
949
+ const items = e.clipboardData && e.clipboardData.items;
950
+ if (!items) return;
951
+ const files = [];
952
+ for (const item of items) {
953
+ if (item.kind === 'file' && item.type.startsWith('image/')) {
954
+ const f = item.getAsFile();
955
+ if (f) files.push(f);
956
+ }
957
+ }
958
+ if (files.length) {
959
+ e.preventDefault();
960
+ processFiles(files);
961
+ showToast('Pasted ' + files.length + ' image' + (files.length > 1 ? 's' : ''), 'info');
962
+ }
963
+ });
964
+
965
+ /* ── Inspector tabs ── */
966
+ const tabEdit = document.getElementById('tab-edit');
967
+ const tabExamples = document.getElementById('tab-examples');
968
+ const pageEdit = document.getElementById('page-edit');
969
+ const pageExamples = document.getElementById('page-examples');
970
+ tabEdit.addEventListener('click', () => {
971
+ tabEdit.classList.add('active'); tabExamples.classList.remove('active');
972
+ pageEdit.classList.add('active'); pageExamples.classList.remove('active');
973
+ });
974
+ tabExamples.addEventListener('click', () => {
975
+ tabExamples.classList.add('active'); tabEdit.classList.remove('active');
976
+ pageExamples.classList.add('active'); pageEdit.classList.remove('active');
977
+ });
978
+
979
+ /* ── Suggestion chips ── */
980
+ const suggWrap = document.getElementById('suggestions-wrap');
981
+ SUGGESTIONS.forEach(([label, prompt]) => {
982
+ const chip = document.createElement('button');
983
+ chip.className = 'suggestion-chip';
984
+ chip.textContent = label;
985
+ chip.addEventListener('click', () => {
986
+ promptInput.value = prompt;
987
+ updateCharCount();
988
+ suggWrap.querySelectorAll('.suggestion-chip').forEach(c => c.classList.remove('active'));
989
+ chip.classList.add('active');
990
+ promptInput.focus();
991
+ });
992
+ suggWrap.appendChild(chip);
993
+ });
994
+
995
+ function updateCharCount() { charCount.textContent = promptInput.value.length; }
996
+ promptInput.addEventListener('input', () => {
997
+ updateCharCount();
998
+ suggWrap.querySelectorAll('.suggestion-chip').forEach(c => c.classList.remove('active'));
999
+ });
1000
+ updateCharCount();
1001
+
1002
+ /* ── Sliders ── */
1003
+ function bindSlider(id) {
1004
+ const slider = document.getElementById(id);
1005
+ const valSpan = document.getElementById(id + '-val');
1006
+ slider.addEventListener('input', () => { valSpan.textContent = slider.value; });
1007
+ }
1008
+ bindSlider('custom-seed');
1009
+ bindSlider('custom-guidance');
1010
+ bindSlider('custom-steps');
1011
+
1012
+ document.getElementById('dice-btn').addEventListener('click', () => {
1013
+ const s = Math.floor(Math.random() * 2147483647);
1014
+ seedSlider.value = s; seedVal.textContent = s;
1015
+ });
1016
+
1017
+ /* ── Loader ── */
1018
+ function showLoader(text) {
1019
+ loaderText.textContent = text || 'Processing image…';
1020
+ loaderFill.classList.remove('determinate');
1021
+ loaderFill.style.width = '100%';
1022
+ loader.classList.add('active');
1023
+ setStatus('Processing…');
1024
+ }
1025
+ function setLoaderProgress(text, frac) {
1026
+ loaderText.textContent = text;
1027
+ if (frac != null && frac >= 0 && frac <= 1) {
1028
+ loaderFill.classList.add('determinate');
1029
+ loaderFill.style.width = Math.max(4, Math.round(frac * 100)) + '%';
1030
+ }
1031
+ }
1032
+ function hideLoader(statusText, cls) {
1033
+ loader.classList.remove('active');
1034
+ setStatus(statusText || 'Done', cls || 'done');
1035
+ }
1036
+
1037
+ /* ── Result / history ── */
1038
+ function showResult(entry) {
1039
+ currentResult = entry;
1040
+ setViewMode('result');
1041
+ dlBtn.disabled = false;
1042
+ useAsInputBtn.disabled = false;
1043
+ zoomBtn.disabled = false;
1044
+ if (entry.beforeB64) compareBtn.disabled = false;
1045
+ if (entry.seed != null) {
1046
+ seedChip.textContent = 'seed ' + entry.seed;
1047
+ seedChip.classList.add('visible');
1048
+ }
1049
+ }
1050
+
1051
+ function renderHistory() {
1052
+ historyStrip.innerHTML = '';
1053
+ historyCount.textContent = history.length;
1054
+ if (history.length === 0) {
1055
+ const empty = document.createElement('div');
1056
+ empty.className = 'fs-empty';
1057
+ empty.textContent = 'No results yet';
1058
+ historyStrip.appendChild(empty);
1059
+ return;
1060
+ }
1061
+ history.forEach((entry, i) => {
1062
+ const t = document.createElement('div');
1063
+ t.className = 'fs-thumb' + (i === historyIdx ? ' selected' : '');
1064
+ t.title = (entry.lora || '') + ' · seed ' + entry.seed;
1065
+ const im = document.createElement('img');
1066
+ im.src = entry.b64;
1067
+ t.appendChild(im);
1068
+ t.addEventListener('click', () => { historyIdx = i; showResult(history[i]); renderHistory(); });
1069
+ historyStrip.appendChild(t);
1070
+ });
1071
+ }
1072
+
1073
+ function pushHistory(entry) {
1074
+ history.push(entry);
1075
+ historyIdx = history.length - 1;
1076
+ renderHistory();
1077
+ updateCounts();
1078
+ }
1079
+
1080
+ /* ── Compare slider ── */
1081
+ function enterCompareMode() {
1082
+ if (!currentResult || !currentResult.beforeB64) return;
1083
+ compareMode = true;
1084
+ compareBtn.classList.add('active');
1085
+ const img = getCanvasImg();
1086
+ if (img) img.style.display = 'none';
1087
+ compareAfterImg.src = currentResult.b64;
1088
+ compareBeforeImg.src = currentResult.beforeB64;
1089
+ compareWrap.classList.add('visible');
1090
+ requestAnimationFrame(() => setComparePos(0.5));
1091
+ }
1092
+ function exitCompareMode() {
1093
+ if (!compareMode) return;
1094
+ compareMode = false;
1095
+ compareBtn.classList.remove('active');
1096
+ compareWrap.classList.remove('visible');
1097
+ const img = getCanvasImg();
1098
+ if (img && (viewMode === 'result' && currentResult || viewMode === 'input' && images.length)) img.style.display = '';
1099
+ }
1100
+ function setComparePos(frac) {
1101
+ frac = Math.max(0, Math.min(1, frac));
1102
+ const w = compareWrap.clientWidth;
1103
+ const x = frac * w;
1104
+ compareTop.style.clipPath = 'inset(0 ' + (w - x) + 'px 0 0)';
1105
+ compareDivider.style.left = x + 'px';
1106
+ }
1107
+ compareBtn.addEventListener('click', () => { compareMode ? exitCompareMode() : enterCompareMode(); });
1108
+
1109
+ let compareDragging = false;
1110
+ function compareMove(clientX) {
1111
+ const rect = compareWrap.getBoundingClientRect();
1112
+ setComparePos((clientX - rect.left) / rect.width);
1113
+ }
1114
+ compareWrap.addEventListener('pointerdown', (e) => {
1115
+ compareDragging = true;
1116
+ compareWrap.setPointerCapture(e.pointerId);
1117
+ compareMove(e.clientX);
1118
+ });
1119
+ compareWrap.addEventListener('pointermove', (e) => { if (compareDragging) compareMove(e.clientX); });
1120
+ compareWrap.addEventListener('pointerup', () => { compareDragging = false; });
1121
+ compareWrap.addEventListener('pointercancel', () => { compareDragging = false; });
1122
+
1123
+ /* ── Lightbox ── */
1124
+ lightbox.addEventListener('click', () => lightbox.classList.remove('visible'));
1125
+ document.addEventListener('keydown', (e) => { if (e.key === 'Escape') lightbox.classList.remove('visible'); });
1126
+ zoomBtn.addEventListener('click', () => {
1127
+ const img = getCanvasImg();
1128
+ const src = (viewMode === 'result' && currentResult) ? currentResult.b64
1129
+ : (images.length ? images[selectedIdx >= 0 ? selectedIdx : 0].b64 : null);
1130
+ if (src) { lightboxImg.src = src; lightbox.classList.add('visible'); }
1131
+ });
1132
+
1133
+ /* ── Download / chain / seed ── */
1134
+ dlBtn.addEventListener('click', () => {
1135
+ if (currentResult && currentResult.b64) {
1136
+ const a = document.createElement('a');
1137
+ a.href = currentResult.b64;
1138
+ a.download = 'qwen_edit_' + (currentResult.seed != null ? currentResult.seed : 'output') + '.png';
1139
+ document.body.appendChild(a); a.click(); document.body.removeChild(a);
1140
+ }
1141
+ });
1142
+ useAsInputBtn.addEventListener('click', () => {
1143
+ if (!currentResult) return;
1144
+ addImage(currentResult.b64, 'edit_seed_' + (currentResult.seed != null ? currentResult.seed : 'x') + '.png');
1145
+ showToast('Result added as input image', 'info');
1146
+ });
1147
+ seedChip.addEventListener('click', () => {
1148
+ if (currentResult && currentResult.seed != null) {
1149
+ navigator.clipboard.writeText(String(currentResult.seed)).then(
1150
+ () => showToast('Seed copied: ' + currentResult.seed, 'info'), () => {});
1151
+ }
1152
+ });
1153
+
1154
+ /* ── Backend connection ── */
1155
+ let client = null;
1156
+ try {
1157
+ client = await Client.connect(window.location.origin);
1158
+ setStatus('Ready');
1159
+ connDot.classList.remove('off');
1160
+ connText.textContent = 'connected';
1161
+ } catch (e) {
1162
+ console.error('Failed to connect to Gradio backend:', e);
1163
+ setStatus('Offline', 'error');
1164
+ connDot.classList.add('off');
1165
+ connText.textContent = 'offline';
1166
+ showToast('Could not connect to the backend API', 'error');
1167
+ }
1168
+
1169
+ /* ── Config: LoRAs + examples ── */
1170
+ function renderConfig(cfg) {
1171
+ loraSelect.innerHTML = '';
1172
+ cfg.loras.forEach(name => {
1173
+ const opt = document.createElement('option');
1174
+ opt.value = name; opt.textContent = name;
1175
+ loraSelect.appendChild(opt);
1176
+ });
1177
+ if (cfg.default_lora) loraSelect.value = cfg.default_lora;
1178
+
1179
+ const list = document.getElementById('examples-scroll');
1180
+ list.innerHTML = '';
1181
+ cfg.examples.forEach(ex => {
1182
+ const card = document.createElement('div');
1183
+ card.className = 'example-card';
1184
+ const thumbs = ex.thumbs.map(t =>
1185
+ t ? '<img src="' + t + '" alt="">' : '<div class="example-thumb-placeholder">Preview</div>'
1186
+ ).join('');
1187
+ const promptShort = ex.prompt.length > 90 ? ex.prompt.slice(0, 90) + '…' : ex.prompt;
1188
+ card.innerHTML =
1189
+ '<div class="example-thumbs">' + thumbs + '</div>'
1190
+ + '<div class="example-meta">'
1191
+ + '<span class="example-badge">' + ex.n_images + ' img' + (ex.n_images > 1 ? 's' : '') + '</span>'
1192
+ + '<span class="example-lora-badge"></span>'
1193
+ + '</div>'
1194
+ + '<div class="example-prompt-text"></div>';
1195
+ card.querySelector('.example-lora-badge').textContent = ex.lora;
1196
+ card.querySelector('.example-prompt-text').textContent = promptShort;
1197
+ card.addEventListener('click', () => loadExample(card, ex.idx));
1198
+ list.appendChild(card);
1199
+ });
1200
+ }
1201
+
1202
+ async function loadExample(card, idx) {
1203
+ if (!client) { showToast('Backend not connected', 'error'); return; }
1204
+ document.querySelectorAll('.example-card.loading').forEach(c => c.classList.remove('loading'));
1205
+ card.classList.add('loading');
1206
+ showToast('Loading example…', 'info');
1207
+ try {
1208
+ const result = await client.predict('/load_example', { idx: idx });
1209
+ const data = result.data[0];
1210
+ if (data && data.status === 'ok' && data.images && data.images.length > 0) {
1211
+ clearAll();
1212
+ if (data.prompt) { promptInput.value = data.prompt; updateCharCount(); }
1213
+ if (data.lora) loraSelect.value = data.lora;
1214
+ data.images.forEach((b64, i) => {
1215
+ const name = (data.names && data.names[i]) ? data.names[i] : ('example_' + (i + 1) + '.jpg');
1216
+ addImage(b64, name);
1217
+ });
1218
+ tabEdit.click();
1219
+ showToast('Example loaded — ' + data.images.length + ' image(s)', 'info');
1220
+ } else {
1221
+ showToast('Could not load example images', 'error');
1222
+ }
1223
+ } catch (e) {
1224
+ console.error('Example load error:', e);
1225
+ showToast('Could not load example images', 'error');
1226
+ } finally {
1227
+ card.classList.remove('loading');
1228
+ }
1229
+ }
1230
+
1231
+ try {
1232
+ const cfg = await fetch('api/config').then(r => r.json());
1233
+ renderConfig(cfg);
1234
+ } catch (e) {
1235
+ console.error('Failed to load config:', e);
1236
+ }
1237
+
1238
+ /* ── Run ── */
1239
+ function validateBeforeRun() {
1240
+ const promptVal = promptInput.value.trim();
1241
+ const hasImages = images.length > 0;
1242
+ if (!hasImages && !promptVal) { showToast('Please upload an image and enter a prompt', 'error'); flashPromptError(); return false; }
1243
+ if (!hasImages) { showToast('Please upload at least one image', 'error'); return false; }
1244
+ if (!promptVal) { showToast('Please enter an edit prompt', 'warning'); flashPromptError(); return false; }
1245
+ return true;
1246
+ }
1247
+
1248
+ function setRunningUI(on) {
1249
+ running = on;
1250
+ runBtn.disabled = on;
1251
+ runBtnLabel.textContent = on ? 'Editing…' : 'Edit Image';
1252
+ cancelBtn.style.display = on ? 'flex' : 'none';
1253
+ }
1254
+
1255
+ async function runEdit() {
1256
+ if (running) return;
1257
+ if (!client) { showToast('Backend not connected', 'error'); return; }
1258
+ if (!validateBeforeRun()) return;
1259
+
1260
+ setRunningUI(true);
1261
+ setViewMode('result');
1262
+ showLoader('Submitting to queue…');
1263
+
1264
+ const beforeB64 = images[0] ? images[0].b64 : null;
1265
+ const usedPrompt = promptInput.value;
1266
+ const usedLora = loraSelect.value;
1267
+
1268
+ const payload = {
1269
+ images_b64_json: JSON.stringify(images.map(img => img.b64)),
1270
+ prompt: usedPrompt,
1271
+ lora_adapter: usedLora,
1272
+ seed: parseInt(seedSlider.value) || 0,
1273
+ randomize_seed: document.getElementById('custom-randomize').checked,
1274
+ guidance_scale: parseFloat(document.getElementById('custom-guidance').value),
1275
+ steps: parseInt(document.getElementById('custom-steps').value),
1276
+ };
1277
+
1278
+ try {
1279
+ currentJob = client.submit('/edit_image', payload);
1280
+ for await (const msg of currentJob) {
1281
+ if (msg.type === 'status') {
1282
+ if (msg.status === 'pending') {
1283
+ const pos = (msg.position != null && msg.position >= 0)
1284
+ ? 'In queue — position ' + (msg.position + 1) + (msg.queue_size ? ' of ' + msg.queue_size : '')
1285
+ : 'Waiting in queue…';
1286
+ setLoaderProgress(pos, null);
1287
+ setStatus('Queued');
1288
+ } else if (msg.status === 'generating') {
1289
+ setStatus('Processing…');
1290
+ const pd = msg.progress_data;
1291
+ if (pd && pd.length > 0) {
1292
+ const p = pd[pd.length - 1];
1293
+ if (p.index != null && p.length) {
1294
+ const pct = Math.round((p.index / p.length) * 100);
1295
+ setLoaderProgress('Generating… ' + p.index + '/' + p.length + ' (' + pct + '%)', p.index / p.length);
1296
+ } else {
1297
+ setLoaderProgress('Generating…', null);
1298
+ }
1299
+ } else {
1300
+ setLoaderProgress('Generating image…', null);
1301
+ }
1302
+ } else if (msg.status === 'error') {
1303
+ throw new Error(msg.message || 'Generation failed');
1304
+ }
1305
+ } else if (msg.type === 'data') {
1306
+ const out = msg.data && msg.data[0];
1307
+ if (out && out.image) {
1308
+ const entry = { b64: out.image, seed: out.seed, prompt: usedPrompt, lora: usedLora, beforeB64 };
1309
+ showResult(entry);
1310
+ pushHistory(entry);
1311
+ if (out.seed != null) {
1312
+ seedSlider.value = out.seed;
1313
+ seedVal.textContent = out.seed;
1314
+ }
1315
+ hideLoader('Done', 'done');
1316
+ showToast('Image edited successfully', 'info');
1317
+ } else {
1318
+ hideLoader('Done', 'done');
1319
+ }
1320
+ }
1321
+ }
1322
+ } catch (e) {
1323
+ console.error('Edit error:', e);
1324
+ hideLoader('Error', 'error');
1325
+ const msg = (e && e.message) ? e.message : 'Generation failed';
1326
+ showToast(msg.length > 120 ? msg.slice(0, 120) + '…' : msg, 'error');
1327
+ } finally {
1328
+ setRunningUI(false);
1329
+ currentJob = null;
1330
+ }
1331
+ }
1332
+
1333
+ runBtn.addEventListener('click', runEdit);
1334
+
1335
+ cancelBtn.addEventListener('click', async () => {
1336
+ if (currentJob) {
1337
+ try { await currentJob.cancel(); } catch (e) { console.warn('Cancel error:', e); }
1338
+ currentJob = null;
1339
+ }
1340
+ setRunningUI(false);
1341
+ hideLoader('Cancelled');
1342
+ showToast('Generation cancelled', 'warning');
1343
+ });
1344
+
1345
+ document.addEventListener('keydown', (e) => {
1346
+ if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
1347
+ e.preventDefault();
1348
+ runEdit();
1349
+ }
1350
+ });
1351
+
1352
+ renderFilmstrip();
1353
+ renderHistory();
1354
+ updateCounts();
1355
+ renderCanvas();
1356
+ </script>
1357
+ </body>
1358
+ </html>