Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
| 1 |
---
|
| 2 |
license: other
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: other
|
| 3 |
+
---pip install transformers torch torchvision
|
| 4 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 5 |
+
import torch
|
| 6 |
+
import torchvision.transforms as transforms
|
| 7 |
+
from torchvision.io import write_video
|
| 8 |
+
model = T5ForConditionalGeneration.from_pretrained("t5-base")
|
| 9 |
+
tokenizer = T5Tokenizer.from_pretrained("t5-base")
|
| 10 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 11 |
+
model = model.to(device)
|
| 12 |
+
def generate_video_from_text(text):
|
| 13 |
+
input_ids = tokenizer.encode(text, return_tensors="pt").to(device)
|
| 14 |
+
output = model.generate(input_ids)
|
| 15 |
+
video_frames = output[0].cpu().numpy()
|
| 16 |
+
|
| 17 |
+
# Convert frames to a video
|
| 18 |
+
frames = [torch.tensor(frame, dtype=torch.uint8).permute(1, 2, 0) for frame in video_frames]
|
| 19 |
+
video = torch.stack(frames)
|
| 20 |
+
video = video.permute(0, 3, 1, 2) # (T, C, H, W)
|
| 21 |
+
|
| 22 |
+
return video
|
| 23 |
+
|