File size: 16,096 Bytes
55fe803
62594be
55fe803
 
 
 
a05628f
55fe803
 
 
 
 
 
eee0c8d
 
e7338c1
 
eee0c8d
a05628f
55fe803
62594be
eee0c8d
a05628f
55fe803
 
 
 
 
a05628f
55fe803
 
 
e28279b
55fe803
 
 
 
 
 
 
fce671e
 
 
 
 
55fe803
 
e28279b
a05628f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fce671e
 
 
 
 
 
 
 
ebf7196
fce671e
7cd771e
 
a05628f
 
fce671e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a05628f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f2b3f2
a05628f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e28279b
a05628f
e28279b
a05628f
55fe803
a05628f
 
e28279b
 
 
55fe803
a05628f
 
e28279b
 
a05628f
 
 
e28279b
 
a05628f
 
 
e28279b
a05628f
55fe803
a05628f
 
 
55fe803
a05628f
e28279b
 
a05628f
e28279b
 
 
a05628f
e28279b
 
 
 
a05628f
e28279b
 
a05628f
e28279b
 
 
 
55fe803
a05628f
e28279b
a05628f
e28279b
 
a05628f
e28279b
a05628f
e28279b
 
 
a05628f
e28279b
fce671e
e28279b
a05628f
 
e28279b
55fe803
a05628f
55fe803
ad4a177
a05628f
e28279b
55fe803
 
a05628f
55fe803
e28279b
55fe803
a05628f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e28279b
a05628f
 
 
55fe803
 
 
 
 
a05628f
55fe803
 
 
 
 
 
 
e28279b
1f2b3f2
a05628f
 
e28279b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
import torch
import spaces
import gradio as gr
from diffusers import DiffusionPipeline

# Load the pipeline once at startup
print("Booting BRAINDANCE FACTORY neural core...")
pipe = DiffusionPipeline.from_pretrained(
    "Tongyi-MAI/Z-Image-Turbo",
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=False,
)
pipe.to("cuda")

# ======== AoTI compilation + FA3 ========
# pipe.transformer.layers._repeated_blocks = ["ZImageTransformerBlock"]
# spaces.aoti_blocks_load(pipe.transformer.layers, "zerogpu-aoti/Z-Image", variant="fa3")

print("Neural core online. Synaptic links established.")

@spaces.GPU
def generate_image(prompt, height, width, num_inference_steps, seed, randomize_seed, progress=gr.Progress(track_tqdm=True)):
    """Jack in. Generate."""
    if randomize_seed:
        seed = torch.randint(0, 2**32 - 1, (1,)).item()
    
    generator = torch.Generator("cuda").manual_seed(int(seed))
    image = pipe(
        prompt=prompt,
        height=int(height),
        width=int(width),
        num_inference_steps=int(num_inference_steps),
        guidance_scale=0.0,
        generator=generator,
    ).images[0]
    
    return image, seed

# Example prompts
examples = [
    ["A highly detailed cyberpunk street scene in Tokyo at night after rain. Pink and cyan neon signs reflecting in wet asphalt puddles. A flying food stall in the foreground with rising steam. Cinematic look, 8k resolution, soft bokeh background, hyper-realistic."],
    ["A floating island in a sea of clouds at sunset. A large, glowing ancient tree with golden leaves stands on the island. Small waterfalls cascading from the cliffs into the void. Soft brushstroke digital art style, magical lighting, pastel colors, dreamy atmosphere."],
    ["Macro photography of a single water droplet on a deep green fern leaf. An entire forest is reflected inside the droplet. Extremely shallow depth of field, intricate leaf texture, natural sunlight filtering through the canopy, 100mm macro lens aesthetic."],
    ["Isometric 3D miniature of a cozy reading room. A small fireplace burning, a comfortable armchair nearby, and walls lined with bookshelves. Octane render style, soft clay textures, warm volumetric lighting, minimalist and cute."],
    ["A dramatic oil painting in the style of Caravaggio. A lone astronomer sitting at a wooden table, studying an ancient star map by candlelight. Strong chiaroscuro, visible brushstrokes, rich textures of parchment and heavy velvet, deep gold and brown tones."],
]


