Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,81 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
-
import requests
|
| 4 |
-
import pandas as pd
|
| 5 |
-
from agent import BasicAgent
|
| 6 |
-
|
| 7 |
-
# --- Constants ---
|
| 8 |
-
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 12 |
-
"""
|
| 13 |
-
Fetches GAIA questions, queries the smolagents-based BasicAgent, and submits answers.
|
| 14 |
-
"""
|
| 15 |
-
if not profile:
|
| 16 |
-
return "Please log in with Hugging Face", None
|
| 17 |
-
|
| 18 |
-
username = profile.username
|
| 19 |
-
agent = BasicAgent()
|
| 20 |
-
|
| 21 |
-
# 1) Fetch questions
|
| 22 |
-
questions_url = f"{DEFAULT_API_URL}/questions"
|
| 23 |
-
try:
|
| 24 |
-
resp = requests.get(questions_url, timeout=15)
|
| 25 |
-
resp.raise_for_status()
|
| 26 |
-
questions = resp.json()
|
| 27 |
-
except Exception as e:
|
| 28 |
-
return f"Error fetching questions: {e}", None
|
| 29 |
-
|
| 30 |
-
# 2) Run agent on each question
|
| 31 |
-
answers = []
|
| 32 |
-
log = []
|
| 33 |
-
for item in questions:
|
| 34 |
-
task_id = item.get("task_id")
|
| 35 |
-
question = item.get("question")
|
| 36 |
-
if not task_id or question is None:
|
| 37 |
-
continue
|
| 38 |
-
|
| 39 |
-
answer = agent(question)
|
| 40 |
-
answers.append({"task_id": task_id, "submitted_answer": answer})
|
| 41 |
-
log.append({"Task ID": task_id, "Question": question, "Answer": answer})
|
| 42 |
-
|
| 43 |
-
if not answers:
|
| 44 |
-
return "Agent did not produce any answers to submit.", pd.DataFrame(log)
|
| 45 |
-
|
| 46 |
-
# 3) Submit answers
|
| 47 |
-
payload = {
|
| 48 |
-
"username": username,
|
| 49 |
-
"agent_code": f"https://huggingface.co/spaces/{os.getenv('SPACE_ID')}/tree/main",
|
| 50 |
-
"answers": answers,
|
| 51 |
-
}
|
| 52 |
-
submit_url = f"{DEFAULT_API_URL}/submit"
|
| 53 |
-
try:
|
| 54 |
-
resp_s = requests.post(submit_url, json=payload, timeout=60)
|
| 55 |
-
resp_s.raise_for_status()
|
| 56 |
-
data = resp_s.json()
|
| 57 |
-
status = (
|
| 58 |
-
f"Score: {data.get('score', 'N/A')}% "
|
| 59 |
-
f"({data.get('correct_count', '?')}/{data.get('total_attempted', '?')})\n"
|
| 60 |
-
f"{data.get('message', '')}"
|
| 61 |
-
)
|
| 62 |
-
except Exception as e:
|
| 63 |
-
status = f"Submission Failed: {e}"
|
| 64 |
-
|
| 65 |
-
return status, pd.DataFrame(log)
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
# ----- Gradio UI -----
|
| 69 |
-
with gr.Blocks() as demo:
|
| 70 |
-
gr.Markdown("# GAIA Q&A with smolagents")
|
| 71 |
-
login = gr.LoginButton()
|
| 72 |
-
run_btn = gr.Button("Run & Submit All", variant="primary")
|
| 73 |
-
|
| 74 |
-
status_out = gr.Textbox(label="Submission Status", lines=4)
|
| 75 |
-
results_table = gr.DataFrame(label="Per-Question Log")
|
| 76 |
-
|
| 77 |
-
run_btn.click(fn=run_and_submit_all, inputs=[login], outputs=[status_out, results_table])
|
| 78 |
-
|
| 79 |
-
if __name__ == "__main__":
|
| 80 |
-
demo.launch()
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|