Spaces:
Running on Zero
Running on Zero
Vicente Alvarez commited on
Commit ·
73f86b7
1
Parent(s): dcbdf35
Fix: Multiple prompts (one per line) for different clips, not variations of same prompt
Browse files
app.py
CHANGED
|
@@ -401,7 +401,7 @@ def loop_clips_with_audio_track(clip_paths: list[str], audio_path: str) -> str:
|
|
| 401 |
def generate_video(
|
| 402 |
first_image,
|
| 403 |
last_image,
|
| 404 |
-
|
| 405 |
duration: float,
|
| 406 |
enhance_prompt: bool = True,
|
| 407 |
seed: int = 42,
|
|
@@ -411,7 +411,6 @@ def generate_video(
|
|
| 411 |
negative_prompt: str = DEFAULT_NEGATIVE_PROMPT,
|
| 412 |
blur_amount: int = 0,
|
| 413 |
remove_music: bool = False,
|
| 414 |
-
num_clips: int = 1,
|
| 415 |
progress=gr.Progress(track_tqdm=True),
|
| 416 |
):
|
| 417 |
try:
|
|
@@ -421,10 +420,10 @@ def generate_video(
|
|
| 421 |
base_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
|
| 422 |
generated_clips = []
|
| 423 |
|
| 424 |
-
# Generate multiple clips in one GPU session
|
| 425 |
-
for clip_idx in
|
| 426 |
current_seed = base_seed + clip_idx
|
| 427 |
-
print(f"[GPU] Generating clip {clip_idx + 1}/{
|
| 428 |
|
| 429 |
frame_rate = DEFAULT_FRAME_RATE
|
| 430 |
num_frames = int(duration * frame_rate) + 1
|
|
@@ -530,28 +529,35 @@ def full_generation_process(
|
|
| 530 |
negative_prompt: str,
|
| 531 |
blur_amount: int,
|
| 532 |
remove_music: bool,
|
| 533 |
-
num_clips: int,
|
| 534 |
audio_track,
|
| 535 |
progress=gr.Progress(track_tqdm=True),
|
| 536 |
):
|
| 537 |
"""Main entry point: generates clips (GPU) then optionally loops with audio (CPU)."""
|
| 538 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 539 |
# Phase 1: Generate clips (GPU time counted)
|
| 540 |
clips, final_seed = generate_video(
|
| 541 |
-
first_image, last_image,
|
| 542 |
seed, randomize_seed, height, width, negative_prompt,
|
| 543 |
-
blur_amount, remove_music,
|
| 544 |
)
|
| 545 |
|
| 546 |
if not clips:
|
| 547 |
return None, final_seed
|
| 548 |
|
| 549 |
# Phase 2: CPU work (free) - loop clips with audio if provided
|
| 550 |
-
if audio_track and
|
| 551 |
print("[CPU] Looping clips to match audio duration...")
|
| 552 |
final_video = loop_clips_with_audio_track(clips, audio_track)
|
| 553 |
return final_video, final_seed
|
| 554 |
-
elif
|
| 555 |
# Single clip - return it directly
|
| 556 |
return clips[0], final_seed
|
| 557 |
else:
|
|
@@ -573,17 +579,14 @@ with gr.Blocks(title="Element-8 Video", delete_cache=(3600, 7200)) as demo: # c
|
|
| 573 |
first_image = gr.Image(label="First Frame (Optional)", type="pil")
|
| 574 |
last_image = gr.Image(label="Last Frame (Optional)", type="pil")
|
| 575 |
prompt = gr.Textbox(
|
| 576 |
-
label="
|
| 577 |
-
info="
|
| 578 |
value="Make this image come alive with cinematic motion, smooth animation",
|
| 579 |
-
lines=
|
| 580 |
-
placeholder="
|
| 581 |
)
|
| 582 |
duration = gr.Slider(label="Duration (seconds)", minimum=1.0, maximum=10.0, value=3.0, step=0.1)
|
| 583 |
-
|
| 584 |
-
with gr.Row():
|
| 585 |
-
num_clips = gr.Slider(label="Number of Clips", info="Generate multiple variations", minimum=1, maximum=3, value=1, step=1)
|
| 586 |
-
audio_track = gr.Audio(label="Audio Track (Optional)", type="filepath", sources=["upload"])
|
| 587 |
|
| 588 |
generate_btn = gr.Button("Generate Video", variant="primary", size="lg")
|
| 589 |
|
|
@@ -657,7 +660,7 @@ with gr.Blocks(title="Element-8 Video", delete_cache=(3600, 7200)) as demo: # c
|
|
| 657 |
inputs=[
|
| 658 |
first_image, last_image, prompt, duration, enhance_prompt,
|
| 659 |
seed, randomize_seed, height, width, negative_prompt, blur_amount, remove_music,
|
| 660 |
-
|
| 661 |
],
|
| 662 |
outputs=[output_video, seed],
|
| 663 |
)
|
|
|
|
| 401 |
def generate_video(
|
| 402 |
first_image,
|
| 403 |
last_image,
|
| 404 |
+
prompts: list[str],
|
| 405 |
duration: float,
|
| 406 |
enhance_prompt: bool = True,
|
| 407 |
seed: int = 42,
|
|
|
|
| 411 |
negative_prompt: str = DEFAULT_NEGATIVE_PROMPT,
|
| 412 |
blur_amount: int = 0,
|
| 413 |
remove_music: bool = False,
|
|
|
|
| 414 |
progress=gr.Progress(track_tqdm=True),
|
| 415 |
):
|
| 416 |
try:
|
|
|
|
| 420 |
base_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
|
| 421 |
generated_clips = []
|
| 422 |
|
| 423 |
+
# Generate multiple clips in one GPU session (one per prompt)
|
| 424 |
+
for clip_idx, prompt in enumerate(prompts):
|
| 425 |
current_seed = base_seed + clip_idx
|
| 426 |
+
print(f"[GPU] Generating clip {clip_idx + 1}/{len(prompts)}, prompt: {prompt[:50]}..., seed={current_seed}")
|
| 427 |
|
| 428 |
frame_rate = DEFAULT_FRAME_RATE
|
| 429 |
num_frames = int(duration * frame_rate) + 1
|
|
|
|
| 529 |
negative_prompt: str,
|
| 530 |
blur_amount: int,
|
| 531 |
remove_music: bool,
|
|
|
|
| 532 |
audio_track,
|
| 533 |
progress=gr.Progress(track_tqdm=True),
|
| 534 |
):
|
| 535 |
"""Main entry point: generates clips (GPU) then optionally loops with audio (CPU)."""
|
| 536 |
|
| 537 |
+
# Parse prompts (one per line, max 3)
|
| 538 |
+
prompts = [p.strip() for p in prompt.split('\n') if p.strip()]
|
| 539 |
+
if not prompts:
|
| 540 |
+
return None, seed
|
| 541 |
+
prompts = prompts[:3] # Limit to 3 clips max
|
| 542 |
+
|
| 543 |
+
print(f"Generating {len(prompts)} clip(s)")
|
| 544 |
+
|
| 545 |
# Phase 1: Generate clips (GPU time counted)
|
| 546 |
clips, final_seed = generate_video(
|
| 547 |
+
first_image, last_image, prompts, duration, enhance_prompt,
|
| 548 |
seed, randomize_seed, height, width, negative_prompt,
|
| 549 |
+
blur_amount, remove_music, progress
|
| 550 |
)
|
| 551 |
|
| 552 |
if not clips:
|
| 553 |
return None, final_seed
|
| 554 |
|
| 555 |
# Phase 2: CPU work (free) - loop clips with audio if provided
|
| 556 |
+
if audio_track and len(clips) > 1:
|
| 557 |
print("[CPU] Looping clips to match audio duration...")
|
| 558 |
final_video = loop_clips_with_audio_track(clips, audio_track)
|
| 559 |
return final_video, final_seed
|
| 560 |
+
elif len(clips) == 1:
|
| 561 |
# Single clip - return it directly
|
| 562 |
return clips[0], final_seed
|
| 563 |
else:
|
|
|
|
| 579 |
first_image = gr.Image(label="First Frame (Optional)", type="pil")
|
| 580 |
last_image = gr.Image(label="Last Frame (Optional)", type="pil")
|
| 581 |
prompt = gr.Textbox(
|
| 582 |
+
label="Prompts (one per line for multiple clips)",
|
| 583 |
+
info="Enter 1-3 prompts, one per line. Each generates a separate clip.",
|
| 584 |
value="Make this image come alive with cinematic motion, smooth animation",
|
| 585 |
+
lines=5,
|
| 586 |
+
placeholder="Prompt 1...\nPrompt 2...\nPrompt 3...",
|
| 587 |
)
|
| 588 |
duration = gr.Slider(label="Duration (seconds)", minimum=1.0, maximum=10.0, value=3.0, step=0.1)
|
| 589 |
+
audio_track = gr.Audio(label="Audio Track (Optional)", info="If provided, clips will loop to match audio duration", type="filepath", sources=["upload"])
|
|
|
|
|
|
|
|
|
|
| 590 |
|
| 591 |
generate_btn = gr.Button("Generate Video", variant="primary", size="lg")
|
| 592 |
|
|
|
|
| 660 |
inputs=[
|
| 661 |
first_image, last_image, prompt, duration, enhance_prompt,
|
| 662 |
seed, randomize_seed, height, width, negative_prompt, blur_amount, remove_music,
|
| 663 |
+
audio_track,
|
| 664 |
],
|
| 665 |
outputs=[output_video, seed],
|
| 666 |
)
|