Spaces:
Running on Zero
Running on Zero
Download tools/test_mixer.py from Bigbearbo/word-problem-reader: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/Bigbearbo/word-problem-reader/resolve/main/tools/test_mixer.py
- Command line
-
hf download hf://spaces/Bigbearbo/word-problem-reader/tools/test_mixer.py
-
curl -L -o test_mixer.py https://huggingface.co/spaces/Bigbearbo/word-problem-reader/resolve/main/tools/test_mixer.py
1.21 kB
| # -*- coding: utf-8 -*- | |
| """The Space's mixer.py (hs/ copy + pickled reader) must give the same mixed replies as tools/mix_replies.py on the | |
| team folder. Also lists any file opened outside the Space folder (should be none besides Python / spaCy). | |
| python -B tools/test_mixer.py fixture.json mixed_ref.json""" | |
| import json | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| OPENED = set() | |
| def hook(ev, args): | |
| if ev == "open" and isinstance(args[0], str): | |
| OPENED.add(args[0]) | |
| sys.addaudithook(hook) | |
| sys.path.insert(0, str(ROOT)) | |
| import pipeline # noqa: E402 | |
| import mixer # noqa: E402 | |
| pipeline.init() | |
| fx = json.load(open(sys.argv[1], encoding="utf-8")) | |
| ref = {r["id"]: r for r in json.load(open(sys.argv[2], encoding="utf-8"))} | |
| diff, nrep = [], 0 | |
| for t in fx: | |
| text, per = mixer.mix(t["q"], t["reply"]) | |
| nrep += sum(p["來源"] == "程式" for p in per) | |
| if text != ref[t["id"]]["mixed_reply"]: | |
| diff.append(t["id"]) | |
| outside = sorted(p for p in OPENED if p.startswith(("H:", "h:")) and not p.startswith(str(ROOT))) | |
| print("題", len(fx), "程式取代句", nrep, "與團隊版不同", diff) | |
| print("開到 Space 資料夾外的檔:", outside[:20]) | |