Download generate.py from Tokymin/text-to-video-ms-1.7b: direct link, hf CLI and curl.
- Browser
- Download file 866 Bytes
-
https://huggingface.co/Tokymin/text-to-video-ms-1.7b/resolve/ba21e8d17c9e07c8b473bd2f589ee3664cbc9dd6/generate.py
- Command line
-
hf download hf://Tokymin/text-to-video-ms-1.7b@ba21e8d17c9e07c8b473bd2f589ee3664cbc9dd6/generate.py
-
curl -L -o generate.py https://huggingface.co/Tokymin/text-to-video-ms-1.7b/resolve/ba21e8d17c9e07c8b473bd2f589ee3664cbc9dd6/generate.py
866 Bytes
| import numpy as np | |
| import torch | |
| from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler | |
| from diffusers.utils import export_to_video | |
| from datetime import datetime | |
| pipe = DiffusionPipeline.from_pretrained(r"J:\Projects\Video-Projects\text-to-video-ms-1.7b", torch_dtype=torch.float16, variant="fp16") | |
| pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) | |
| pipe.enable_model_cpu_offload() | |
| timestamp_str = datetime.now().strftime("%Y-%m-%d-%H%M%S") | |
| output_video_path=f"J:/Projects/Video-Projects/text-to-video-ms-1.7b/output_videos/{timestamp_str}.mp4" | |
| prompt = "Spiderman is surfing" | |
| video_frames = pipe(prompt, num_inference_steps=25).frames | |
| video_frames_np = [np.array(frame) for frame in video_frames] | |
| video_frames_np = np.concatenate(video_frames_np, axis=0) | |
| video_path = export_to_video(video_frames_np,output_video_path) | |