AlekseyCalvin commited on
Commit
2e7a936
·
verified ·
1 Parent(s): d46a1b1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -0
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ from deforum_engine import DeforumRunner
4
+
5
+ runner = DeforumRunner(device="cpu")
6
+
7
+ def process(model, lora, sched, prompts, neg,
8
+ frames, width, height, fps, steps, cfg, seed, seed_beh,
9
+ zoom, angle, tx, ty, stre, noi,
10
+ color, cadence, border, use_init, init_img):
11
+
12
+ if not use_init: init_img = None
13
+
14
+ # Dictionary packing allows for cleaner code in the engine
15
+ args = {
16
+ 'model': model, 'lora': lora, 'sched': sched,
17
+ 'prompts': prompts, 'neg': neg,
18
+ 'max_frames': frames, 'W': width, 'H': height,
19
+ 'zoom': zoom, 'angle': angle, 'tx': tx, 'ty': ty,
20
+ 'strength': stre, 'noise': noi,
21
+ 'fps': fps, 'steps': steps, 'cfg': cfg, 'cadence': cadence,
22
+ 'color': color, 'border': border, 'seed_beh': seed_beh,
23
+ 'init_image': init_img, 'use_init': use_init, 'seed': seed
24
+ }
25
+ yield from runner.render(args)
26
+
27
+ def stop_gen():
28
+ runner.stop()
29
+ return "Stopping..."
30
+
31
+ css = "#col-container {max_width: 1000px; margin: 0 auto;}"
32
+
33
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
34
+ gr.Markdown("# 🌀 Deforum Soon® Diffusion CPU")
35
+ gr.Markdown("**Model Suggestions:** cc-nms/tiny-sd-turbo, AiArtLab/sdxs, runwayml/stable-diffusion-v1-5, segmind/tiny-sd, stabilityai/sdxl-turbo, CodeGoat24/sdxl-turbo-unified-reward-dpo, fluently/Fluently-XL-v3-Lightning, SimianLuo/LCM_Dreamshaper_v7, segmind/portrait-finetuned, rupeshs/sdxs-512-0.9-orig-vae, Disty0/LCM_SoteMix, qiacheng/stable-diffusion-v1-5-lcm, AiArtLab/sdxs-08b, n1i/sdxl-ssd-1b-lcm, nota-ai/bk-sdm-tiny, nota-ai/bk-sdm-small-2m, nota-ai/bk-sdm-base-2m, nota-ai/bk-sdm-v2-tiny, nota-ai/bk-sdm-tiny-2m, segmind/small-sd | LoRA: latent-consistency/lcm-lora-sdv1-5, akameswa/lcm-lora-tiny-sd, kmpartner/bkv2tpcmlra-test, openskyml/lcm-lora-sdxl-turbo")
36
+ with gr.Row():
37
+ with gr.Column():
38
+ with gr.Accordion("Pipeline Config", open=True):
39
+ # TEXTBOXES allows any model
40
+ model = gr.Textbox(label="Model ID (HuggingFace)", value="cc-nms/tiny-sd-turbo")
41
+ lora = gr.Textbox(label="LoRA ID (Optional)", value="")
42
+ sched = gr.Dropdown(label="Scheduler", value="Euler A", choices=["LCM", "Euler A", "DDIM", "DPM++ 2M"])
43
+ seed_beh = gr.Dropdown(label="Seed Behavior", value="iter", choices=["iter", "fixed", "random"])
44
+ init_img = gr.Image(label="Init Image", type="pil", height=200)
45
+ use_init = gr.Checkbox(label="Use Init Image", value=False)
46
+
47
+ prompts = gr.Code(label="Prompts (JSON)", language="json",
48
+ value='{\n "0": "Leonora Carrington style modelshot art of <1> Abraxas ancient deity human cat hybrid <2> tarot card, cat person portrait, full-height, paws, cat ears, ancient futuristic mysterium, Mandelbrot set patterned green-eyes, elegant, elaborate 8k fancy decorative book art hyper-realism",\n "10":"high resolution, realistically-shaded, detailed ultra-HD masterpiece of photo realism catalogue art by Austin Osman Spare, depicting people getting surrounded, squeezed, and suffocated by countless common household objects from a soviet catalogue, a highly intricate realistic museum-quality artwork",\n "20":"detailed colorful book art by Félicien Rops of androgynous quasi-cyborg young bespectacled historically-accurate Guy Debord stood alone on stage, singing a lecture into a microphone on a tall mic-stand, addressing diverse crowd of holographic rock and roll situationist feline and academic woodland fairies, crazed chimney sweepers, novelists, and other wildly eccentric folks gathered on a dance-floor below",\n "30": "8K high resolution detailed museum-quality surrealist panoramic art of smiling rebel cyberpunk Janelle Monae, newly a president of Earth and the near-cosmos leading a procession over a star river in space and smiling, in the background are screaming exploding planets, Howard Johnson-style sci fi image",\n "40":"dynamic composition art by Austin Osman Spare of William S Burroughs setting on fire an occult temple with TOPY symbols in Kiev crumbling under a massive terrifying nuclear blast at night",\n "50":"RAW color 50 mm f/1.4 photo pinup portrait of soviet alien catwomen led catgirl Guy Debord weeping and screaming in horror in the sight of something truly monstrous",\n "60":"illustration of young red-haired female poet Irina Odoevtseva:3 sailing a beautiful red-sailed sailboat over the Neva River past an early-Soviet Leningrad while phantasmal spirits of famous historical revolutionaries and punks swirl around",\n "70": "young punk rock dark-angel-winged Rosa Luxemburg flying through the sky, wearing robes made of newspapers, elaborate arcane illustration by Max Ernst"\n}')
49
+ neg = gr.Textbox(label="Negative Prompt", value="complex, realistic, photo, blur")
50
+
51
+ with gr.Row():
52
+ frames = gr.Number(label="Frames", value=80)
53
+ fps = gr.Number(label="FPS", value=4)
54
+
55
+ with gr.Row():
56
+ width = gr.Slider(128, 1024, value=512, step=64, label="Width")
57
+ height = gr.Slider(128, 1024, value=256, step=64, label="Height")
58
+
59
+ with gr.Row():
60
+ steps = gr.Slider(1, 50, value=5, step=1, label="Steps")
61
+ cfg = gr.Slider(0.0, 20.0, value=0.5, step=0.1, label="CFG Scale (0-2 for SDXS/LCM)")
62
+ cadence = gr.Slider(1, 8, value=3, step=1, label="Cadence")
63
+
64
+ with gr.Accordion("🎬 Motion & Coherence", open=True):
65
+ with gr.Row():
66
+ color = gr.Dropdown(label="Color Match", value="LAB", choices=["None", "LAB", "HSV", "RGB"])
67
+ border = gr.Dropdown(label="Border Mode", value="Replicate", choices=["Reflect", "Replicate", "Wrap", "Black"])
68
+
69
+ z = gr.Textbox(label="Zoom", value="0:(0), 2:(-0.9), 6:(0.9), 10:(-0.9), 14:(0), 20:(1), 30:(-1), 40:(0), 50:(2), 60:(-2), 70:(4), 80:(-5)")
70
+ a = gr.Textbox(label="Angle", value="0:(0), 2:(-0.9), 6:(0.9), 10:(-0.9), 14:(0), 20:(1), 30:(-1), 40:(0), 50:(2), 60:(-2), 70:(4)")
71
+ tx = gr.Textbox(label="Translation X", value="0:(-.9), 18:(.8), 30:(-.9), 50:(1.5), 64:(-2)")
72
+ ty = gr.Textbox(label="Translation Y", value="0:(-.1), 10:(.1), 20:(-.3), 30:(.3), 20:(-.4), 30:(.4), 40:(-.5), 50:(.5), 60:(-.6), 70:(.6)")
73
+ stre = gr.Textbox(label="Strength", value="0:(.75), 6:(0.25), 10:(0.45), 16:(0.71), 20:(0.23), 30: (0.39), 34:(0.71), 36:(0.25), 44:(.39), 48:(0.72), 50:(0.25), 56:(0.39), 62:(0.75), 64:(0.3), 68:(0.4), 72:(0.75), 76:(0.55)")
74
+ noi = gr.Textbox(label="Noise", value="0:(0.06), 20:(0.06), 30:(0.12), 40:(0.04), 60:(0.03), 76:(0.05)")
75
+
76
+ with gr.Row():
77
+ btn = gr.Button("GENERATE", variant="primary", scale=2)
78
+ stop = gr.Button("STOP", variant="stop", scale=1)
79
+
80
+ with gr.Column(scale=1):
81
+ status = gr.Markdown("Ready")
82
+ preview = gr.Image(label="Last Frame")
83
+ video_out = gr.Video(label="Rendered Video")
84
+ zip_out = gr.File(label="Frames ZIP")
85
+
86
+ inputs = [
87
+ model, lora, sched, prompts, neg,
88
+ frames, width, height, fps, steps, cfg, gr.State(-1), seed_beh,
89
+ z, a, tx, ty, stre, noi,
90
+ color, cadence, border, use_init, init_img
91
+ ]
92
+
93
+ btn.click(process, inputs=inputs, outputs=[preview, video_out, zip_out, status])
94
+ stop.click(stop_gen, outputs=status)
95
+
96
+ demo.queue().launch(css=css, theme=gr.themes.Glass())