Spaces:
Running on Zero

Bigbearbo's picture
Refusal line: omit sentence number when the gap has none
6626621 verified
Raw History Blame Contribute Delete
1.48 kB
# -*- coding: utf-8 -*-
"""Acceptance: call the running Space with gradio_client: 2 random questions + 1 typed question.
python -B tools/accept.py out.json
"""
import json
import sys
import time
from gradio_client import Client
from huggingface_hub import get_token
c = Client("Bigbearbo/word-problem-reader", hf_token=get_token(), verbose=False)
TYPED = ("Maria has 3 boxes of pencils with 12 pencils in each box. She gives 9 pencils to her friend. "
"How many pencils does Maria have left?")
runs = []
EXTRA = sys.argv[2:] # optional extra typed questions (e.g. one from the data that Qwen answered offline)
for kind in ["隨機抽題型 Random type", "隨機抽題型 Random type", None] + EXTRA:
if kind and kind.startswith("隨機"):
q, info, _ = c.predict(kind, api_name="/random")
else:
q, info = (kind or TYPED), "typed"
t0 = time.time()
ans, trace = c.predict(q, api_name="/solve")
sec = round(time.time() - t0, 1)
lines = []
if "### 3." in trace:
part = trace.split("### 3.")[1].split("```")[1]
lines = [x for x in part.strip().split("\n") if x.strip()]
runs.append({"抽題": info, "題目": q, "資訊句": lines, "回答框": ans, "耗秒_含網路": sec, "過程": trace})
print(json.dumps({k: v for k, v in runs[-1].items() if k != "過程"}, ensure_ascii=False, indent=1), flush=True)
json.dump(runs, open(sys.argv[1], "w", encoding="utf-8"), ensure_ascii=False, indent=1)