Download anime-2d-reference-kit/engine/render_request.py from DenSnoychik/ArenaAISpace: direct link, hf CLI and curl.
- Browser
- Download file 3.38 kB
-
https://huggingface.co/datasets/DenSnoychik/ArenaAISpace/resolve/main/anime-2d-reference-kit/engine/render_request.py
- Command line
-
hf download hf://datasets/DenSnoychik/ArenaAISpace/anime-2d-reference-kit/engine/render_request.py
-
curl -L -o render_request.py https://huggingface.co/datasets/DenSnoychik/ArenaAISpace/resolve/main/anime-2d-reference-kit/engine/render_request.py
3.38 kB
| """Validate a render request and expose its settings to GitHub Actions.""" | |
| import json | |
| import math | |
| import os | |
| from pathlib import Path | |
| import re | |
| import subprocess | |
| from final_review import validate_final_review | |
| def read_request(): | |
| if os.environ["EVENT"] == "workflow_dispatch": | |
| return json.loads(os.environ["INPUTS"]) | |
| added = subprocess.check_output( | |
| ["git", "diff-tree", "--root", "--no-commit-id", "--diff-filter=A", "-r", | |
| "--name-only", "HEAD", "--", "render-requests/"], | |
| text=True, | |
| ).splitlines() | |
| requests = [p for p in added if re.fullmatch(r"render-requests/[a-z0-9-]+\.json", p)] | |
| if len(requests) != 1: | |
| raise SystemExit("Add exactly one new render-requests/<id>.json per launch commit.") | |
| return json.loads(Path(requests[0]).read_text(encoding="utf-8")) | |
| def main(): | |
| request = read_request() | |
| root = Path("scenes").resolve(strict=True) | |
| raw_scene = request["scene"] | |
| if not re.fullmatch(r"scenes/(?:[a-zA-Z0-9_-]+/)*[a-zA-Z0-9_-]+\.py", raw_scene): | |
| raise SystemExit("Choose a Python file under scenes/.") | |
| scene = Path(raw_scene).resolve(strict=True) | |
| if not scene.is_relative_to(root) or not scene.is_file(): | |
| raise SystemExit("Scene must be a file under scenes/.") | |
| duration = float(request.get("duration", 3)) | |
| fps_value = str(request.get("fps", 30)) | |
| video_format = request.get("format", "horizontal") | |
| voice = request.get("voice", False) | |
| if not math.isfinite(duration) or not 0 < duration <= 300: | |
| raise SystemExit("Duration must be greater than zero and at most 300 seconds.") | |
| if not re.fullmatch(r"[0-9]{1,3}", fps_value) or not 1 <= int(fps_value) <= 120: | |
| raise SystemExit("FPS must be between 1 and 120.") | |
| if video_format not in ("horizontal", "vertical", "square") or not isinstance(voice, bool): | |
| raise SystemExit("Invalid video format or voice option.") | |
| stage = request.get("stage", "standard") | |
| if stage not in ("standard", "assets", "draft", "final"): | |
| raise SystemExit("Invalid render stage.") | |
| checks = request.get("checkpoints", []) | |
| if not isinstance(checks, list) or len(checks) > 20: | |
| raise SystemExit("Supply at most 20 checkpoints.") | |
| if stage in ("draft", "final") and not checks: | |
| raise SystemExit("Draft and final requests require checkpoints.") | |
| for check in checks: | |
| if (not isinstance(check, dict) or set(check) != {"time", "label"} | |
| or type(check["time"]) not in (int, float) or not 0 <= check["time"] < duration | |
| or not isinstance(check["label"], str) or not 0 < len(check["label"].strip()) <= 100): | |
| raise SystemExit("Checkpoint requires an in-range time and a short label.") | |
| motion = request.get("motion") | |
| if motion is not None: | |
| from motion_review import validate_motion | |
| validate_motion(motion, duration) | |
| print("motion=" + json.dumps(motion or [], ensure_ascii=True, separators=(",", ":"))) | |
| if stage == "final": | |
| validate_final_review(request) | |
| print(f"stage={stage}") | |
| print("checkpoints=" + json.dumps(checks, ensure_ascii=True, separators=(",", ":"))) | |
| print(f"scene={raw_scene}") | |
| print(f"duration={duration}") | |
| print(f"fps={int(fps_value)}") | |
| print(f"format={video_format}") | |
| print(f"voice={str(voice).lower()}") | |
| if __name__ == "__main__": | |
| main() | |