import requests import gradio as gr import os # ==================================================== # CONFIGURATION # ==================================================== BASE_URL = "https://huggingface.co/api/gaia" # Replace with your actual GAIA API base URL USERNAME = os.getenv("HF_USERNAME") or "your_hf_username_here" AGENT_CODE = "https://huggingface.co/spaces/your_username/gaia-agent/tree/main" # ==================================================== # API FUNCTIONS # ==================================================== def get_questions(): """Retrieve all evaluation questions""" resp = requests.get(f"{BASE_URL}/questions") resp.raise_for_status() return resp.json() def get_random_question(): """Retrieve a random single question""" resp = requests.get(f"{BASE_URL}/random-question") resp.raise_for_status() return resp.json() def submit_answers(answers): """Submit all answers to the leaderboard""" payload = { "username": USERNAME, "agent_code": AGENT_CODE, "answers": answers } resp = requests.post(f"{BASE_URL}/submit", json=payload) resp.raise_for_status() return resp.json() # ==================================================== # AGENT LOGIC # ==================================================== def answer_question(question): """Simple rule-based answering agent (replace with LLM logic later)""" q_text = question["question_text"].lower() if "capital" in q_text: return "Paris" elif "language" in q_text: return "English" elif "2+2" in q_text or "two plus two" in q_text: return "4" else: return "Unknown" def run_agent(): """Fetch all questions and generate answers""" questions = get_questions() answers = [] for q in questions: ans = answer_question(q) answers.append({ "task_id": q["task_id"], "submitted_answer": ans }) return answers # ==================================================== # GRADIO UI # ==================================================== def main_ui(): def on_run(): answers = run_agent() result = submit_answers(answers) return f"✅ Submission complete!\n\nResult:\n{result}" iface = gr.Interface( fn=on_run, inputs=[], outputs="text", title="🤗 GAIA Agent Submission Tool", description=( "This tool fetches GAIA questions, generates simple answers, and submits them " "to the Hugging Face leaderboard.\n\n" "👉 Replace the `answer_question()` logic with your own model or reasoning approach." ) ) iface.launch() if __name__ == "__main__": main_ui()