| import requests |
| import json |
|
|
| |
| HF_USERNAME = "YOUR_HF_USERNAME" |
| AGENT_CODE_URL = f"https://huggingface.co/spaces/{HF_USERNAME}/YOUR_SPACE_NAME/tree/main" |
| API_BASE_URL = "https://agents-course-unit4-scoring.hf.space" |
|
|
| def fetch_questions(): |
| """Retrieves the 20 GAIA level 1 validation questions from the API.""" |
| print("Fetching questions from the API...") |
| response = requests.get(f"{API_BASE_URL}/questions") |
| if response.status_code == 200: |
| return response.json() |
| else: |
| raise Exception(f"Failed to fetch questions: {response.text}") |
|
|
| def download_task_file(task_id): |
| """Downloads associated files if the task requires it.""" |
| |
| |
| url = f"{API_BASE_URL}/files/{task_id}" |
| response = requests.get(url) |
| if response.status_code == 200: |
| file_path = f"./{task_id}_file" |
| with open(file_path, "wb") as f: |
| f.write(response.content) |
| return file_path |
| return None |
|
|
| def dummy_agent_fallback(question_text): |
| """ |
| Placeholder for your real agent call. |
| REPLACE THIS with your actual LLM/Agent call! |
| """ |
| |
| system_prompt = ( |
| "You are a precise QA bot. Answer the question using your tools. " |
| "Output ONLY the final string or number representing the answer. " |
| "Do not include 'The answer is...', do not include 'FINAL ANSWER', " |
| "and do not include any conversational filler." |
| ) |
| |
| return "example_answer" |
|
|
| def submit_answers(submission_payload): |
| """Submits the payload to the final leaderboard API.""" |
| print("Submitting answers to the leaderboard...") |
| headers = {"Content-Type": "application/json"} |
| response = requests.post(f"{API_BASE_URL}/submit", json=submission_payload, headers=headers) |
| |
| if response.status_code == 200: |
| print("π Submission Successful!") |
| print("API Response:", response.json()) |
| else: |
| print(f"β Submission Failed ({response.status_code}):", response.text) |
|
|
| def main(): |
| questions = fetch_questions() |
| submitted_answers = [] |
| |
| |
| for item in questions: |
| task_id = item.get("task_id") |
| question = item.get("question") |
| has_file = item.get("has_file", False) |
| |
| print(f"\nProcessing Task ID: {task_id}") |
| |
| |
| if has_file: |
| file_path = download_task_file(task_id) |
| print(f"Downloaded file for task to: {file_path}") |
| |
| |
| answer = dummy_agent_fallback(question) |
| print(f"Agent Output: {answer}") |
| |
| |
| submitted_answers.append({ |
| "task_id": task_id, |
| "submitted_answer": str(answer).strip() |
| }) |
| |
| |
| payload = { |
| "username": HF_USERNAME, |
| "agent_code": AGENT_CODE_URL, |
| "answers": submitted_answers |
| } |
| |
| |
| submit_answers(payload) |
|
|
| if __name__ == "__main__": |
| main() |