Spaces:
Sleeping
Sleeping
File size: 1,821 Bytes
d03c5e0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | # 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()
|