Datasets:
Download scripts/make_gifs.py from Nabidnur/RoboRACE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/datasets/Nabidnur/RoboRACE-Bench/resolve/main/scripts/make_gifs.py
- Command line
-
hf download hf://datasets/Nabidnur/RoboRACE-Bench/scripts/make_gifs.py
-
curl -L -o make_gifs.py https://huggingface.co/datasets/Nabidnur/RoboRACE-Bench/resolve/main/scripts/make_gifs.py
1.83 kB
| #!/usr/bin/env python3 | |
| """README GIFs from the MP4 masters, sized for GitHub's ~960 px content column. | |
| GitHub cannot play committed MP4s inline in a README, so each video gets a crisp GIF | |
| (flat-colour palette, rectangle diff mode keeps files small) and the README links the MP4. | |
| robot_rollouts.gif highlight: episode 1 (rollout + honest verdict + liar-majority verdict) | |
| swarm_rendezvous.gif full clip | |
| planbench_modulo.gif full clip (shown in a half-width table cell) | |
| """ | |
| import subprocess | |
| from pathlib import Path | |
| V = Path("media/videos") | |
| SPEC = { # name: (start s, duration s or None, width px, fps) | |
| "robot_rollouts": (4.0, 12.3, 960, 10), | |
| "swarm_rendezvous": (0.0, None, 960, 12), | |
| "planbench_modulo": (0.0, None, 720, 10), | |
| "maze_swarm": (4.0, None, 960, 10), | |
| "maze_false_walls": (4.0, None, 960, 10), | |
| "panda_rollouts": (4.0, 13.5, 960, 10), | |
| } | |
| def gif(name, start, dur, width, fps): | |
| src, out, pal = V / f"{name}.mp4", V / f"{name}.gif", V / f"{name}.pal.png" | |
| cut = ["-ss", str(start)] + (["-t", str(dur)] if dur else []) | |
| vf = f"fps={fps},scale={width}:-1:flags=lanczos" | |
| subprocess.run(["ffmpeg", "-y", "-loglevel", "error", *cut, "-i", str(src), "-vf", | |
| vf + ",palettegen=max_colors=160:stats_mode=diff", str(pal)], check=True) | |
| subprocess.run(["ffmpeg", "-y", "-loglevel", "error", *cut, "-i", str(src), "-i", str(pal), "-lavfi", | |
| vf + "[x];[x][1:v]paletteuse=dither=bayer:bayer_scale=4:diff_mode=rectangle", str(out)], check=True) | |
| pal.unlink() | |
| return out | |
| if __name__ == "__main__": | |
| import sys | |
| for n, s in SPEC.items(): | |
| if (sys.argv[1:] and n not in sys.argv[1:]) or not (V / f"{n}.mp4").exists(): | |
| continue | |
| o = gif(n, *s) | |
| print(f"{o} {o.stat().st_size / 1e6:.2f} MB") | |