Update app.py
Browse files
app.py
CHANGED
|
@@ -217,37 +217,54 @@ def download_scoring_file(task_id: str):
|
|
| 217 |
|
| 218 |
|
| 219 |
def dataset_fallback_file(task_id: str, hf_token: str):
|
| 220 |
-
"""Use the
|
| 221 |
try:
|
| 222 |
from datasets import load_dataset
|
| 223 |
|
|
|
|
|
|
|
|
|
|
| 224 |
ds = load_dataset(
|
| 225 |
GAIA_DATASET,
|
| 226 |
"2023_level1",
|
| 227 |
split="validation",
|
| 228 |
token=hf_token,
|
| 229 |
)
|
| 230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
if len(matches) == 0:
|
| 232 |
-
|
|
|
|
|
|
|
| 233 |
|
| 234 |
file_path = matches[0].get("file_path")
|
|
|
|
| 235 |
if not file_path:
|
| 236 |
-
|
|
|
|
|
|
|
| 237 |
|
| 238 |
-
|
|
|
|
|
|
|
| 239 |
repo_id=GAIA_DATASET,
|
| 240 |
repo_type="dataset",
|
| 241 |
filename=file_path,
|
| 242 |
token=hf_token,
|
| 243 |
)
|
| 244 |
-
except Exception as exc:
|
| 245 |
-
print(
|
| 246 |
-
f"GAIA dataset fallback unavailable for "
|
| 247 |
-
f"{task_id}: {type(exc).__name__}: {exc}"
|
| 248 |
-
)
|
| 249 |
-
raise
|
| 250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
def download_task_file(task_id: str, hf_token: str):
|
| 253 |
return download_scoring_file(task_id) or dataset_fallback_file(task_id, hf_token)
|
|
|
|
| 217 |
|
| 218 |
|
| 219 |
def dataset_fallback_file(task_id: str, hf_token: str):
|
| 220 |
+
"""Use the GAIA validation dataset to locate the exact attachment."""
|
| 221 |
try:
|
| 222 |
from datasets import load_dataset
|
| 223 |
|
| 224 |
+
if not hf_token:
|
| 225 |
+
raise RuntimeError("HF_TOKEN is empty.")
|
| 226 |
+
|
| 227 |
ds = load_dataset(
|
| 228 |
GAIA_DATASET,
|
| 229 |
"2023_level1",
|
| 230 |
split="validation",
|
| 231 |
token=hf_token,
|
| 232 |
)
|
| 233 |
+
|
| 234 |
+
matches = ds.filter(
|
| 235 |
+
lambda row: row["task_id"] == task_id
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
if len(matches) == 0:
|
| 239 |
+
raise RuntimeError(
|
| 240 |
+
f"Task ID {task_id} was not found in the GAIA validation dataset."
|
| 241 |
+
)
|
| 242 |
|
| 243 |
file_path = matches[0].get("file_path")
|
| 244 |
+
|
| 245 |
if not file_path:
|
| 246 |
+
raise RuntimeError(
|
| 247 |
+
f"Task {task_id} exists, but file_path is empty."
|
| 248 |
+
)
|
| 249 |
|
| 250 |
+
print(f"GAIA attachment file_path: {file_path}")
|
| 251 |
+
|
| 252 |
+
downloaded = hf_hub_download(
|
| 253 |
repo_id=GAIA_DATASET,
|
| 254 |
repo_type="dataset",
|
| 255 |
filename=file_path,
|
| 256 |
token=hf_token,
|
| 257 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
|
| 259 |
+
print(f"GAIA attachment downloaded: {downloaded}")
|
| 260 |
+
|
| 261 |
+
return downloaded
|
| 262 |
+
|
| 263 |
+
except Exception as exc:
|
| 264 |
+
raise RuntimeError(
|
| 265 |
+
f"GAIA dataset attachment fallback failed: "
|
| 266 |
+
f"{type(exc).__name__}: {exc}"
|
| 267 |
+
) from exc
|
| 268 |
|
| 269 |
def download_task_file(task_id: str, hf_token: str):
|
| 270 |
return download_scoring_file(task_id) or dataset_fallback_file(task_id, hf_token)
|