Spaces:
Runtime error
Runtime error
# submission.py | |
import requests | |
import gradio as gr | |
from agent import run_agent_on_question | |
from utils import format_answer | |
API_BASE_URL = "https://agents-course-unit4-scoring.hf.space" | |
def fetch_questions(): | |
""" | |
Retrieve all evaluation questions from the API. | |
""" | |
response = requests.get(f"{API_BASE_URL}/questions") | |
return response.json() if response.status_code == 200 else [] | |
def submit_answers_to_leaderboard(username, agent_code_url): | |
""" | |
Runs the agent on all evaluation questions and submits answers. | |
""" | |
questions = fetch_questions() | |
print(f"Fetched {len(questions)} questions.") | |
answers = [] | |
for q in questions: | |
print(f"\nπ Running agent on task: {q['task_id']}") | |
response = run_agent_on_question(q) # β Pass full task dictionary | |
formatted_answer = format_answer(response) | |
print(f"Answer: {formatted_answer}") | |
answers.append({ | |
"task_id": q["task_id"], | |
"submitted_answer": formatted_answer | |
}) | |
# Prepare final submission payload | |
submission = { | |
"username": username, | |
"agent_code": agent_code_url, | |
"answers": answers | |
} | |
res = requests.post(f"{API_BASE_URL}/submit", json=submission) | |
if res.status_code == 200: | |
print("\nβ Submission Complete!") | |
print("Result:", res.json()) | |
return res.json() | |
else: | |
print("\nβ Submission Failed!") | |
print("Status Code:", res.status_code) | |
print("Response:", res.text) | |
return None | |
# Optional Gradio UI for easier submission | |
with gr.Blocks() as demo: | |
gr.Markdown("## π€ GAIA Agent Submission") | |
with gr.Row(): | |
username = gr.Textbox(label="Your Hugging Face Username") | |
agent_code_url = gr.Textbox(label="Public URL to Your Hugging Face Space Code") | |
submit_btn = gr.Button("Run Evaluation & Submit All Answers") | |
output = gr.Textbox(label="Submission Result") | |
submit_btn.click( | |
fn=submit_answers_to_leaderboard, | |
inputs=[username, agent_code_url], | |
outputs=[output] | |
) | |
if __name__ == "__main__": | |
demo.launch() | |