iQuentin commited on
Commit
d60a3ea
·
verified ·
1 Parent(s): daa1f61

add already_answered write

Browse files
Files changed (1) hide show
  1. simuGAIA.py +26 -0
simuGAIA.py CHANGED
@@ -232,6 +232,7 @@ def run_simuGAIA_all( profile: gr.OAuthProfile | None, submit: Optional[bool] =
232
  # 3. Run your Agent
233
  results_log = []
234
  answers_payload = []
 
235
  print(f"Running agent on {len(questions_data)} questions...")
236
  for item in questions_data:
237
  task_id = item.get("task_id")
@@ -243,11 +244,34 @@ def run_simuGAIA_all( profile: gr.OAuthProfile | None, submit: Optional[bool] =
243
  if question_text.startswith(".rewsna eht sa"): # ("How many studio albums"): <--- REMOVE THAT FOR ALL QUESTIONS
244
  print(f"First question detected. INVOKING AGENT! Be careful!")
245
  submitted_answer = agent.invoke(question_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
247
  else:
248
  submitted_answer = "NO AGENT INVOKED"
249
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
250
 
 
251
  except Exception as e:
252
  print(f"Error running agent on task {task_id}: {e}")
253
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
@@ -259,11 +283,13 @@ def run_simuGAIA_all( profile: gr.OAuthProfile | None, submit: Optional[bool] =
259
  if not submit:
260
  return "Run finished. No submission done, as asked.", pd.DataFrame(results_log)
261
 
 
262
  # 4. Prepare Submission
263
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
264
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
265
  print(status_update)
266
 
 
267
  # 5. Submit
268
  print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
269
  try:
 
232
  # 3. Run your Agent
233
  results_log = []
234
  answers_payload = []
235
+
236
  print(f"Running agent on {len(questions_data)} questions...")
237
  for item in questions_data:
238
  task_id = item.get("task_id")
 
244
  if question_text.startswith(".rewsna eht sa"): # ("How many studio albums"): <--- REMOVE THAT FOR ALL QUESTIONS
245
  print(f"First question detected. INVOKING AGENT! Be careful!")
246
  submitted_answer = agent.invoke(question_text)
247
+
248
+ # Save answer, task_id, and question_text to already_answered.json
249
+ record = {
250
+ "task_id": task_id,
251
+ "question_text": question_text,
252
+ "submitted_answer": submitted_answer
253
+ }
254
+ json_path = "already_answered.json"
255
+ try:
256
+ if os.path.exists(json_path):
257
+ with open(json_path, "r", encoding="utf-8") as f:
258
+ data = json.load(f)
259
+ if not isinstance(data, list):
260
+ data = []
261
+ else:
262
+ data = []
263
+ data.append(record)
264
+ with open(json_path, "w", encoding="utf-8") as f:
265
+ json.dump(data, f, ensure_ascii=False, indent=2)
266
+ except Exception as e:
267
+ print(f"Error saving to {json_path}: {e}")
268
+
269
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
270
  else:
271
  submitted_answer = "NO AGENT INVOKED"
272
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
273
 
274
+
275
  except Exception as e:
276
  print(f"Error running agent on task {task_id}: {e}")
277
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
 
283
  if not submit:
284
  return "Run finished. No submission done, as asked.", pd.DataFrame(results_log)
285
 
286
+
287
  # 4. Prepare Submission
288
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
289
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
290
  print(status_update)
291
 
292
+
293
  # 5. Submit
294
  print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
295
  try: