File size: 2,154 Bytes
7fb1978 |
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 |
# 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()
|