|
import gradio as gr |
|
import subprocess |
|
import os |
|
import random |
|
|
|
|
|
|
|
|
|
WAN_SCRIPT = "generate_wan_video.py" |
|
|
|
def generate_video(prompt, negative_prompt, image, frames, fps): |
|
|
|
image_path = "/tmp/uploaded_image.png" |
|
image.save(image_path) |
|
|
|
output_path = f"/tmp/generated_{random.randint(1000,9999)}.mp4" |
|
|
|
|
|
command = [ |
|
"python3", WAN_SCRIPT, |
|
"--prompt", prompt, |
|
"--negative_prompt", negative_prompt, |
|
"--image", image_path, |
|
"--frames", str(frames), |
|
"--fps", str(fps), |
|
"--output", output_path |
|
] |
|
|
|
print("Running command:", " ".join(command)) |
|
subprocess.run(command) |
|
|
|
print("Generated:", output_path) |
|
return output_path |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("## π¬ WAN 2.1 I2V Video Generator\nUpload an image, enter a prompt β generate animated video!") |
|
|
|
with gr.Row(): |
|
with gr.Column(): |
|
prompt = gr.Textbox(label="Positive Prompt", value="A beautiful anime girl turning around") |
|
negative_prompt = gr.Textbox(label="Negative Prompt", value="ugly, low quality") |
|
image = gr.Image(label="Input Image", type="pil") |
|
frames = gr.Slider(label="Frames", minimum=8, maximum=64, step=1, value=32) |
|
fps = gr.Slider(label="FPS", minimum=8, maximum=30, step=1, value=16) |
|
generate_btn = gr.Button("Generate Video") |
|
|
|
with gr.Column(): |
|
output_video = gr.Video(label="Generated Video") |
|
|
|
generate_btn.click( |
|
fn=generate_video, |
|
inputs=[prompt, negative_prompt, image, frames, fps], |
|
outputs=[output_video] |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|