Asapyams commited on
Commit
406867e
·
verified ·
1 Parent(s): 9f87063

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -25
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, num_chains: int):
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 through each question
21
  rows = []
22
  answers_payload = []
23
  for item in questions:
24
- task_id = 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"] = num_chains
30
 
31
  answer = agent.run(prompt, profile)
32
  rows.append({
33
- "Task ID": task_id,
34
- "Question": prompt,
35
- "Answer": answer
36
  })
37
  answers_payload.append({
38
- "task_id": task_id,
39
- "submitted_answer": answer
40
  })
41
 
42
- # 4) Write submission.json for inspection or manual upload
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 for download
52
  return pd.DataFrame(rows), "submission.json"
53
 
54
 
55
  with gr.Blocks() as demo:
56
- gr.Markdown("## GAIA Benchmark — Evaluate Only (CPU)")
57
 
58
- with gr.Row():
59
- temp_slider = gr.Slider(0.0, 1.0, value=0.3, step=0.05, label="Temperature")
60
- chains_slider = gr.Slider(1, 5, value=1, step=1, label="Self-Consistency Chains")
 
61
 
62
- run_btn = gr.Button("▶️ Run Evaluation")
63
- # <<< Fix here: use 'headers' instead of 'header' >>>
64
- results_df = gr.DataFrame(headers=["Task ID","Question","Answer"], label="Results")
 
 
65
  download = gr.File(label="Download submission.json")
66
 
67
  run_btn.click(
68
  fn=evaluate_all,
69
- inputs=[temp_slider, chains_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
+