Spaces:
Sleeping
Sleeping
File size: 1,895 Bytes
281882c | 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 50 51 52 53 54 55 56 57 58 59 | """Try the agent outside the Space (laptop or Colab), without submitting anything.
python run_local.py --list # show the questions and their task ids
python run_local.py --task 8e867cd7 # answer one question (task id prefix is enough)
python run_local.py --first 3 # answer the first 3 questions
python run_local.py --ask "What is 2+2?" # any ad-hoc question
Answers for real tasks are written to the same answers_cache.json the Space uses.
"""
import argparse
import gaia_api as api
def main():
p = argparse.ArgumentParser()
p.add_argument("--list", action="store_true")
p.add_argument("--task", help="task_id or a unique prefix of it")
p.add_argument("--first", type=int)
p.add_argument("--ask")
args = p.parse_args()
if args.ask:
from agent import GaiaAgent
print("ANSWER:", GaiaAgent()(args.ask))
return
questions = api.fetch_questions()
if args.list:
for q in questions:
f = f" [file: {q['file_name']}]" if q.get("file_name") else ""
print(f"{q['task_id'][:8]} {q['question'][:90]!r}{f}")
return
if args.task:
chosen = [q for q in questions if q["task_id"].startswith(args.task)]
else:
chosen = questions[: args.first or 1]
if not chosen:
raise SystemExit("No matching task.")
from agent import GaiaAgent
agent = GaiaAgent()
cache = api.load_cache()
for q in chosen:
path = api.download_task_file(q["task_id"], q.get("file_name", ""))
answer = agent(q["question"], path)
print(f"\n=== {q['task_id'][:8]} -> {answer!r}\n")
cache[q["task_id"]] = {"question": q["question"], "file_name": q.get("file_name", ""),
"submitted_answer": answer}
api.save_cache(cache)
if __name__ == "__main__":
main()
|