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