Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import subprocess
|
3 |
+
import os
|
4 |
+
import random
|
5 |
+
|
6 |
+
# You can also import your real generate_video() from your comfy pipeline here
|
7 |
+
# For demo, this will simulate calling your WAN pipeline
|
8 |
+
|
9 |
+
WAN_SCRIPT = "generate_wan_video.py" # You can rename this to your actual comfy runner
|
10 |
+
|
11 |
+
def generate_video(prompt, negative_prompt, image, frames, fps):
|
12 |
+
# Save uploaded image
|
13 |
+
image_path = "/tmp/uploaded_image.png"
|
14 |
+
image.save(image_path)
|
15 |
+
|
16 |
+
output_path = f"/tmp/generated_{random.randint(1000,9999)}.mp4"
|
17 |
+
|
18 |
+
# Example: calling your WAN I2V pipeline (replace with actual command)
|
19 |
+
command = [
|
20 |
+
"python3", WAN_SCRIPT,
|
21 |
+
"--prompt", prompt,
|
22 |
+
"--negative_prompt", negative_prompt,
|
23 |
+
"--image", image_path,
|
24 |
+
"--frames", str(frames),
|
25 |
+
"--fps", str(fps),
|
26 |
+
"--output", output_path
|
27 |
+
]
|
28 |
+
|
29 |
+
print("Running command:", " ".join(command))
|
30 |
+
subprocess.run(command)
|
31 |
+
|
32 |
+
print("Generated:", output_path)
|
33 |
+
return output_path
|
34 |
+
|
35 |
+
# Gradio UI
|
36 |
+
with gr.Blocks() as demo:
|
37 |
+
gr.Markdown("## 🎬 WAN 2.1 I2V Video Generator\nUpload an image, enter a prompt — generate animated video!")
|
38 |
+
|
39 |
+
with gr.Row():
|
40 |
+
with gr.Column():
|
41 |
+
prompt = gr.Textbox(label="Positive Prompt", value="A beautiful anime girl turning around")
|
42 |
+
negative_prompt = gr.Textbox(label="Negative Prompt", value="ugly, low quality")
|
43 |
+
image = gr.Image(label="Input Image", type="pil")
|
44 |
+
frames = gr.Slider(label="Frames", minimum=8, maximum=64, step=1, value=32)
|
45 |
+
fps = gr.Slider(label="FPS", minimum=8, maximum=30, step=1, value=16)
|
46 |
+
generate_btn = gr.Button("Generate Video")
|
47 |
+
|
48 |
+
with gr.Column():
|
49 |
+
output_video = gr.Video(label="Generated Video")
|
50 |
+
|
51 |
+
generate_btn.click(
|
52 |
+
fn=generate_video,
|
53 |
+
inputs=[prompt, negative_prompt, image, frames, fps],
|
54 |
+
outputs=[output_video]
|
55 |
+
)
|
56 |
+
|
57 |
+
# Run Gradio app
|
58 |
+
if __name__ == "__main__":
|
59 |
+
demo.launch()
|