Spaces:
Runtime error
Runtime error
File size: 5,989 Bytes
a5fc5ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
from typing import Dict
import gradio as gr
import json
from cinematic_planning import build_scene_sequence
from generation import generate_video
from prompt_template_control import generate_video_prompt_with_template
from storyboard import generate_multiple_storyboards
def save_storyboard_choice(choice: Dict[str, str]):
# Save the full dictionary as JSON (append mode)
with open("selected_storyboards.json", "a") as f:
f.write(json.dumps(choice) + "\n")
return f"β
Saved your selection to selected_storyboards.json:\n\n{json.dumps(choice, indent=2)}"
# Connect button
def run_pseudo_video_workflow(scene, shot_type, emotion, model_choice, num_keyframes):
# Build storyboard dict
storyboard = {
"scene": scene,
"shot_type": shot_type,
"emotion": emotion
}
# Call your iterative builder
scene_sequence = build_scene_sequence(
storyboard, model_choice, num_keyframes=num_keyframes
)
# Format result as text
result_text = ""
for i, step in enumerate(scene_sequence):
result_text += f"\nKeyframe {i + 1}:\n"
result_text += f"Transition: {step['transition_text']}\n"
result_text += f"Video Path: {step['video_path']}\n"
return result_text
if __name__ == "__main__":
with gr.Blocks() as demo:
gr.Markdown("# π₯ Video Generator")
# Video Generator Interface
with gr.Row():
with gr.Column():
video_prompt = gr.Textbox(label="Enter your video prompt")
negative_prompt = gr.Textbox(label="Enter your negative prompt (optional: Wan2.1 Only)")
model_choice = gr.Radio(
choices=["SkyReels-V2", "Wan2.1", "Veo-2", "T2V-01-Director"],
label="Choose the video generation model"
)
generate_btn = gr.Button("Generate Video")
with gr.Column():
video_output = gr.Video(label="Generated Video")
generate_btn.click(
generate_video,
inputs=[video_prompt, model_choice, negative_prompt],
outputs=video_output
)
# Divider
gr.Markdown("---")
# Narrative to Storyboard interface
gr.Markdown("# π¬ Narrative to Storyboard Grounding")
narrative_input = gr.Textbox(label="Enter your narrative")
generate_storyboards_btn = gr.Button("Generate 5 Storyboards")
storyboards_output = gr.Radio(
choices=[],
label="Select your preferred storyboard"
)
save_choice_btn = gr.Button("Save Selection")
save_output = gr.Textbox(label="Save Output", interactive=False)
# Generate the storyboards
def update_storyboards(narrative):
cards = generate_multiple_storyboards(narrative)
return gr.update(choices=cards)
generate_storyboards_btn.click(
update_storyboards,
inputs=narrative_input,
outputs=storyboards_output
)
# Save the choice
save_choice_btn.click(
save_storyboard_choice,
inputs=storyboards_output,
outputs=save_output
)
gr.Markdown("---")
# Prompt Injection + Template Control
gr.Markdown("# π₯ Prompt Injection + Template Control (LLM + T2V)")
# Modular controls
role_input = gr.Textbox(label="Role", placeholder="e.g., Product demo")
setting_input = gr.Textbox(label="Setting", placeholder="e.g., Urban bar")
emotion_input = gr.Textbox(label="Emotion", placeholder="e.g., Energetic")
shot_input = gr.Textbox(label="Shot Type", placeholder="e.g., Front-facing")
duration_input = gr.Textbox(label="Duration", placeholder="e.g., 5s loop")
# Model selection
model_choice = gr.Radio(
choices=["SkyReels-V2", "Veo-2", "Runway", "T2V-01-Director"],
label="Choose video generation model"
)
# Generate final natural language prompt
generate_prompt_btn = gr.Button("Generate Final Prompt")
final_prompt_output = gr.Textbox(label="Final Video Prompt", interactive=False)
# Generate video
generate_video_btn = gr.Button("Generate Video")
video_output = gr.Video(label="Generated Video")
# Connect callbacks
generate_prompt_btn.click(
generate_video_prompt_with_template,
inputs=[role_input, setting_input, emotion_input, shot_input, duration_input],
outputs=final_prompt_output
)
generate_video_btn.click(
generate_video,
inputs=[final_prompt_output, model_choice, negative_prompt],
outputs=video_output
)
gr.Markdown("# ποΈ Pseudo Video Workflow (Storyboard β Scene Builder)")
# Storyboard inputs
pseudo_scene_input = gr.Textbox(label="Scene", placeholder="e.g., Misty forest")
pseudo_shot_input = gr.Textbox(label="Shot Type", placeholder="e.g., Wide shot")
pseudo_emotion_input = gr.Textbox(label="Emotion", placeholder="e.g., Mysterious")
pseudo_model_choice = gr.Radio(
choices=["SkyReels-V2", "Wan2.1", "Veo-2", "T2V-01-Director"],
label="Choose video generation model"
)
num_keyframes_input = gr.Slider(minimum=1, maximum=20, value=12, label="Number of Keyframes")
run_pseudo_video_btn = gr.Button("Build Pseudo Video Workflow")
pseudo_output = gr.Textbox(label="Workflow Result", lines=10)
# Hook to Gradio button
run_pseudo_video_btn.click(
run_pseudo_video_workflow,
inputs=[
pseudo_scene_input,
pseudo_shot_input,
pseudo_emotion_input,
pseudo_model_choice,
num_keyframes_input
],
outputs=pseudo_output
)
demo.launch()
|