Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,65 +8,68 @@ from agents.router import route_task, profiles
|
|
| 8 |
|
| 9 |
API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
-
def evaluate_all(temperature: float
|
| 12 |
# 1) Fetch GAIA questions
|
| 13 |
resp = requests.get(f"{API_URL}/questions", timeout=15)
|
| 14 |
resp.raise_for_status()
|
| 15 |
questions = resp.json()
|
| 16 |
|
| 17 |
-
# 2) Initialize agent
|
| 18 |
agent = GaiaAgent()
|
| 19 |
|
| 20 |
-
# 3) Run
|
| 21 |
rows = []
|
| 22 |
answers_payload = []
|
| 23 |
for item in questions:
|
| 24 |
-
|
| 25 |
-
prompt
|
| 26 |
-
kind
|
| 27 |
profile = profiles.get(kind, {}).copy()
|
| 28 |
profile["temperature"] = temperature
|
| 29 |
-
profile["num_samples"] =
|
| 30 |
|
| 31 |
answer = agent.run(prompt, profile)
|
| 32 |
rows.append({
|
| 33 |
-
"Task ID":
|
| 34 |
-
"Question":
|
| 35 |
-
"Answer":
|
| 36 |
})
|
| 37 |
answers_payload.append({
|
| 38 |
-
"task_id":
|
| 39 |
-
"submitted_answer":
|
| 40 |
})
|
| 41 |
|
| 42 |
-
# 4)
|
| 43 |
submission = {
|
| 44 |
-
"username":
|
| 45 |
-
"agent_code":
|
| 46 |
-
"answers":
|
| 47 |
}
|
| 48 |
with open("submission.json", "w") as f:
|
| 49 |
json.dump(submission, f, indent=2)
|
| 50 |
|
| 51 |
-
# 5) Return the DataFrame and the file
|
| 52 |
return pd.DataFrame(rows), "submission.json"
|
| 53 |
|
| 54 |
|
| 55 |
with gr.Blocks() as demo:
|
| 56 |
-
gr.Markdown("## GAIA Benchmark — Evaluate Only (
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
-
run_btn = gr.Button("▶️ Run Evaluation")
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
| 65 |
download = gr.File(label="Download submission.json")
|
| 66 |
|
| 67 |
run_btn.click(
|
| 68 |
fn=evaluate_all,
|
| 69 |
-
inputs=[temp_slider
|
| 70 |
outputs=[results_df, download]
|
| 71 |
)
|
| 72 |
|
|
@@ -76,3 +79,4 @@ if __name__ == "__main__":
|
|
| 76 |
|
| 77 |
|
| 78 |
|
|
|
|
|
|
| 8 |
|
| 9 |
API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
+
def evaluate_all(temperature: float):
|
| 12 |
# 1) Fetch GAIA questions
|
| 13 |
resp = requests.get(f"{API_URL}/questions", timeout=15)
|
| 14 |
resp.raise_for_status()
|
| 15 |
questions = resp.json()
|
| 16 |
|
| 17 |
+
# 2) Initialize agent (Falcon3-1B-Instruct on CPU)
|
| 18 |
agent = GaiaAgent()
|
| 19 |
|
| 20 |
+
# 3) Run each question with 1 chain
|
| 21 |
rows = []
|
| 22 |
answers_payload = []
|
| 23 |
for item in questions:
|
| 24 |
+
tid = item["task_id"]
|
| 25 |
+
prompt = item["question"]
|
| 26 |
+
kind = route_task(prompt)
|
| 27 |
profile = profiles.get(kind, {}).copy()
|
| 28 |
profile["temperature"] = temperature
|
| 29 |
+
profile["num_samples"] = 1
|
| 30 |
|
| 31 |
answer = agent.run(prompt, profile)
|
| 32 |
rows.append({
|
| 33 |
+
"Task ID": tid,
|
| 34 |
+
"Question": prompt,
|
| 35 |
+
"Answer": answer
|
| 36 |
})
|
| 37 |
answers_payload.append({
|
| 38 |
+
"task_id": tid,
|
| 39 |
+
"submitted_answer": answer
|
| 40 |
})
|
| 41 |
|
| 42 |
+
# 4) Save submission.json locally for inspection
|
| 43 |
submission = {
|
| 44 |
+
"username": "<evaluate_only>",
|
| 45 |
+
"agent_code": "<none>",
|
| 46 |
+
"answers": answers_payload
|
| 47 |
}
|
| 48 |
with open("submission.json", "w") as f:
|
| 49 |
json.dump(submission, f, indent=2)
|
| 50 |
|
| 51 |
+
# 5) Return the DataFrame and the file link
|
| 52 |
return pd.DataFrame(rows), "submission.json"
|
| 53 |
|
| 54 |
|
| 55 |
with gr.Blocks() as demo:
|
| 56 |
+
gr.Markdown("## GAIA Benchmark — Evaluate Only (Falcon3-1B-Instruct)")
|
| 57 |
|
| 58 |
+
temp_slider = gr.Slider(
|
| 59 |
+
0.0, 1.0, value=0.3, step=0.05,
|
| 60 |
+
label="Temperature"
|
| 61 |
+
)
|
| 62 |
|
| 63 |
+
run_btn = gr.Button("▶️ Run Evaluation (1 chain)")
|
| 64 |
+
results_df = gr.DataFrame(
|
| 65 |
+
headers=["Task ID", "Question", "Answer"],
|
| 66 |
+
label="Results (20 questions, 1 chain)"
|
| 67 |
+
)
|
| 68 |
download = gr.File(label="Download submission.json")
|
| 69 |
|
| 70 |
run_btn.click(
|
| 71 |
fn=evaluate_all,
|
| 72 |
+
inputs=[temp_slider],
|
| 73 |
outputs=[results_df, download]
|
| 74 |
)
|
| 75 |
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
+
|