import requests from typing import List from agent import agent, AgentState API_BASE = "https://hf.space/embed/epfml/GAIA-leaderboard/api" # Replace with your Hugging Face username and space repo URL username = "XeroDN" code_link = "https://huggingface.co/spaces/XeroDN/langgraph_agent/tree/main" def ask_question(question: str) -> str: state: AgentState = { "question": question, "thoughts": [], "tool_results": [], "answer": None, } result = agent.invoke(state) return result["answer"] def fetch_questions(): API_BASE = "https://epfml-gaia-leaderboard.hf.space/api" resp = requests.get(f"{API_BASE}/questions") if resp.status_code != 200: raise RuntimeError(f"Failed to fetch questions: {resp.status_code} {resp.text}") try: return resp.json() except Exception as e: raise RuntimeError(f"Response is not valid JSON: {resp.text[:200]}") def submit_answers(answers: List[dict]) -> dict: payload = { "username": username, "code_link": code_link, "answers": answers, } resp = requests.post(f"{API_BASE}/submit", json=payload) resp.raise_for_status() return resp.json() def run_submission() -> dict: questions = fetch_questions() answers = [] for task in questions: task_id = task["task_id"] question = task["question"] print(f"Answering task {task_id}...") answer = ask_question(question) answers.append({"task_id": task_id, "submitted_answer": answer}) result = submit_answers(answers) return result