Omnibus commited on
Commit
a5ec285
·
1 Parent(s): 772e2a0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
4
+ from diffusers.utils import export_to_video
5
+
6
+ # load pipeline
7
+ pipe = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b", torch_dtype=torch.float16, variant="fp16")
8
+ pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
9
+
10
+ # optimize for GPU memory
11
+ pipe.enable_model_cpu_offload()
12
+ pipe.enable_vae_slicing()
13
+ def ttv():
14
+
15
+ # generate
16
+ prompt = "Spiderman is surfing. Darth Vader is also surfing and following Spiderman"
17
+ video_frames = pipe(prompt, num_inference_steps=25, num_frames=200).frames
18
+
19
+ # convent to video
20
+ video_path = export_to_video(video_frames)
21
+ return video_path
22
+
23
+ with gr.Blocks() as app:
24
+ inp = gr.Textbox()
25
+ btn = gr.Button()
26
+ outp = gr.Video()
27
+ btn.click(ttv,None,outp)
28
+ app.launch()