Deforum_Soonr / appVar5.py
AlekseyCalvin's picture
Rename app.py to appVar5.py
d46a1b1 verified
import gradio as gr
import json
from deforum_engine import DeforumRunner
runner = DeforumRunner(device="cpu")
def process(model, lora, sched, prompts, neg,
frames, width, height, fps, steps, cfg, seed, seed_beh,
zoom, angle, tx, ty, stre, noi,
color, cadence, border, use_init, init_img):
if not use_init: init_img = None
# Dictionary packing allows for cleaner code in the engine
args = {
'model': model, 'lora': lora, 'sched': sched,
'prompts': prompts, 'neg': neg,
'max_frames': frames, 'W': width, 'H': height,
'zoom': zoom, 'angle': angle, 'tx': tx, 'ty': ty,
'strength': stre, 'noise': noi,
'fps': fps, 'steps': steps, 'cfg': cfg, 'cadence': cadence,
'color': color, 'border': border, 'seed_beh': seed_beh,
'init_image': init_img, 'use_init': use_init, 'seed': seed
}
yield from runner.render(args)
def stop_gen():
runner.stop()
return "Stopping..."
css = "#col-container {max_width: 1000px; margin: 0 auto;}"
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# 🌀 Deforum Soon® CPU")
gr.Markdown("**Model Suggestions:** AiArtLab/sdxs, runwayml/stable-diffusion-v1-5, stabilityai/sdxl-turbo, CodeGoat24/sdxl-turbo-unified-reward-dpo, fluently/Fluently-XL-v3-Lightning, stabilityai/sd-turbo, SimianLuo/LCM_Dreamshaper_v7, rupeshs/sdxs-512-0.9-orig-vae, Disty0/LCM_SoteMix, qiacheng/stable-diffusion-v1-5-lcm, AiArtLab/sdxs-08b | LoRA: latent-consistency/lcm-lora-sdv1-5")
with gr.Row():
with gr.Column():
with gr.Accordion("Pipeline Config", open=True):
# TEXTBOXES allows any model
model = gr.Textbox(label="Model ID (HuggingFace)", value="rupeshs/sdxs-512-0.9-orig-vae")
lora = gr.Textbox(label="LoRA ID (Optional)", value="")
sched = gr.Dropdown(label="Scheduler", value="Euler A", choices=["LCM", "Euler A", "DDIM", "DPM++ 2M"])
seed_beh = gr.Dropdown(label="Seed Behavior", value="iter", choices=["iter", "fixed", "random"])
init_img = gr.Image(label="Init Image", type="pil", height=200)
use_init = gr.Checkbox(label="Use Init Image", value=False)
prompts = gr.Code(label="Prompts (JSON)", language="json",
value='{\n "0": "a simple black line drawing of a cat, white background",\n "30": "a simple black line drawing of a dog, white background"\n}')
neg = gr.Textbox(label="Negative Prompt", value="complex, realistic, photo, blur")
with gr.Row():
frames = gr.Number(label="Frames", value=30)
fps = gr.Number(label="FPS", value=4)
with gr.Row():
width = gr.Slider(256, 512, value=256, step=64, label="Width")
height = gr.Slider(256, 512, value=256, step=64, label="Height")
with gr.Row():
steps = gr.Slider(1, 50, value=2, step=1, label="Steps")
cfg = gr.Slider(0.0, 20.0, value=1.0, step=0.1, label="CFG Scale (0-2 for SDXS/LCM)")
cadence = gr.Slider(1, 8, value=5, step=1, label="Cadence")
with gr.Accordion("🎬 Motion & Coherence", open=True):
with gr.Row():
color = gr.Dropdown(label="Color Match", value="LAB", choices=["None", "LAB", "HSV", "RGB"])
border = gr.Dropdown(label="Border Mode", value="Replicate", choices=["Reflect", "Replicate", "Wrap", "Black"])
z = gr.Textbox(label="Zoom", value="0:(1.0)")
a = gr.Textbox(label="Angle", value="0:(2)")
tx = gr.Textbox(label="Translation X", value="0:(0.3)")
ty = gr.Textbox(label="Translation Y", value="0:(0)")
stre = gr.Textbox(label="Strength", value="0:(0.25)")
noi = gr.Textbox(label="Noise", value="0:(0.04)")
with gr.Row():
btn = gr.Button("GENERATE", variant="primary", scale=2)
stop = gr.Button("STOP", variant="stop", scale=1)
with gr.Column(scale=1):
status = gr.Markdown("Ready")
preview = gr.Image(label="Last Frame")
video_out = gr.Video(label="Rendered Video")
zip_out = gr.File(label="Frames ZIP")
inputs = [
model, lora, sched, prompts, neg,
frames, width, height, fps, steps, cfg, gr.State(-1), seed_beh,
z, a, tx, ty, stre, noi,
color, cadence, border, use_init, init_img
]
btn.click(process, inputs=inputs, outputs=[preview, video_out, zip_out, status])
stop.click(stop_gen, outputs=status)
demo.queue().launch(css=css, theme=gr.themes.Glass())