Spaces:
Sleeping
Sleeping
File size: 2,851 Bytes
12232f8 | 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | 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()
|