AlekseyCalvin commited on
Commit
c3502b3
·
verified ·
1 Parent(s): 512cf8c

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
+ # Initialize Engine
6
+ runner = DeforumRunner(device="cpu")
7
+
8
+ def process(
9
+ prompts_json, neg_prompt, max_frames,
10
+ width, height,
11
+ zoom, angle, tx, ty,
12
+ strength, noise,
13
+ fps, steps
14
+ ):
15
+ # Validate JSON
16
+ try:
17
+ # Convert single quotes to double if user messed up
18
+ prompts_json = prompts_json.replace("'", '"')
19
+ # Ensure keys are integers
20
+ prompts_dict = json.loads(prompts_json)
21
+ prompts_fixed = {int(k): v for k, v in prompts_dict.items()}
22
+ except:
23
+ # Fallback manual parse
24
+ try:
25
+ prompts_fixed = eval(prompts_json)
26
+ except:
27
+ return None, None, None, "Error parsing prompts JSON"
28
+
29
+ return runner.render(
30
+ prompts_fixed, neg_prompt, int(max_frames),
31
+ int(width), int(height),
32
+ zoom, angle, tx, ty,
33
+ strength, noise,
34
+ int(fps), int(steps)
35
+ )
36
+
37
+ css = """
38
+ #col-container {max_width: 900px; margin-left: auto; margin-right: auto;}
39
+ """
40
+
41
+ with gr.Blocks() as demo:
42
+ gr.Markdown("# 🌀 Authentic Deforum (CPU/SDXS)")
43
+ gr.Markdown("""
44
+ **Core Config:**
45
+ * **Model:** SDXS-512-0.9 (Fast 1-step capable).
46
+ * **Authenticity:** Full 2D Warping, Noise Schedules, and Img2Img Loopback.
47
+ * **Tip:** Keep `Steps` around 3-4. If you use 1 step, 'Strength' (fade) will not work and frames will look disjointed.
48
+ """)
49
+
50
+ with gr.Row():
51
+ with gr.Column():
52
+ # Prompts
53
+ prompts_input = gr.Code(
54
+ label="Prompts (JSON format)",
55
+ value='{\n "0": "tiny cute swamp bunny, highly detailed, intricate, 8k",\n "30": "anthro swamp bunny, cyberpunk city background, neon lights"\n}',
56
+ language="json"
57
+ )
58
+ neg_prompt = gr.Textbox(label="Negative Prompt", value="nsfw, nude, watermark, text, blurry")
59
+
60
+ with gr.Row():
61
+ max_frames = gr.Number(label="Max Frames", value=120, precision=0)
62
+ fps = gr.Number(label="FPS", value=12, precision=0)
63
+ steps = gr.Slider(1, 10, value=3, step=1, label="Steps (Rec: 3+)")
64
+
65
+ with gr.Accordion("Motion Settings", open=True):
66
+ gr.Markdown("Supports Math: `sin(t/10)`, `t*0.5`, etc. `t` = frame index.")
67
+ angle = gr.Textbox(label="Angle (deg)", value="0:(0)")
68
+ zoom = gr.Textbox(label="Zoom (1.0 = static)", value="0:(1.0 + 0.01*sin(t/20))")
69
+ tx = gr.Textbox(label="Translation X", value="0:(2*sin(t/10))")
70
+ ty = gr.Textbox(label="Translation Y", value="0:(0)")
71
+
72
+ with gr.Accordion("Coherence (The 'Glue')", open=True):
73
+ strength = gr.Textbox(label="Strength Schedule (0.0-1.0)", value="0:(0.65)")
74
+ noise = gr.Textbox(label="Noise Schedule (0.0-1.0)", value="0:(0.04)")
75
+
76
+ run_btn = gr.Button("Generate Animation", variant="primary")
77
+
78
+ with gr.Column():
79
+ out_image = gr.Image(label="Last Frame", type="pil")
80
+ out_video = gr.Video(label="Video Output")
81
+ out_zip = gr.File(label="Download Frames")
82
+
83
+ run_btn.click(
84
+ fn=process,
85
+ inputs=[
86
+ prompts_input, neg_prompt, max_frames,
87
+ gr.State(256), gr.State(256), # Fixed resolution for CPU speed
88
+ zoom, angle, tx, ty,
89
+ strength, noise,
90
+ fps, steps
91
+ ],
92
+ outputs=[out_image, out_video, out_zip]
93
+ )
94
+
95
+ if __name__ == "__main__":
96
+ demo.launch(css=css, theme=gr.themes.Glass())