File size: 1,723 Bytes
10e9b7d
eccf8e4
7fb1978
 
 
e80aab9
7fb1978
7d65c66
7fb1978
 
 
 
3c4371f
7fb1978
 
 
 
 
 
 
 
 
 
 
7d65c66
7fb1978
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7d65c66
7fb1978
 
 
 
 
 
3c4371f
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
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()