|
import gradio as gr |
|
import subprocess |
|
import os |
|
|
|
|
|
output_dir = './results' |
|
|
|
|
|
os.makedirs(output_dir, exist_ok=True) |
|
|
|
|
|
def generate_video(prompt, video_size, video_length, infer_steps, seed, save_path): |
|
|
|
command = [ |
|
"python3", "sample_video.py", |
|
"--prompt", prompt, |
|
"--video-size", video_size, |
|
"--video-length", str(video_length), |
|
"--infer-steps", str(infer_steps), |
|
"--seed", str(seed), |
|
"--save-path", save_path |
|
] |
|
|
|
|
|
try: |
|
subprocess.run(command, check=True) |
|
|
|
generated_video_path = os.path.join(save_path, "generated_video.mp4") |
|
return generated_video_path |
|
except subprocess.CalledProcessError as e: |
|
return f"Error generating video: {e}" |
|
|
|
|
|
def create_interface(): |
|
|
|
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter the prompt for the video.") |
|
video_size_input = gr.Textbox(label="Video Size", value="720 1280") |
|
video_length_input = gr.Slider(label="Video Length", minimum=1, maximum=200, value=129) |
|
infer_steps_input = gr.Slider(label="Inference Steps", minimum=1, maximum=100, value=30) |
|
seed_input = gr.Slider(label="Seed", minimum=0, maximum=1000, value=0) |
|
save_path_input = gr.Textbox(label="Save Path", value=output_dir) |
|
|
|
|
|
output_video = gr.Video(label="Generated Video") |
|
|
|
|
|
interface = gr.Interface( |
|
fn=generate_video, |
|
inputs=[prompt_input, video_size_input, video_length_input, infer_steps_input, seed_input, save_path_input], |
|
outputs=[output_video], |
|
live=True |
|
) |
|
|
|
|
|
interface.launch() |
|
|
|
if __name__ == "__main__": |
|
create_interface() |
|
|