JoeS51 commited on
Commit
280b1ae
·
1 Parent(s): bfb6e25

animate diff model for vid gen

Browse files
Files changed (2) hide show
  1. app.py +29 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import AnimateDiffPipeline
4
+ from PIL import Image
5
+ import tempfile
6
+ import os
7
+
8
+ pipe = AnimateDiffPipeline.from_pretrained(
9
+ "guoyww/animatediff", torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
10
+ )
11
+ pipe.to("cuda" if torch.cuda.is_available() else "cpu")
12
+
13
+ def generate_video(prompt):
14
+ frames = pipe(prompt).frames
15
+
16
+ with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as temp_video:
17
+ pipe.export_to_video(frames, temp_video.name)
18
+ return temp_video.name
19
+
20
+ demo = gr.Interface(
21
+ fn=generate_video,
22
+ inputs=gr.Textbox(label="Prompt"),
23
+ outputs=gr.Video(label="Generated Animation"),
24
+ title="AnimateDiff Demo",
25
+ description="Generate animations from text prompts using AnimateDiff."
26
+ )
27
+
28
+ demo.launch()
29
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ torch
3
+ diffusers
4
+ transformers