Create vid_gen.py
Browse files- vid_gen.py +16 -0
vid_gen.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@torch.no_grad()
|
2 |
+
def generate_video(text, steps=1000):
|
3 |
+
model.eval()
|
4 |
+
text_enc = tokenizer(text, return_tensors="pt").input_ids.to(device)
|
5 |
+
x = torch.randn(1, 3, FRAMES, H, W).to(device)
|
6 |
+
|
7 |
+
for t in range(steps, 0, -1):
|
8 |
+
t_tensor = torch.tensor([[t/steps]]).to(device)
|
9 |
+
pred_noise = model(x, t_tensor, text_enc)
|
10 |
+
alpha_t = (1 - t_tensor).view(-1, 1, 1, 1, 1)
|
11 |
+
x = (x - (1 - alpha_t)/torch.sqrt(alpha_t) * pred_noise) / torch.sqrt(alpha_t)
|
12 |
+
|
13 |
+
return x.clamp(-1, 1)
|
14 |
+
|
15 |
+
|
16 |
+
video = generate_video("YOUR_PROMPT_HERE")
|