CYBERPUNK_CSS = """
/* ============================================
   BRAINDANCE FACTORY β€” NEURAL INTERFACE v2.0.77
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Orbitron:wght@400;700;900&family=Rajdhani:wght@300;400;600&display=swap');

/* Root & Scanlines */
.gradio-container {
    max-width: 1500px !important;
    margin: 0 auto !important;
    background: #050811 !important;
    position: relative;
}

.gradio-container::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 245, 255, 0.015) 2px,
        rgba(0, 245, 255, 0.015) 4px
    );
    pointer-events: none;
    z-index: 9999;
}

/* Header */
.bd-header {
    font-family: 'Orbitron', monospace;
    text-align: center;
    padding: 2.5rem 1rem 1.5rem;
    position: relative;
    border-bottom: 1px solid #00f5ff18;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.bd-header::after {
    content: '';
    position: absolute;
    bottom: 0; left: 10%; right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent, #00f5ff, #ff00c8, #00f5ff, transparent);
    animation: scanline-sweep 4s linear infinite;
}

@keyframes scanline-sweep {
    0% { opacity: 0.3; } 50% { opacity: 1; } 100% { opacity: 0.3; }
}

.bd-header h1 {
    font-size: clamp(2rem, 5vw, 3.8rem) !important;
    font-weight: 900 !important;
    letter-spacing: 0.12em;
    margin: 0 0 0.3rem !important;
    color: #00f5ff !important;
    text-shadow:
        0 0 10px #00f5ff,
        0 0 30px #00f5ffaa,
        0 0 60px #00f5ff44;
    -webkit-text-fill-color: unset !important;
    background: none !important;
    animation: flicker 6s infinite;
}

@keyframes flicker {
    0%, 95%, 100% { opacity: 1; }
    96% { opacity: 0.7; }
    97% { opacity: 1; }
    98% { opacity: 0.4; }
    99% { opacity: 1; }
}

.bd-header .glitch-sub {
    font-family: 'Rajdhani', sans-serif;
    font-size: 1rem;
    letter-spacing: 0.35em;
    text-transform: uppercase;
    color: #ff00c8 !important;
    opacity: 0.85;
    text-shadow: 0 0 8px #ff00c8aa;
}

.bd-header .glitch-sub span {
    color: #00f5ff88;
    margin: 0 0.5em;
}

/* Tagline badge */
.bd-tagline {
    display: inline-block;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.72rem;
    color: #00f5ff66;
    border: 1px solid #00f5ff22;
    padding: 0.2em 0.8em;
    margin-top: 0.8rem;
    letter-spacing: 0.15em;
    background: #00f5ff08;
}

/* Panel blocks */
.block, .gr-block, .gr-panel {
    border: 1px solid #00f5ff1a !important;
    border-radius: 2px !important;
    background: #0a0f1e !important;
    box-shadow: 0 0 20px #00f5ff08, inset 0 0 20px #00000033 !important;
}

/* Corner decorators on panels */
.block::before, .block::after {
    content: '';
    position: absolute;
    width: 8px; height: 8px;
    border-color: #00f5ff55;
    border-style: solid;
}
.block::before {
    top: -1px; left: -1px;
    border-width: 1px 0 0 1px;
}
.block::after {
    bottom: -1px; right: -1px;
    border-width: 0 1px 1px 0;
}

/* Generate button β€” the big CTA */
.generate-btn button, button[class*="primary"] {
    font-family: 'Orbitron', monospace !important;
    font-size: 0.95rem !important;
    font-weight: 700 !important;
    letter-spacing: 0.2em !important;
    text-transform: uppercase !important;
    background: linear-gradient(135deg, #00f5ff, #00b8cc) !important;
    color: #020710 !important;
    border: none !important;
    border-radius: 2px !important;
    padding: 0.9rem 1.5rem !important;
    position: relative;
    overflow: hidden;
    transition: all 0.25s ease !important;
    box-shadow: 0 0 20px #00f5ff55, 0 0 40px #00f5ff22 !important;
    cursor: pointer;
}

.generate-btn button::before, button[class*="primary"]::before {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, #ffffff33, transparent);
    transition: left 0.4s ease;
}

.generate-btn button:hover::before, button[class*="primary"]:hover::before {
    left: 100%;
}

.generate-btn button:hover, button[class*="primary"]:hover {
    background: linear-gradient(135deg, #ff00c8, #cc0099) !important;
    box-shadow: 0 0 25px #ff00c888, 0 0 50px #ff00c833 !important;
    transform: translateY(-2px) !important;
    color: #fff !important;
}

/* Input fields */
textarea, input[type="text"], input[type="number"] {
    font-family: 'Rajdhani', sans-serif !important;
    font-size: 1.05rem !important;
    color: #c8e0ef !important;
    background: #0d1526 !important;
    border: 1px solid #00f5ff22 !important;
    border-radius: 2px !important;
    caret-color: #00f5ff;
    transition: border-color 0.2s, box-shadow 0.2s !important;
}

textarea:focus, input:focus {
    border-color: #00f5ff88 !important;
    box-shadow: 0 0 12px #00f5ff22 !important;
    outline: none !important;
}

textarea::placeholder {
    color: #2a4055 !important;
    font-style: italic;
}

/* Labels */
label span, .gr-block label {
    font-family: 'Share Tech Mono', monospace !important;
    font-size: 0.78rem !important;
    letter-spacing: 0.12em !important;
    text-transform: uppercase !important;
    color: #00f5ffaa !important;
}

/* Sliders */
input[type="range"] {
    accent-color: #00f5ff !important;
}

input[type="range"]::-webkit-slider-thumb {
    background: #00f5ff !important;
    box-shadow: 0 0 8px #00f5ff !important;
}

input[type="range"]::-webkit-slider-runnable-track {
    background: linear-gradient(to right, #00f5ff, #0d1526) !important;
}

/* Accordion */
.gr-accordion > .label-wrap {
    border-bottom: 1px solid #00f5ff18 !important;
}

.gr-accordion {
    border: 1px solid #00f5ff1a !important;
    background: #070c1a !important;
    border-radius: 2px !important;
}

/* Image output */
.gr-image img, .output-image img {
    border: 1px solid #00f5ff33 !important;
    border-radius: 2px !important;
    box-shadow: 0 0 30px #00f5ff18, 0 0 60px #00000066 !important;
    transition: box-shadow 0.4s ease;
}

.gr-image img:hover, .output-image img:hover {
    box-shadow: 0 0 40px #00f5ff44, 0 0 80px #ff00c822 !important;
}

/* Examples β€” catch-all for every Gradio version */
.examples, .examples *,
.svelte-examples, .svelte-examples *,
[class*="examples"], [class*="examples"] *,
[class*="example-"] button, [class*="example-"] td,
#examples-block, #examples-block *,
.wrap > .examples_table,
.wrap > .examples_table * {
    color: #b8d8e8 !important;
    background-color: #0a1220 !important;
    font-family: 'Rajdhani', sans-serif !important;
    font-weight: 600 !important;
}

[class*="examples"] button:hover,
[class*="example-"] button:hover {
    background-color: #0d1e30 !important;
    color: #00f5ff !important;
    text-shadow: 0 0 8px #00f5ff77 !important;
}

/* Also catch bare table cells anywhere in the UI */
td {
    color: #b8d8e8 !important;
    background-color: #0a1220 !important;
    font-family: 'Rajdhani', sans-serif !important;
    font-weight: 600 !important;
    font-size: 0.9rem !important;
    border-color: #00f5ff15 !important;
    padding: 0.4em 0.7em !important;
}

tr:hover td {
    background-color: #0d1e30 !important;
    color: #00f5ff !important;
}

/* Footer */
.bd-footer {
    font-family: 'Share Tech Mono', monospace;
    text-align: center;
    padding: 1.5rem 0 0.5rem;
    border-top: 1px solid #00f5ff12;
    margin-top: 1rem;
    font-size: 0.75rem;
    color: #2a4055;
    letter-spacing: 0.08em;
}

.bd-footer a {
    color: #00f5ff66 !important;
    text-decoration: none !important;
    transition: color 0.2s, text-shadow 0.2s;
}

.bd-footer a:hover {
    color: #ff00c8 !important;
    text-shadow: 0 0 8px #ff00c888 !important;
}

.bd-footer .sep {
    color: #00f5ff22;
    margin: 0 0.6em;
}

/* Status dot */
.status-dot {
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #00f5ff;
    box-shadow: 0 0 6px #00f5ff;
    animation: pulse-dot 1.8s infinite;
    vertical-align: middle;
    margin-right: 0.4em;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; box-shadow: 0 0 6px #00f5ff; }
    50% { opacity: 0.4; box-shadow: 0 0 2px #00f5ff; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: #050811; }
::-webkit-scrollbar-thumb { background: #00f5ff33; border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: #00f5ff66; }

/* Mobile */
@media (max-width: 768px) {
    .bd-header h1 { font-size: 1.8rem !important; }
}
"""

