Datasets:
Download evaluation/local_inference.py from OpenMOSS-Team/LongLongTextBench: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/datasets/OpenMOSS-Team/LongLongTextBench/resolve/main/evaluation/local_inference.py
- Command line
-
hf download hf://datasets/OpenMOSS-Team/LongLongTextBench/evaluation/local_inference.py
-
curl -L -o local_inference.py https://huggingface.co/datasets/OpenMOSS-Team/LongLongTextBench/resolve/main/evaluation/local_inference.py
1.69 kB
| #!/usr/bin/env python3 | |
| """Adapt an existing inference function returning PIL.Image to the exported jobs.""" | |
| import argparse | |
| import importlib | |
| import json | |
| from pathlib import Path | |
| import sys | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--adapter", required=True, help="importable module:function returning PIL.Image") | |
| parser.add_argument("--jobs", required=True) | |
| parser.add_argument("--images", required=True) | |
| parser.add_argument("--num-shards", type=int, default=1) | |
| parser.add_argument("--shard-index", type=int, default=0) | |
| args = parser.parse_args() | |
| if args.num_shards < 1 or not 0 <= args.shard_index < args.num_shards: | |
| parser.error("require 0 <= shard-index < num-shards") | |
| module, name = args.adapter.split(":", 1) | |
| generate = getattr(importlib.import_module(module), name) | |
| root = Path(args.images).resolve() | |
| jobs = [json.loads(line) for line in Path(args.jobs).read_text(encoding="utf-8").splitlines() if line.strip()] | |
| for index, job in enumerate(jobs): | |
| if index % args.num_shards != args.shard_index: | |
| continue | |
| target = (root / job["output_relpath"]).resolve() | |
| if not target.is_relative_to(root): | |
| raise ValueError(f"Output path escapes image root: {target}") | |
| target.parent.mkdir(parents=True, exist_ok=True) | |
| image = generate(prompt=job["prompt"], seed=job["seed"], width=job["width"], height=job["height"]) | |
| image.save(target, format="PNG") | |
| print(f"[{index + 1}/{len(jobs)}] {target}", flush=True) | |
| if __name__ == "__main__": | |
| main() | |