Spaces:
Sleeping
Sleeping
Fetch GAIA attachments directly from the dataset, bypass broken proxy
Browse filesScoring server's /files/{task_id} always 404s (confirmed bug, matching open unmerged PR on agents-course/Unit4_scoring). Fetch attachments directly from gaia-benchmark/GAIA dataset at 2023/validation/<file_name> via hf_hub_download() with the user's OAuth token instead. Verified working for png/mp3/py.
app.py
CHANGED
|
@@ -7,6 +7,7 @@ import requests
|
|
| 7 |
import inspect
|
| 8 |
import pandas as pd
|
| 9 |
import spaces
|
|
|
|
| 10 |
|
| 11 |
from smolagents import (
|
| 12 |
ActionStep,
|
|
@@ -22,6 +23,17 @@ from smolagents import (
|
|
| 22 |
# --- Constants ---
|
| 23 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
@spaces.GPU
|
| 27 |
def _zerogpu_startup_check():
|
|
@@ -175,7 +187,7 @@ class BasicAgent:
|
|
| 175 |
print(f"Agent returning answer: {answer}")
|
| 176 |
return answer
|
| 177 |
|
| 178 |
-
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 179 |
"""
|
| 180 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 181 |
and displays the results.
|
|
@@ -241,14 +253,25 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 241 |
file_path = None
|
| 242 |
if file_name:
|
| 243 |
try:
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
try:
|
| 254 |
submitted_answer = agent(question_text, file_path=file_path)
|
|
|
|
| 7 |
import inspect
|
| 8 |
import pandas as pd
|
| 9 |
import spaces
|
| 10 |
+
from huggingface_hub import hf_hub_download
|
| 11 |
|
| 12 |
from smolagents import (
|
| 13 |
ActionStep,
|
|
|
|
| 23 |
# --- Constants ---
|
| 24 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 25 |
|
| 26 |
+
# The scoring server's own /files/{task_id} endpoint is broken (confirmed via
|
| 27 |
+
# a direct request and a matching open PR on agents-course/Unit4_scoring:
|
| 28 |
+
# it stores GAIA attachment paths as HF-Hub-repo-relative paths but checks
|
| 29 |
+
# them as local filesystem paths, so every lookup 404s: "No file path
|
| 30 |
+
# associated with task_id ..."). Attachments live directly in the gated
|
| 31 |
+
# gaia-benchmark/GAIA dataset instead; fetch them from there using the
|
| 32 |
+
# logged-in user's own OAuth token (requires that account to have requested
|
| 33 |
+
# access to the dataset, and the `gated-repos` OAuth scope in README.md).
|
| 34 |
+
GAIA_DATASET_REPO = "gaia-benchmark/GAIA"
|
| 35 |
+
GAIA_DATASET_SUBDIR = "2023/validation"
|
| 36 |
+
|
| 37 |
|
| 38 |
@spaces.GPU
|
| 39 |
def _zerogpu_startup_check():
|
|
|
|
| 187 |
print(f"Agent returning answer: {answer}")
|
| 188 |
return answer
|
| 189 |
|
| 190 |
+
def run_and_submit_all( profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None):
|
| 191 |
"""
|
| 192 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 193 |
and displays the results.
|
|
|
|
| 253 |
file_path = None
|
| 254 |
if file_name:
|
| 255 |
try:
|
| 256 |
+
file_path = hf_hub_download(
|
| 257 |
+
repo_id=GAIA_DATASET_REPO,
|
| 258 |
+
repo_type="dataset",
|
| 259 |
+
filename=f"{GAIA_DATASET_SUBDIR}/{file_name}",
|
| 260 |
+
token=oauth_token.token if oauth_token else None,
|
| 261 |
+
)
|
| 262 |
+
except Exception as e:
|
| 263 |
+
print(f"Could not download attached file for task {task_id} from {GAIA_DATASET_REPO}: {e}")
|
| 264 |
+
# Fall back to the scoring server's own endpoint, in case
|
| 265 |
+
# it's since been fixed (see GAIA_DATASET_REPO comment above).
|
| 266 |
+
try:
|
| 267 |
+
file_response = requests.get(f"{api_url}/files/{task_id}", timeout=30)
|
| 268 |
+
file_response.raise_for_status()
|
| 269 |
+
file_path = os.path.join(tmp_dir, file_name)
|
| 270 |
+
with open(file_path, "wb") as f:
|
| 271 |
+
f.write(file_response.content)
|
| 272 |
+
except requests.exceptions.RequestException as e2:
|
| 273 |
+
print(f"Fallback download also failed for task {task_id}: {e2}")
|
| 274 |
+
file_path = None
|
| 275 |
|
| 276 |
try:
|
| 277 |
submitted_answer = agent(question_text, file_path=file_path)
|