Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import gradio as gr
|
3 |
+
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
4 |
+
from diffusers.utils import export_to_video
|
5 |
+
|
6 |
+
pipeline = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b")
|
7 |
+
|
8 |
+
def generate_video(prompt):
|
9 |
+
# load pipeline
|
10 |
+
pipe = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b", torch_dtype=torch.float16, variant="fp16")
|
11 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
12 |
+
|
13 |
+
# optimize for GPU memory
|
14 |
+
pipe.enable_model_cpu_offload()
|
15 |
+
pipe.enable_vae_slicing()
|
16 |
+
|
17 |
+
# generate
|
18 |
+
video_frames = pipe(prompt, num_inference_steps=25, num_frames=200).frames
|
19 |
+
|
20 |
+
# convert to video
|
21 |
+
video_path = export_to_video(video_frames)
|
22 |
+
return video_path
|
23 |
+
|
24 |
+
iface = gr.Interface(fn=generate_video, inputs="text", outputs="file")
|
25 |
+
iface.launch()
|