Mustafa-albakkar commited on
Commit
2e0bf0f
ยท
verified ยท
1 Parent(s): 9c1af9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -20
app.py CHANGED
@@ -506,38 +506,39 @@ class GaiaRunner:
506
  _session.mount("https://", _adapter)
507
  _session.mount("http://", _adapter)
508
 
509
- @staticmethod
510
- def download_gaia_attachment(task: dict) -> str:
511
- """
512
- ุชู†ุฒูŠู„ ุงู„ู…ุฑูู‚ ุงู„ู…ุฑุชุจุท ุจุงู„ุณุคุงู„ ู…ู† GAIA API ูˆุชุฎุฒูŠู†ู‡ ู…ุญู„ูŠู‹ุง (ุฅู† ูˆุฌุฏ).
513
- ุฅุฐุง ู„ู… ูŠูˆุฌุฏ ุงู„ู…ุฑูู‚ ุฃูˆ ูุดู„ ุงู„ุชุญู…ูŠู„ุŒ ุชุนูŠุฏ ุงู„ุฏุงู„ุฉ None.
514
- """
515
- task_id = task.get("task_id")
516
- file_name = task.get("file_name")
517
 
518
- if not task_id or not file_name:
519
- return None # ู„ุง ูŠูˆุฌุฏ ู…ุฑูู‚
 
 
 
 
520
 
521
- url = f"https://agents-course-unit4-scoring.hf.space/files/{task_id}"
522
- local_path = os.path.join("attachments", file_name)
523
 
524
- if os.path.exists(local_path):
525
- print(f"[GAIA] Attachment already exists: {local_path}")
526
- return local_path
527
 
 
 
528
  try:
529
  r = requests.get(url, timeout=30)
530
- if r.status_code == 404:
531
- print(f"[GAIA] No attachment found on server for task {task_id} (404).")
532
- return None
533
  r.raise_for_status()
534
  with open(local_path, "wb") as f:
535
  f.write(r.content)
536
  print(f"[GAIA] Attachment downloaded: {local_path}")
537
- return local_path
538
  except Exception as e:
539
- print(f"[GAIA] Failed to download attachment for {task_id}: {e}")
540
  return None
 
 
 
 
541
 
542
  # -------------------- LangGraph Integration --------------------
543
  if LANGGRAPH_AVAILABLE:
 
506
  _session.mount("https://", _adapter)
507
  _session.mount("http://", _adapter)
508
 
509
+ # @staticmethod
510
+ ATTACHMENTS_DIR = "attachments"
511
+ os.makedirs(ATTACHMENTS_DIR, exist_ok=True)
 
 
 
 
 
512
 
513
+ def download_gaia_attachment(task: dict) -> str:
514
+ """
515
+ ุชู†ุฒูŠู„ ุงู„ู…ุฑูู‚ ุงู„ู…ุฑุชุจุท ุจุงู„ุณุคุงู„ ู…ู† GAIA API ูˆุชุฎุฒูŠู†ู‡ ู…ุญู„ูŠู‹ุง.
516
+ """
517
+ task_id = task.get("task_id")
518
+ file_name = task.get("file_name")
519
 
520
+ if not task_id or not file_name:
521
+ return None # ู„ุง ูŠูˆุฌุฏ ู…ุฑูู‚
522
 
523
+ # ุฑุงุจุท API ู„ุชุญู…ูŠู„ ุงู„ู…ู„ู
524
+ url = f"https://agents-course-unit4-scoring.hf.space/files/{task_id}"
525
+ local_path = os.path.join(ATTACHMENTS_DIR, file_name)
526
 
527
+ # ุชู†ุฒูŠู„ ุงู„ู…ู„ู ุฅุฐุง ู„ู… ูŠูƒู† ู…ูˆุฌูˆุฏู‹ุง ู…ุญู„ูŠู‹ุง
528
+ if not os.path.exists(local_path):
529
  try:
530
  r = requests.get(url, timeout=30)
 
 
 
531
  r.raise_for_status()
532
  with open(local_path, "wb") as f:
533
  f.write(r.content)
534
  print(f"[GAIA] Attachment downloaded: {local_path}")
 
535
  except Exception as e:
536
+ print(f"[GAIA] Failed to download attachment: {e}")
537
  return None
538
+ else:
539
+ print(f"[GAIA] Attachment already exists: {local_path}")
540
+
541
+ return local_path
542
 
543
  # -------------------- LangGraph Integration --------------------
544
  if LANGGRAPH_AVAILABLE: