Wan2.1 / app.py
IAMTFRMZA's picture
Create app.py
3f975b2 verified
raw
history blame
1.98 kB
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()