Spaces:
Running on Zero
Running on Zero
image-tab + gallery-build tab; progress fix; speech examples
Browse files
app.py
CHANGED
|
@@ -41,7 +41,22 @@ pipe.load_lora_weights(load_file(_lora_path), adapter_name="ingredients")
|
|
| 41 |
pipe.set_adapters("ingredients", LORA_SCALE)
|
| 42 |
|
| 43 |
|
| 44 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
imgs = [Image.open(p).convert("RGB") for p in paths]
|
| 46 |
if len(imgs) == 1:
|
| 47 |
return imgs[0]
|
|
@@ -59,13 +74,6 @@ def _compose_sheet(paths):
|
|
| 59 |
return canvas
|
| 60 |
|
| 61 |
|
| 62 |
-
def build_sheet_preview(files):
|
| 63 |
-
if not files:
|
| 64 |
-
return None
|
| 65 |
-
paths = [f if isinstance(f, str) else f.get("path", f.get("name")) for f in files]
|
| 66 |
-
return _compose_sheet(paths)
|
| 67 |
-
|
| 68 |
-
|
| 69 |
def _build_prompt(sheet, action):
|
| 70 |
return f"Reference sheet: {sheet.strip()}\n\nGenerated video: {action.strip()}"
|
| 71 |
|
|
@@ -82,9 +90,9 @@ def _duration(*args, **kwargs):
|
|
| 82 |
|
| 83 |
|
| 84 |
@spaces.GPU(duration=_duration)
|
| 85 |
-
def generate(
|
| 86 |
-
if
|
| 87 |
-
raise gr.Error("
|
| 88 |
if not sheet.strip():
|
| 89 |
raise gr.Error("Describe the elements in the reference sheet (characters, props, location).")
|
| 90 |
if not action.strip():
|
|
@@ -94,8 +102,7 @@ def generate(files, sheet, action, lora_scale, seed, randomize, progress=gr.Prog
|
|
| 94 |
seed = random.randint(0, MAX_SEED)
|
| 95 |
seed = int(seed)
|
| 96 |
|
| 97 |
-
|
| 98 |
-
sheet_img = _compose_sheet(paths).resize((WIDTH, HEIGHT), Image.LANCZOS)
|
| 99 |
ref = [sheet_img] * NUM_FRAMES
|
| 100 |
pipe.set_adapters("ingredients", float(lora_scale))
|
| 101 |
prompt = _build_prompt(sheet, action)
|
|
@@ -122,21 +129,25 @@ def generate(files, sheet, action, lora_scale, seed, randomize, progress=gr.Prog
|
|
| 122 |
with gr.Blocks(title="LTX-2.3 Ingredients (Fast)") as demo:
|
| 123 |
gr.Markdown(
|
| 124 |
"# ⚡ LTX-2.3 Ingredients — Fast (Distilled)\n"
|
| 125 |
-
"Reference-sheet control, fast.
|
| 126 |
-
"**Upload a ready sheet, or several subject images and we'll tile them into one.** Using "
|
| 127 |
"[LTX 2.3 Distilled](https://huggingface.co/diffusers/LTX-2.3-Distilled-Diffusers) with the "
|
| 128 |
"[Ingredients IC-LoRA](https://huggingface.co/ltx-community/LTX-2.3-loras), via diffusers 🧨. "
|
| 129 |
"(For maximum fidelity, see the Dev demo.)"
|
| 130 |
)
|
| 131 |
with gr.Row():
|
| 132 |
with gr.Column():
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
sheet = gr.Textbox(label="Reference sheet description", lines=3,
|
| 137 |
placeholder="a young woman with red hair in a green jacket (face close-up + turnaround); a brass pocket watch; a cobblestone alley at night")
|
| 138 |
-
action = gr.Textbox(label="Generated video —
|
| 139 |
-
placeholder="the woman walks down the alley
|
| 140 |
with gr.Accordion("Settings", open=False):
|
| 141 |
lora_scale = gr.Slider(0.8, 1.8, value=1.4, step=0.05, label="LoRA strength")
|
| 142 |
randomize = gr.Checkbox(True, label="Randomize seed")
|
|
@@ -146,25 +157,25 @@ with gr.Blocks(title="LTX-2.3 Ingredients (Fast)") as demo:
|
|
| 146 |
video_out = gr.Video(label="Generated video")
|
| 147 |
used_seed = gr.Number(label="Seed used", interactive=False)
|
| 148 |
|
| 149 |
-
|
| 150 |
-
run.click(generate, inputs=[
|
| 151 |
|
| 152 |
gr.Examples(
|
| 153 |
examples=[
|
| 154 |
-
[
|
| 155 |
"a cartoon hedgehog (face close-up and body turnaround) and a cartoon rabbit (turnaround); a green coiled garden hose reel and green spray bottles; the interior of a 'Greenfield Home & Garden' store with shelves of plants",
|
| 156 |
-
"the hedgehog
|
| 157 |
1.4, 42, False],
|
| 158 |
-
[
|
| 159 |
"a young woman hiker in a green shirt and khaki shorts (face close-up and body turnaround); a large blue hiking backpack; a wooden walking stick; a shaggy yak with a colorful woven saddle blanket; a Himalayan stone village with prayer flags and snowy mountains",
|
| 160 |
-
"the woman loads the blue backpack onto the yak
|
| 161 |
1.4, 42, False],
|
| 162 |
-
[
|
| 163 |
"a smiling young woman with curly dark hair; a dappled grey horse; a green misty mountain meadow",
|
| 164 |
-
"the woman walks up to the grey horse in the misty meadow
|
| 165 |
1.4, 42, False],
|
| 166 |
],
|
| 167 |
-
inputs=[
|
| 168 |
outputs=[video_out, used_seed], fn=generate, cache_examples=True, cache_mode="lazy",
|
| 169 |
)
|
| 170 |
|
|
|
|
| 41 |
pipe.set_adapters("ingredients", LORA_SCALE)
|
| 42 |
|
| 43 |
|
| 44 |
+
def _gallery_paths(gallery):
|
| 45 |
+
paths = []
|
| 46 |
+
for item in gallery or []:
|
| 47 |
+
if isinstance(item, (list, tuple)):
|
| 48 |
+
item = item[0]
|
| 49 |
+
if isinstance(item, dict):
|
| 50 |
+
item = item.get("path") or item.get("name") or item.get("image")
|
| 51 |
+
if isinstance(item, str):
|
| 52 |
+
paths.append(item)
|
| 53 |
+
return paths
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def compose_sheet(gallery):
|
| 57 |
+
paths = _gallery_paths(gallery)
|
| 58 |
+
if not paths:
|
| 59 |
+
raise gr.Error("Upload at least one subject image to build a sheet.")
|
| 60 |
imgs = [Image.open(p).convert("RGB") for p in paths]
|
| 61 |
if len(imgs) == 1:
|
| 62 |
return imgs[0]
|
|
|
|
| 74 |
return canvas
|
| 75 |
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
def _build_prompt(sheet, action):
|
| 78 |
return f"Reference sheet: {sheet.strip()}\n\nGenerated video: {action.strip()}"
|
| 79 |
|
|
|
|
| 90 |
|
| 91 |
|
| 92 |
@spaces.GPU(duration=_duration)
|
| 93 |
+
def generate(sheet_image, sheet, action, lora_scale, seed, randomize, progress=gr.Progress()):
|
| 94 |
+
if sheet_image is None:
|
| 95 |
+
raise gr.Error("Add a reference sheet (upload one, or build one from subject images in the other tab).")
|
| 96 |
if not sheet.strip():
|
| 97 |
raise gr.Error("Describe the elements in the reference sheet (characters, props, location).")
|
| 98 |
if not action.strip():
|
|
|
|
| 102 |
seed = random.randint(0, MAX_SEED)
|
| 103 |
seed = int(seed)
|
| 104 |
|
| 105 |
+
sheet_img = sheet_image.convert("RGB").resize((WIDTH, HEIGHT), Image.LANCZOS)
|
|
|
|
| 106 |
ref = [sheet_img] * NUM_FRAMES
|
| 107 |
pipe.set_adapters("ingredients", float(lora_scale))
|
| 108 |
prompt = _build_prompt(sheet, action)
|
|
|
|
| 129 |
with gr.Blocks(title="LTX-2.3 Ingredients (Fast)") as demo:
|
| 130 |
gr.Markdown(
|
| 131 |
"# ⚡ LTX-2.3 Ingredients — Fast (Distilled)\n"
|
| 132 |
+
"Reference-sheet control, fast. Upload a ready sheet, or build one from individual subject images. Using "
|
|
|
|
| 133 |
"[LTX 2.3 Distilled](https://huggingface.co/diffusers/LTX-2.3-Distilled-Diffusers) with the "
|
| 134 |
"[Ingredients IC-LoRA](https://huggingface.co/ltx-community/LTX-2.3-loras), via diffusers 🧨. "
|
| 135 |
"(For maximum fidelity, see the Dev demo.)"
|
| 136 |
)
|
| 137 |
with gr.Row():
|
| 138 |
with gr.Column():
|
| 139 |
+
with gr.Tabs():
|
| 140 |
+
with gr.Tab("Reference sheet"):
|
| 141 |
+
sheet_image = gr.Image(type="pil", label="Reference sheet (composite of characters / props / location)")
|
| 142 |
+
with gr.Tab("Build from subject images"):
|
| 143 |
+
gallery = gr.Gallery(label="Upload subject images (characters, props, location)",
|
| 144 |
+
type="filepath", interactive=True, columns=4, height=240)
|
| 145 |
+
build_btn = gr.Button("Build reference sheet ➜")
|
| 146 |
+
gr.Markdown("*Tiles your images into one sheet and loads it into the **Reference sheet** tab.*")
|
| 147 |
sheet = gr.Textbox(label="Reference sheet description", lines=3,
|
| 148 |
placeholder="a young woman with red hair in a green jacket (face close-up + turnaround); a brass pocket watch; a cobblestone alley at night")
|
| 149 |
+
action = gr.Textbox(label="Generated video — action / shot, plus any speech & sounds", lines=3,
|
| 150 |
+
placeholder="the woman walks down the alley, checks the pocket watch and whispers 'almost time'; footsteps on cobblestone, distant city hum")
|
| 151 |
with gr.Accordion("Settings", open=False):
|
| 152 |
lora_scale = gr.Slider(0.8, 1.8, value=1.4, step=0.05, label="LoRA strength")
|
| 153 |
randomize = gr.Checkbox(True, label="Randomize seed")
|
|
|
|
| 157 |
video_out = gr.Video(label="Generated video")
|
| 158 |
used_seed = gr.Number(label="Seed used", interactive=False)
|
| 159 |
|
| 160 |
+
build_btn.click(compose_sheet, inputs=gallery, outputs=sheet_image)
|
| 161 |
+
run.click(generate, inputs=[sheet_image, sheet, action, lora_scale, seed, randomize], outputs=[video_out, used_seed])
|
| 162 |
|
| 163 |
gr.Examples(
|
| 164 |
examples=[
|
| 165 |
+
["examples/sheet_garden.png",
|
| 166 |
"a cartoon hedgehog (face close-up and body turnaround) and a cartoon rabbit (turnaround); a green coiled garden hose reel and green spray bottles; the interior of a 'Greenfield Home & Garden' store with shelves of plants",
|
| 167 |
+
"the hedgehog waddles up to the camera in the Greenfield Home & Garden store and says cheerfully 'Welcome to Greenfield!', while the rabbit hops past holding a green spray bottle; upbeat store music, the hedgehog's friendly voice and soft footsteps",
|
| 168 |
1.4, 42, False],
|
| 169 |
+
["examples/sheet_hiker.png",
|
| 170 |
"a young woman hiker in a green shirt and khaki shorts (face close-up and body turnaround); a large blue hiking backpack; a wooden walking stick; a shaggy yak with a colorful woven saddle blanket; a Himalayan stone village with prayer flags and snowy mountains",
|
| 171 |
+
"the woman loads the blue backpack onto the yak, pats its neck and says warmly 'almost at the summit, buddy', snowy peaks and a monastery behind her; wind, distant prayer bells, her voice and the yak's low grunt",
|
| 172 |
1.4, 42, False],
|
| 173 |
+
["examples/subj_composite.png",
|
| 174 |
"a smiling young woman with curly dark hair; a dappled grey horse; a green misty mountain meadow",
|
| 175 |
+
"the woman walks up to the grey horse in the misty meadow, gently strokes its neck and says softly 'good boy, easy now'; a soft horse nicker, her gentle voice, light wind and birdsong",
|
| 176 |
1.4, 42, False],
|
| 177 |
],
|
| 178 |
+
inputs=[sheet_image, sheet, action, lora_scale, seed, randomize],
|
| 179 |
outputs=[video_out, used_seed], fn=generate, cache_examples=True, cache_mode="lazy",
|
| 180 |
)
|
| 181 |
|