Download gate.py from IntelligenceLab/WetLab-Data-Gate: direct link, hf CLI and curl.
- Browser
- Download file 3.93 kB
-
https://huggingface.co/spaces/IntelligenceLab/WetLab-Data-Gate/resolve/main/gate.py
- Command line
-
hf download hf://spaces/IntelligenceLab/WetLab-Data-Gate/gate.py
-
curl -L -o gate.py https://huggingface.co/spaces/IntelligenceLab/WetLab-Data-Gate/resolve/main/gate.py
3.93 kB
| #!/usr/bin/env python3 | |
| """Wet-lab data gate, command line. | |
| python3 -I gate.py cases/<submission>.json --out runs/<name> | |
| python3 -I gate.py cases/<submission>.json --out runs/<name> --lang en # English report | |
| python3 -I gate.py cases/<submission>.json --out runs/<name> --lang en --provider-feedback # plus a letter for the provider | |
| Reads the submission described by the JSON file, runs every implemented clause of clauses.json, writes report.md and | |
| result.json into the output folder, and compares the outcome with the 'expected' block of the submission file if there is one. | |
| Submitted data is only read as data. Nothing in it is imported or executed.""" | |
| import sys, os, json, argparse | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| sys.path.insert(0, HERE) | |
| from wdg import core, report, i18n # noqa: E402 | |
| from wdg.source import classify | |
| from wdg.checks import source_finding | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("submission") | |
| ap.add_argument("--out", required=True) | |
| ap.add_argument("--lang", choices=["zh", "en"], default="zh", | |
| help="language of the report and of the result file. zh (default) writes report.md and result.json; en writes report_en.md and result_en.json") | |
| ap.add_argument("--provider-feedback", action="store_true", | |
| help="also write provider_feedback.md (provider_feedback_en.md for English): what was received, what was verified, what is missing " | |
| "and what to send, with no clause numbers, lines, rungs or dry runs in it") | |
| a = ap.parse_args() | |
| cen = json.load(open(os.path.join(HERE, "clauses_en.json"), encoding="utf-8"))["clauses"] if a.lang == "en" else None | |
| i18n.set_lang(a.lang, cen) | |
| cfg = i18n.localise(json.load(open(a.submission, encoding="utf-8"))) | |
| clauses = json.load(open(os.path.join(HERE, "clauses.json"), encoding="utf-8"))["clauses"] | |
| os.makedirs(a.out, exist_ok=True) | |
| if not cfg.get("root") and not cfg.get("experiments") and any(cfg.get(k) for k in ("source_url", "source_type", "sources")): | |
| access = classify(cfg) | |
| report.build_source_only(cfg, source_finding(access), a.out) | |
| print("source:", access["label"], "|", access["basis_label"]) | |
| print("report:", os.path.join(a.out, report.out_name("report", ".md"))) | |
| return 0 | |
| if not cfg.get("root") or not os.path.isdir(cfg["root"]): | |
| ap.error(tr("请提供有效的数据文件夹 root;只有来源线索时填写 source_url 或 sources,并省略 root 和 experiments")) | |
| ctx = core.run(cfg, clauses, a.out) | |
| md, res = report.build(ctx, clauses, a.out) | |
| print("submission:", cfg["name"], "| files:", res["files"], "| seconds:", res["seconds"]) | |
| print("source:", ctx.source_access["label"], "|", ctx.source_access["basis_label"]) | |
| for eid, s in res["summary"].items(): | |
| print(" %-28s rung %s | fail: %s | warn: %s" % (eid, s["rung"], ",".join(s["fail"]) or "-", ",".join(s["warn"]) or "-")) | |
| err = [f for f in res["findings"] if f["status"] == "ERROR"] | |
| for f in err: | |
| print(" GATE ERROR in", f["clause"], f["message"], f["evidence"].get("trace")) | |
| exp = cfg.get("expected") | |
| ok = True | |
| if exp: | |
| for eid, want in exp.items(): | |
| got = res["summary"].get(eid, {}) | |
| for k in ("fail", "rung"): | |
| if k in want and want[k] != got.get(k): | |
| ok = False | |
| print(" NOT AS EXPECTED: %s %s: expected %s, got %s" % (eid, k, want[k], got.get(k))) | |
| print("expected outcome:", "matches" if ok else "DIFFERS") | |
| print("report:", os.path.join(a.out, report.out_name("report", ".md"))) | |
| if a.provider_feedback: | |
| from wdg import feedback | |
| print("provider feedback:", feedback.build(ctx, a.out)) | |
| return 0 if (ok and not err) else 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |