Spaces:
Runtime error
Runtime error
| # 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() |