AlekseyCalvin commited on
Commit
231ef6a
·
verified ·
1 Parent(s): d48ea42

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ from deforum_engine import DeforumRunner
4
+
5
+ runner = DeforumRunner(device="cpu")
6
+
7
+ def process(prompts_json, neg, frames, w, h, z, a, tx, ty, stre, noi, fps, steps,
8
+ cadence, color, border, init_img, model, lora, sched):
9
+ try:
10
+ p_dict = json.loads(prompts_json.replace("'", '"'))
11
+ prompts = {int(k): v for k, v in p_dict.items()}
12
+ except: return None, None, None
13
+
14
+ yield from runner.render(
15
+ prompts, neg, int(frames), 256, 256,
16
+ z, a, tx, ty, stre, noi, int(fps), int(steps),
17
+ int(cadence), color, border, init_img,
18
+ model, lora, sched
19
+ )
20
+
21
+ def stop_gen():
22
+ runner.stop()
23
+ return gr.update(value="Stopping...")
24
+
25
+ css = "#col-container {max_width: 950px; margin-left: auto; margin-right: auto;}"
26
+ with gr.Blocks() as demo:
27
+ gr.Markdown("# 🌀 Authentic Deforum (CPU/LCM)")
28
+
29
+ with gr.Row(elem_id="col-container"):
30
+ with gr.Column(scale=1):
31
+ with gr.Accordion("⚙️ Model & Init", open=False):
32
+ model = gr.Dropdown(label="Model", value="AlekseyCalvin/acs_model",
33
+ choices=["AlekseyCalvin/acs_model", "runwayml/stable-diffusion-v1-5"])
34
+ lora = gr.Dropdown(label="LoRA", value="latent-consistency/lcm-lora-sdv1-5",
35
+ choices=["latent-consistency/lcm-lora-sdv1-5", "None"])
36
+ sched = gr.Dropdown(label="Scheduler", value="LCM", choices=["LCM", "Euler A"])
37
+ init_img = gr.Image(label="Init Image (Optional)", type="pil", height=150)
38
+
39
+ prompts = gr.Code(label="Prompts (JSON)", language="json", height=150,
40
+ value='{\n "0": "a mystical forest, highly detailed, 8k",\n "40": "a forest fire, intricate details"\n}')
41
+ neg = gr.Textbox(label="Negative", value="blur, low quality, watermark")
42
+
43
+ with gr.Row():
44
+ frames = gr.Number(label="Frames", value=120, step=10)
45
+ steps = gr.Slider(2, 12, value=4, step=1, label="Steps (LCM: 4-8)")
46
+ cadence = gr.Slider(1, 4, value=1, step=1, label="Cadence (Warp-only frames)")
47
+ fps = gr.Number(label="FPS", value=12)
48
+
49
+ with gr.Accordion("🎬 Motion & Coherence", open=True):
50
+ with gr.Row():
51
+ color = gr.Dropdown(label="Color Match", value="LAB", choices=["None", "LAB", "HSV"])
52
+ border = gr.Dropdown(label="Border Mode", value="Reflect", choices=["Reflect", "Replicate", "Wrap", "Black"])
53
+
54
+ zoom = gr.Textbox(label="Zoom", value="0:(1.01)")
55
+ angle = gr.Textbox(label="Angle", value="0:(0.5*sin(t/10))")
56
+ tx = gr.Textbox(label="TX", value="0:(1*cos(t/15))")
57
+ ty = gr.Textbox(label="TY", value="0:(0)")
58
+ stre = gr.Textbox(label="Strength (Decay)", value="0:(0.65)")
59
+ noi = gr.Textbox(label="Noise (Grain)", value="0:(0.03)")
60
+
61
+ with gr.Row():
62
+ btn = gr.Button("Generate", variant="primary", scale=3)
63
+ stop = gr.Button("Stop", variant="stop", scale=1)
64
+
65
+ with gr.Column(scale=1):
66
+ img = gr.Image(label="Live Preview")
67
+ vid = gr.Video(label="Final Video")
68
+ files = gr.File(label="Frames ZIP")
69
+ stop_msg = gr.Markdown("", visible=True)
70
+
71
+ inputs = [prompts, neg, frames, gr.State(256), gr.State(256), zoom, angle, tx, ty, stre, noi, fps, steps, cadence, color, border, init_img, model, lora, sched]
72
+ btn.click(process, inputs=inputs, outputs=[img, vid, files])
73
+ stop.click(stop_gen, outputs=stop_msg)
74
+
75
+ if __name__ == "__main__":
76
+ demo.queue().launch(css=css, theme=gr.themes.Glass())