Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
import torch
|
3 |
from diffusers.utils import export_to_video
|
4 |
from diffusers import AutoencoderKLWan, WanPipeline
|
@@ -6,13 +6,7 @@ from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepSchedu
|
|
6 |
import os
|
7 |
from uuid import uuid4
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
@app.route('/')
|
12 |
-
def index():
|
13 |
-
return jsonify({"message": "Welcome to the Wan2.1 Video Generation API!", "status": "running"})
|
14 |
-
|
15 |
-
# Load the model once at startup
|
16 |
model_id = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
|
17 |
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
|
18 |
scheduler = UniPCMultistepScheduler(
|
@@ -25,16 +19,8 @@ pipe = WanPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16
|
|
25 |
pipe.scheduler = scheduler
|
26 |
pipe.to("cuda")
|
27 |
|
28 |
-
|
29 |
-
def generate_video():
|
30 |
-
data = request.json
|
31 |
-
prompt = data.get('prompt')
|
32 |
-
negative_prompt = data.get('negative_prompt', '')
|
33 |
-
height = data.get('height', 720)
|
34 |
-
width = data.get('width', 1280)
|
35 |
-
num_frames = data.get('num_frames', 81)
|
36 |
-
guidance_scale = data.get('guidance_scale', 5.0)
|
37 |
-
|
38 |
output = pipe(
|
39 |
prompt=prompt,
|
40 |
negative_prompt=negative_prompt,
|
@@ -49,7 +35,22 @@ def generate_video():
|
|
49 |
os.makedirs("outputs", exist_ok=True)
|
50 |
export_to_video(output, output_path, fps=16)
|
51 |
|
52 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
-
|
55 |
-
app.run(host='0.0.0.0', port=7860)
|
|
|
1 |
+
import gradio as gr
|
2 |
import torch
|
3 |
from diffusers.utils import export_to_video
|
4 |
from diffusers import AutoencoderKLWan, WanPipeline
|
|
|
6 |
import os
|
7 |
from uuid import uuid4
|
8 |
|
9 |
+
# Load model on startup
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
model_id = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
|
11 |
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
|
12 |
scheduler = UniPCMultistepScheduler(
|
|
|
19 |
pipe.scheduler = scheduler
|
20 |
pipe.to("cuda")
|
21 |
|
22 |
+
# Define the generation function
|
23 |
+
def generate_video(prompt, negative_prompt="", height=720, width=1280, num_frames=81, guidance_scale=5.0):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
output = pipe(
|
25 |
prompt=prompt,
|
26 |
negative_prompt=negative_prompt,
|
|
|
35 |
os.makedirs("outputs", exist_ok=True)
|
36 |
export_to_video(output, output_path, fps=16)
|
37 |
|
38 |
+
return output_path # Gradio returns this as downloadable file/video
|
39 |
+
|
40 |
+
# Gradio Interface
|
41 |
+
iface = gr.Interface(
|
42 |
+
fn=generate_video,
|
43 |
+
inputs=[
|
44 |
+
gr.Textbox(label="Prompt"),
|
45 |
+
gr.Textbox(label="Negative Prompt", value=""),
|
46 |
+
gr.Number(label="Height", value=720),
|
47 |
+
gr.Number(label="Width", value=1280),
|
48 |
+
gr.Number(label="Number of Frames", value=81),
|
49 |
+
gr.Number(label="Guidance Scale", value=5.0)
|
50 |
+
],
|
51 |
+
outputs=gr.File(label="Generated Video"),
|
52 |
+
title="Wan2.1 Video Generator",
|
53 |
+
description="Generate realistic videos from text prompts using the Wan2.1 T2V model."
|
54 |
+
)
|
55 |
|
56 |
+
iface.launch()
|
|