# ─── Build the Gradio Interface ───────────────────────────────────────────────
with gr.Blocks() as demo:

    # ── Header ──
    gr.HTML("""
        <div class="bd-header">
            <h1>BRAINDANCE FACTORY</h1>
            <div class="glitch-sub">
                Neural Image Synthesis
                <span>///</span>
                Z-Image-Turbo Core
                <span>///</span>
                8-Step Protocol
            </div>
            <div class="bd-tagline">
                <span class="status-dot"></span>
                SYNAPTIC UPLINK ESTABLISHED β€” JACK IN TO BEGIN
            </div>
        </div>
    """)

    with gr.Row(equal_height=False):
        # ── Left: Controls ──
        with gr.Column(scale=1, min_width=320):

            prompt = gr.Textbox(
                label="⬑ NEURAL PROMPT INPUT",
                placeholder="Inject your vision into the braindance matrix...",
                lines=5,
                max_lines=10,
                autofocus=True,
            )

            with gr.Accordion("⬑ SYSTEM PARAMETERS", open=False):
                with gr.Row():
                    height = gr.Slider(
                        minimum=512, maximum=2048, value=1024, step=64,
                        label="HEIGHT  [px]",
                        info="Vertical resolution"
                    )
                    width = gr.Slider(
                        minimum=512, maximum=2048, value=1024, step=64,
                        label="WIDTH  [px]",
                        info="Horizontal resolution"
                    )

                num_inference_steps = gr.Slider(
                    minimum=1, maximum=20, value=9, step=1,
                    label="INFERENCE CYCLES",
                    info="9 steps = 8 DiT forwards (optimal)"
                )

                with gr.Row():
                    randomize_seed = gr.Checkbox(
                        label="⬑ RANDOMIZE SEED",
                        value=True,
                    )
                    seed = gr.Number(
                        label="SEED NODE",
                        value=42,
                        precision=0,
                        visible=False,
                    )

                def toggle_seed(randomize):
                    return gr.Number(visible=not randomize)

                randomize_seed.change(
                    toggle_seed,
                    inputs=[randomize_seed],
                    outputs=[seed]
                )

            generate_btn = gr.Button(
                "⬑ INITIATE BRAINDANCE",
                variant="primary",
                size="lg",
                elem_classes=["generate-btn"],
            )

            gr.Examples(
                examples=examples,
                inputs=[prompt],
                label="⬑ MEMORY FRAGMENTS β€” SAMPLE INPUTS",
                examples_per_page=5,
                elem_id="examples-block",
            )

        # ── Right: Output ──
        with gr.Column(scale=1, min_width=320):
            output_image = gr.Image(
                label="SYNTHESIZED BRAINDANCE OUTPUT",
                type="pil",
                format="png",
                show_label=True,
                height=600,
            )
            used_seed = gr.Number(
                label="⬑ SEED NODE USED",
                interactive=False,
                container=True,
            )

    # ── Footer ──
    gr.HTML("""
        <div class="bd-footer">
            <span class="status-dot"></span>
            MODEL: <a href="https://huggingface.co/Tongyi-MAI/Z-Image-Turbo" target="_blank">TONGYI-MAI / Z-IMAGE-TURBO</a>
            <span class="sep">//</span>
            APACHE 2.0 LICENSE
            <span class="sep">//</span>
            DEMO: <a href="https://x.com/realmrfakename" target="_blank">@MRFAKENAME</a>
            <span class="sep">//</span>
            OPTIMIZATIONS: <a href="https://huggingface.co/multimodalart" target="_blank">@MULTIMODALART</a>
            <span class="sep">//</span>
            BRAINDANCE SKIN: ANYCODER
            <br><br>
            &gt;&gt; ALL MEMORIES ARE PROPERTY OF THE FACTORY. UNAUTHORIZED DREAMING IS ENCOURAGED. &lt;&lt;
        </div>
    """)

    # ── Events ──
    generate_btn.click(
        fn=generate_image,
        inputs=[prompt, height, width, num_inference_steps, seed, randomize_seed],
        outputs=[output_image, used_seed],
    )

    prompt.submit(
        fn=generate_image,
        inputs=[prompt, height, width, num_inference_steps, seed, randomize_seed],
        outputs=[output_image, used_seed],
    )

if __name__ == "__main__":
    demo.launch(
        css=CYBERPUNK_CSS,
        mcp_server=True,
        footer_links=["api", "gradio"],
    )