Spaces:
Running on Zero
Running on Zero
Download rtcwm/data/qc/__main__.py from hugging-apps/streaming-code-world-model: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/spaces/hugging-apps/streaming-code-world-model/resolve/main/rtcwm/data/qc/__main__.py
- Command line
-
hf download hf://spaces/hugging-apps/streaming-code-world-model/rtcwm/data/qc/__main__.py
-
curl -L -o __main__.py https://huggingface.co/spaces/hugging-apps/streaming-code-world-model/resolve/main/rtcwm/data/qc/__main__.py
1.5 kB
| """python -m rtcwm.data.qc {clipping,audit,coarse} [--workers N] CLIP_DIR ... | lists""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from multiprocessing import Pool | |
| from pathlib import Path | |
| from ... import paths | |
| from . import audit, clipping, coarse, lists | |
| SCANS = dict(clipping=clipping.scan, audit=audit.audit, coarse=coarse.scan) | |
| def _run(job): | |
| check, clip = job | |
| try: | |
| rep = SCANS[check](Path(clip)) | |
| except Exception as e: # report and keep going | |
| return f"{Path(clip).name} {check} ERROR {e!r}" | |
| out = paths.QC / check | |
| out.mkdir(parents=True, exist_ok=True) | |
| (out / f"{Path(clip).name}.json").write_text(json.dumps(rep)) | |
| return f"{Path(clip).name} {check} bad_windows={rep.get('bad_windows', '-')}" | |
| def main(): | |
| ap = argparse.ArgumentParser(description=__doc__) | |
| ap.add_argument("check", choices=[*SCANS, "lists"]) | |
| ap.add_argument("clips", nargs="*") | |
| ap.add_argument("--workers", type=int, default=1) | |
| a = ap.parse_intermixed_args() # options may sit between the check name and the clips | |
| if a.check == "lists": | |
| print(lists.build()) | |
| return | |
| jobs = [(a.check, c) for c in a.clips] | |
| if a.workers > 1: | |
| with Pool(a.workers) as p: | |
| for line in p.imap_unordered(_run, jobs): | |
| print(line, flush=True) | |
| else: | |
| for j in jobs: | |
| print(_run(j), flush=True) | |
| if __name__ == "__main__": | |
| main() | |