File size: 1,980 Bytes
3f975b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import subprocess
import os
import random

# You can also import your real generate_video() from your comfy pipeline here
# For demo, this will simulate calling your WAN pipeline

WAN_SCRIPT = "generate_wan_video.py"  # You can rename this to your actual comfy runner

def generate_video(prompt, negative_prompt, image, frames, fps):
    # Save uploaded image
    image_path = "/tmp/uploaded_image.png"
    image.save(image_path)

    output_path = f"/tmp/generated_{random.randint(1000,9999)}.mp4"

    # Example: calling your WAN I2V pipeline (replace with actual command)
    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

# Gradio UI
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]
    )

# Run Gradio app
if __name__ == "__main__":
    demo.launch()