Spaces:
Sleeping
Sleeping
Download encode_prompt.py from arnaupq2/taurus-animated: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/arnaupq2/taurus-animated/resolve/main/encode_prompt.py
- Command line
-
hf download hf://spaces/arnaupq2/taurus-animated/encode_prompt.py
-
curl -L -o encode_prompt.py https://huggingface.co/spaces/arnaupq2/taurus-animated/resolve/main/encode_prompt.py
1.1 kB
| """Encodes Taurus Animate's fixed prompt with UMT5-XXL, in a process of its own, and saves the embeddings. | |
| Run by app.py at start-up: `python encode_prompt.py <wan_dir> <out.pt>`. It lives apart from the Space's main | |
| process because that process is the one ZeroGPU forks its GPU worker from, and a big multi-threaded CPU run of | |
| torch there has left the worker unable to see the GPU ("No CUDA GPUs are available"). This file never imports | |
| `spaces`, so torch here is plain torch. | |
| """ | |
| import sys | |
| import torch | |
| from diffusers import WanImageToVideoPipeline | |
| import core | |
| def main(wan_dir, out): | |
| pipe = WanImageToVideoPipeline.from_pretrained(wan_dir, transformer=None, vae=None, torch_dtype=torch.bfloat16) | |
| with torch.inference_mode(): | |
| positive, negative = pipe.encode_prompt( | |
| prompt=core.POSITIVE, negative_prompt=core.NEGATIVE, do_classifier_free_guidance=True, | |
| num_videos_per_prompt=1, device=torch.device("cpu")) | |
| torch.save({"positive": positive.cpu(), "negative": negative.cpu()}, out) | |
| if __name__ == "__main__": | |
| main(sys.argv[1], sys.argv[2]) | |