Download utils.py from aexyb/Gravo: direct link, hf CLI and curl.
- Browser
- Download file 788 Bytes
-
https://huggingface.co/spaces/aexyb/Gravo/resolve/main/utils.py
- Command line
-
hf download hf://spaces/aexyb/Gravo/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/aexyb/Gravo/resolve/main/utils.py
788 Bytes
| import os | |
| import time | |
| from pathlib import Path | |
| OUTPUT_DIR = Path("outputs") | |
| OUTPUT_DIR.mkdir(exist_ok=True) | |
| def cleanup_outputs(max_age_hours=2): | |
| """ | |
| Delete old generated videos. | |
| """ | |
| now = time.time() | |
| for file in OUTPUT_DIR.glob("*.mp4"): | |
| age = now - file.stat().st_mtime | |
| if age > max_age_hours * 3600: | |
| try: | |
| file.unlink() | |
| except Exception: | |
| pass | |
| def random_seed(): | |
| import random | |
| return random.randint(0, 2**31 - 1) | |
| def validate_frames(frames): | |
| # Wan requires 4k+1 | |
| if frames < 5: | |
| frames = 5 | |
| remainder = (frames - 1) % 4 | |
| if remainder != 0: | |
| frames += 4 - remainder | |
| return frames | |
| def ensure_output_dir(): | |
| OUTPUT_DIR.mkdir(exist_ok=True) |