Spaces:
Running on Zero
Running on Zero
File size: 1,481 Bytes
d435d94 6626621 d435d94 6626621 d435d94 | 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 | # -*- 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)
|