File size: 2,651 Bytes
23caa29
 
 
 
 
a92112f
23caa29
 
a92112f
a884a74
23caa29
 
 
 
 
 
 
3c4371f
a884a74
23caa29
 
 
a884a74
23caa29
eccf8e4
23caa29
7d65c66
23caa29
a884a74
23caa29
 
 
 
 
a884a74
23caa29
 
 
 
a884a74
23caa29
 
 
 
 
a92112f
23caa29
 
e80aab9
 
23caa29
 
 
a884a74
23caa29
 
 
 
 
 
 
7e4a06b
23caa29
 
 
 
 
 
e80aab9
23caa29
e80aab9
23caa29
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
# app.py  –  Gradio UI + Orchestrierung
# =====================================
import os
import gradio as gr
import pandas as pd

from agent import GaiaAgent              # deine LangChain/LangGraph-Implementierung
import logic                             # Netzwerk- / Loader- / Submit-Utilities


# ---------------------------------------------------------------------
# Callback für den Gradio-Button
# ---------------------------------------------------------------------
def run_and_submit_all(profile: gr.OAuthProfile | None):
    # 0) Login prüfen
    if profile is None:
        return "⚠️  Please log in with the Hugging Face button.", None

    username = profile.username
    space_id = os.getenv("SPACE_ID", "your-space-id")       # Fallback für lokales Testen
    agent_code_url = f"https://huggingface.co/spaces/{space_id}/tree/main"
    print(f"👤  User: {username} | Repo: {agent_code_url}")

    # 1) Agent instanziieren
    try:
        gaia_agent = GaiaAgent()
    except Exception as e:
        return f"❌ Error initialising GaiaAgent: {e}", None

    # 2) Fragen (und evtl. Dateien) laden
    try:
        questions = logic.fetch_all_questions()
    except Exception as e:
        return f"❌ Could not fetch questions: {e}", None

    # 3) Agent auf alle Fragen loslassen
    results_log, answers_payload = logic.run_agent(gaia_agent, questions)
    if not answers_payload:
        return "⚠️  Agent produced no answers.", pd.DataFrame(results_log)

    # 4) Einsenden & Score abrufen
    submission = {
        "username": username.strip(),
        "agent_code": agent_code_url,
        "answers": answers_payload,
    }
    status_msg, results_df = logic.submit_answers(submission, results_log)
    return status_msg, results_df


# ---------------------------------------------------------------------
# Gradio-Interface
# ---------------------------------------------------------------------
with gr.Blocks() as demo:
    gr.Markdown("# GAIA Level-1 Agent – Evaluation Runner")
    gr.Markdown(
        "1. **Clone** this Space and implement your logic in `agent.py`.\n"
        "2. **Log in** with your HF account.\n"
        "3. Click **Run** to fetch questions, run the agent, and submit answers."
    )

    gr.LoginButton()
    run_btn = gr.Button("Run Evaluation & Submit All Answers")

    status_box = gr.Textbox(label="Status / Score", lines=4, interactive=False)
    results_df = gr.DataFrame(label="Questions & Answers", wrap=True)

    run_btn.click(run_and_submit_all, outputs=[status_box, results_df])

# Standard-Start – auch lokal lauffähig
if __name__ == "__main__":
    demo.launch()