# local_test.py from core_agent import GAIAAgent import json import requests from pathlib import Path API_URL = "https://agents-course-unit4-scoring.hf.space/questions" agent = GAIAAgent() def fetch_real_questions(): try: print("šŸ“” Fetching GAIA-style questions from HF server...") response = requests.get(API_URL, timeout=15) response.raise_for_status() questions = response.json() return questions except Exception as e: print(f"āŒ Failed to fetch questions: {e}") return [] def main(): questions = fetch_real_questions() if not questions: print("āš ļø No questions found. Exiting.") return results = [] for i, q in enumerate(questions, 1): task_id = q.get("task_id") question_text = q.get("question") print(f"\n[{i}] Task ID: {task_id}") print(f"šŸ“Ø Question: {question_text}") try: answer = agent.answer_question(question_text) print(f"āœ… Answer: {answer}") results.append({ "task_id": task_id, "question": question_text, "submitted_answer": answer }) except Exception as e: print(f"āŒ Error: {e}") results.append({ "task_id": task_id, "question": question_text, "submitted_answer": f"ERROR: {e}" }) # Optional: save answers locally save_path = Path("gaia_local_results.json") with save_path.open("w", encoding="utf-8") as f: json.dump(results, f, ensure_ascii=False, indent=4) print(f"\nšŸ“ Saved results to: {save_path.absolute()}") if __name__ == "__main__": main()