|
import gradio as gr |
|
import requests |
|
import os |
|
from agent import run_agent_on_question |
|
from utils import get_hf_username, get_code_link |
|
|
|
API_BASE = "https://agents-course-unit4-scoring.hf.space" |
|
|
|
def fetch_questions(): |
|
response = requests.get(f"{API_BASE}/questions") |
|
if response.status_code == 200: |
|
return response.json() |
|
else: |
|
return [] |
|
|
|
def submit_answers(answers, username, code_link): |
|
payload = { |
|
"username": username, |
|
"agent_code": code_link, |
|
"answers": answers |
|
} |
|
response = requests.post(f"{API_BASE}/submit", json=payload) |
|
if response.status_code == 200: |
|
return response.json() |
|
else: |
|
return {"message": "Submission failed.", "score": 0} |
|
|
|
def run_and_submit(): |
|
print("Fetching questions...") |
|
questions = fetch_questions() |
|
print(f"Fetched {len(questions)} questions") |
|
|
|
answers = [] |
|
for q in questions: |
|
print(f"Running agent on task {q['task_id']}") |
|
answer = run_agent_on_question(q) |
|
answers.append({ |
|
"task_id": q["task_id"], |
|
"submitted_answer": answer |
|
}) |
|
|
|
username = get_hf_username() |
|
code_link = get_code_link() |
|
print(f"Submitting answers as {username} with code link {code_link}") |
|
|
|
result = submit_answers(answers, username, code_link) |
|
print(result) |
|
return f"Score: {result.get('score', 0)}\nMessage: {result.get('message', 'No message')}" |
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("## GAIA Agent Evaluation Space") |
|
with gr.Row(): |
|
submit_btn = gr.Button("Run Evaluation & Submit All Answers") |
|
output = gr.Textbox(label="Submission Result") |
|
submit_btn.click(fn=run_and_submit, outputs=output) |
|
|
|
demo.launch() |
|
|