Spaces:
Runtime error
Runtime error
import requests | |
import os | |
import json | |
# API base URL | |
BASE_URL = "https://agents-course-unit4-scoring.hf.space" | |
import os | |
def get_hf_username(): | |
""" | |
Gets Hugging Face username for submission. | |
""" | |
return os.environ.get("HF_USERNAME", "shrutikaP8497") # replace with your HF username | |
def get_code_link(): | |
""" | |
Returns the public URL to the Hugging Face Space code. | |
""" | |
return "https://huggingface.co/spaces/shrutikaP8497/gaia_agent_code" | |
def download_task_file(task_id, save_dir="downloads"): | |
""" | |
Downloads a file associated with a task from the GAIA evaluation API. | |
""" | |
os.makedirs(save_dir, exist_ok=True) | |
url = f"{BASE_URL}/files/{task_id}" | |
response = requests.get(url) | |
if response.status_code == 200: | |
filename = os.path.join(save_dir, task_id) | |
with open(filename, "wb") as f: | |
f.write(response.content) | |
return filename | |
else: | |
print(f"Failed to download file for task {task_id}") | |
return None | |
def format_answer(agent_output): | |
""" | |
Format the agent's response to meet submission requirements: | |
- Do NOT include 'FINAL ANSWER' | |
- Must be a concise string or comma-separated list | |
""" | |
if isinstance(agent_output, str): | |
return agent_output.strip() | |
elif isinstance(agent_output, list): | |
return ", ".join(map(str, agent_output)) | |
elif isinstance(agent_output, (int, float)): | |
return str(agent_output) | |
else: | |
return str(agent_output) | |
def log_submission(task_id, answer, reasoning_trace=None, save_path="submission_log.jsonl"): | |
""" | |
Log the task_id and answer for debugging/submission traceability. | |
""" | |
entry = { | |
"task_id": task_id, | |
"submitted_answer": answer, | |
} | |
if reasoning_trace: | |
entry["reasoning_trace"] = reasoning_trace | |
with open(save_path, "a") as f: | |
f.write(json.dumps(entry) + "\n") | |