Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import os
|
3 |
+
import gradio as gr
|
4 |
+
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
5 |
+
from diffusers.utils import export_to_video
|
6 |
+
from IPython.display import HTML
|
7 |
+
from base64 import b64encode
|
8 |
+
|
9 |
+
pipe = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b", torch_dtype=torch.float16, variant="fp16")
|
10 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
11 |
+
pipe.enable_model_cpu_offload()
|
12 |
+
pipe.enable_vae_slicing()
|
13 |
+
|
14 |
+
def model(txt, time):
|
15 |
+
prompt = txt
|
16 |
+
video_duration_seconds = time
|
17 |
+
num_frames = video_duration_seconds * 10
|
18 |
+
video_frames = pipe(prompt, negative_prompt="low quality",
|
19 |
+
num_inference_steps=25, num_frames=num_frames).frames
|
20 |
+
video_path = export_to_video(video_frames)
|
21 |
+
return video_path
|
22 |
+
|
23 |
+
demo = gr.Interface(
|
24 |
+
fn=model,
|
25 |
+
inputs=["text", gr.Slider(1, 10, step=1)],
|
26 |
+
outputs=gr.Video(label="Out",output_width=400, output_height=300)
|
27 |
+
)
|
28 |
+
|
29 |
+
demo.launch(inline = False)
|