Ghisalbertifederico commited on
Commit
47cc8ce
·
verified ·
1 Parent(s): a1457c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -19
app.py CHANGED
@@ -280,21 +280,37 @@ def read_task_file(file_path: str) -> str:
280
  return f.read()
281
 
282
 
 
 
 
 
283
  def _download_task_file(task_id: str, file_name: str, api_url: str = DEFAULT_API_URL) -> str | None:
284
  """Download a file attached to a GAIA task and save it locally. Returns local path or None."""
285
  url = f"{api_url}/files/{task_id}"
286
- headers = {"Authorization": f"Bearer {HF_TOKEN}"}
287
- try:
288
- resp = requests.get(url, headers=headers, timeout=30)
289
- resp.raise_for_status()
290
- local_path = os.path.join(os.getcwd(), f"task_{task_id}_{file_name}")
291
- with open(local_path, "wb") as fh:
292
- fh.write(resp.content)
293
- print(f"Downloaded task file: {local_path}")
294
- return local_path
295
- except Exception as e:
296
- print(f"Could not download file for task {task_id}: {e}")
297
- return None
 
 
 
 
 
 
 
 
 
 
 
 
298
 
299
 
300
  class WebSearchAgent:
@@ -309,13 +325,6 @@ class WebSearchAgent:
309
  api_base="https://api.groq.com/openai/v1",
310
  api_key=GROQ_API_KEY,
311
  timeout=60,
312
- # --- Groq alternatives ---
313
- # model_id="meta-llama/llama-4-scout-17b-16e-instruct",
314
- # --- OpenRouter: free models (often 429/rate-limited) ---
315
- # model_id="arcee-ai/trinity-large-preview:free",
316
- # model_id="google/gemma-3-27b-it:free",
317
- # api_base="https://openrouter.ai/api/v1",
318
- # api_key=OPENROUTER_API_KEY,
319
  ),
320
  tools=[
321
  web_search,
 
280
  return f.read()
281
 
282
 
283
+ _DOWNLOAD_DIR = os.path.join(os.environ.get("TMPDIR", "/tmp"), "gaia_files")
284
+ os.makedirs(_DOWNLOAD_DIR, exist_ok=True)
285
+
286
+
287
  def _download_task_file(task_id: str, file_name: str, api_url: str = DEFAULT_API_URL) -> str | None:
288
  """Download a file attached to a GAIA task and save it locally. Returns local path or None."""
289
  url = f"{api_url}/files/{task_id}"
290
+ local_path = os.path.join(_DOWNLOAD_DIR, f"task_{task_id}_{file_name}")
291
+
292
+ # Try with auth first, then without (some endpoints don't require it)
293
+ for headers in [
294
+ {"Authorization": f"Bearer {HF_TOKEN}"},
295
+ {},
296
+ ]:
297
+ try:
298
+ resp = requests.get(url, headers=headers, timeout=30)
299
+ resp.raise_for_status()
300
+ with open(local_path, "wb") as fh:
301
+ fh.write(resp.content)
302
+ print(f"Downloaded task file: {local_path} ({len(resp.content)} bytes)")
303
+ return local_path
304
+ except requests.exceptions.HTTPError as e:
305
+ status = e.response.status_code if e.response is not None else "?"
306
+ print(f"Download attempt for {task_id} returned {status} (auth={'yes' if headers else 'no'})")
307
+ continue
308
+ except Exception as e:
309
+ print(f"Download error for {task_id}: {e}")
310
+ continue
311
+
312
+ print(f"Could not download file for task {task_id} after all attempts")
313
+ return None
314
 
315
 
316
  class WebSearchAgent:
 
325
  api_base="https://api.groq.com/openai/v1",
326
  api_key=GROQ_API_KEY,
327
  timeout=60,
 
 
 
 
 
 
 
328
  ),
329
  tools=[
330
  web_search,