Deforum_Soonr / app.py
AlekseyCalvin's picture
Update app.py
2932507 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;}
@font-face {
font-family: "Cadman Regular";
src: url("https://st.1001fonts.net/download/font/cadman.regular.otf") format('opentype');
body, .gradio-container {
font-family: "Cadman Regular", sans-serif !important;
background-color: #132015 !important;
color: #e0eecd;
}
.block {
border: 1px solid #1a2f1a;
border-radius: 4px;
box-shadow: 1px 1px 2px 1px #1D3A1B;
padding: 10px !important; /* Reduced padding like Merger */
}
}
"""
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# 🌀 DEFORUM SOON®🐢 DIFFUSION 🌀 ")
gr.Markdown(" ***whatever comes, here's a lazy lil cpu deforum animator for our forever | it's still better than we've known*** ")
gr.Markdown("#### MODEL SUGGESTIONS (below):| *Note:* cpu handles turbo/sx/lcm surprisingly ok @low-res|**strength**+**steps** are *KEY*:if both too low=diffusion dies;both too high=slow w/no flow|lower **strength** = more coherence/less detail|use schedules!|try my defaults")
gr.Markdown(" *Models in* **bold** *confirmed to work well here.* **cc-nms/tiny-sd-turbo**, **Disty0/LCM_SoteMix**, **AiArtLab/sdxs**, **rupeshs/sdxs-512-0.9-orig-vae**, **SimianLuo/LCM_Dreamshaper_v7**, runwayml/stable-diffusion-v1-5, segmind/tiny-sd, stabilityai/sdxl-turbo, CodeGoat24/sdxl-turbo-unified-reward-dpo, fluently/Fluently-XL-v3-Lightning, segmind/portrait-finetuned, qiacheng/stable-diffusion-v1-5-lcm, AiArtLab/sdxs-08b, 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")
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="cc-nms/tiny-sd-turbo")
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": "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}')
neg = gr.Textbox(label="Negative Prompt", value="bad, mangled, warped, worst, faint, blur")
with gr.Row():
frames = gr.Number(label="Frames", value=80)
fps = gr.Number(label="FPS", value=4)
with gr.Row():
width = gr.Slider(128, 1024, value=512, step=64, label="Width")
height = gr.Slider(128, 1024, value=256, step=64, label="Height")
with gr.Row():
steps = gr.Slider(1, 50, value=6, step=1, label="Steps")
cfg = gr.Slider(0.0, 20.0, value=0.5, step=0.1, label="CFG Scale (0-2 for Turbo/XS/LCM)")
cadence = gr.Slider(1, 8, value=2, step=1, label="Diffusion 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.00), 6:(1.00), 16:(.985), 26:(1.02), 45:(1.00), 60:(0.975), 70:(1.05)")
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)")
tx = gr.Textbox(label="Translation X", value="0:(0), 4:(-0.94) 18:(.8), 30:(-0.9), 50:(1.5), 64:(-2)")
ty = gr.Textbox(label="Translation Y", value="0:(0), 4:(-0.1) 10:(0.1), 20:(-0.3), 30:(0.3), 20:(-0.4), 30:(0.4), 40:(-0.5), 50:(0.5), 60:(-0.6), 70:(0.6)")
stre = gr.Textbox(label="Strength", value="0:(.75), 4:(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)")
noi = gr.Textbox(label="Noise Injection", value="0:(0.06), 20:(0.06), 30:(0.12), 40:(0.04), 60:(0.03), 76:(0.05)")
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(), mcp_server=True, share=True)