Spaces:
Running
Running
File size: 1,745 Bytes
0cb108c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | """Fast engine on a small fixed document (default: 4 AI-written subject paragraphs, ~460 words), all rounds allowed,
scored by the live detector ensemble. For comparing engine settings; speed on CPU is not meaningful.
python devtools/bench_fast.py [--paras 4] [--tag name] (FAST_* variables apply as on the Space)
Writes devtools/logs/bench_fast_<tag>.docx and prints the score after each round."""
import argparse
import os
import shutil
import sys
import time
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
sys.path.insert(0, str(Path(__file__).resolve().parent))
import env # noqa: E402
env.load()
os.environ.setdefault("LT_MODE", "off")
os.environ.setdefault("SKIP_MODEL_LOAD", "1")
sys.stdout.reconfigure(encoding="utf-8")
from docx import Document # noqa: E402
PICK = ["civil engineering", "medicine", "management", "law", "computer science", "economics"]
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--paras", type=int, default=4)
ap.add_argument("--tag", default="run")
a = ap.parse_args()
from samples_domains import DOMAINS
import fast as F
d = Document()
d.add_heading("Benchmark", 1)
for k in PICK[:a.paras]:
d.add_heading(k.title(), 2)
d.add_paragraph(DOMAINS[k])
src = ROOT / "devtools" / "logs" / "bench_fast_src.docx"
d.save(str(src))
t = time.time()
r = F.humanize_docx(str(src), budget=100000)
print(f"RESULT {a.tag}: {r['before']['pct']}% -> {r['after']['pct']}% | " + " | ".join(r["log"])
+ f" | {time.time() - t:.0f}s", flush=True)
shutil.copy(r["path"], ROOT / "devtools" / "logs" / f"bench_fast_{a.tag}.docx")
if __name__ == "__main__":
main()
|