Omlesna commited on
Commit
22db229
·
1 Parent(s): 50ae8da
Files changed (2) hide show
  1. app.py +72 -0
  2. requirements.txt +2 -1
app.py CHANGED
@@ -69,6 +69,78 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
69
  )
70
  except Exception as e:
71
  print(f"Attempted access to resource at {file_url} -> error: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  except requests.exceptions.RequestException as e:
73
  print(f"Error fetching questions: {e}")
74
  return f"Error fetching questions: {e}", None
 
69
  )
70
  except Exception as e:
71
  print(f"Attempted access to resource at {file_url} -> error: {e}")
72
+
73
+ # Try fetching the same files from the official GAIA dataset using the HF token.
74
+ gaia_repo = "gaia-benchmark/GAIA"
75
+ gaia_files_cache = None
76
+ try:
77
+ from huggingface_hub import list_repo_files, hf_hub_download
78
+ except Exception as e:
79
+ print(f"Skipping GAIA file fetch (huggingface_hub not available): {e}")
80
+ gaia_repo = None
81
+
82
+ if gaia_repo:
83
+ # Inspect profile to locate token; also allow env var fallbacks.
84
+ try:
85
+ print("Profile keys:", list(profile.__dict__.keys()))
86
+ except Exception as e:
87
+ print(f"Could not introspect profile: {e}")
88
+
89
+ token = None
90
+ for attr in ("access_token", "token"):
91
+ token = getattr(profile, attr, None)
92
+ if token:
93
+ print(f"Using token from profile.{attr}")
94
+ break
95
+ if not token:
96
+ # Some OAuth profiles keep tokens under .tokens or .auth
97
+ for attr in ("tokens", "auth"):
98
+ container = getattr(profile, attr, None)
99
+ if isinstance(container, dict):
100
+ token = container.get("access_token") or container.get("token")
101
+ if token:
102
+ print(f"Using token from profile.{attr}")
103
+ break
104
+ if not token:
105
+ token = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACEHUB_API_TOKEN") or os.getenv("HUGGINGFACE_HUB_TOKEN")
106
+ if token:
107
+ print("Using token from environment.")
108
+
109
+ if not token:
110
+ print("Skipping GAIA file fetch (no HF token found in profile or env).")
111
+ else:
112
+ for q in with_file:
113
+ fname = q.get("file_name")
114
+ task_id = q.get("task_id")
115
+ if gaia_files_cache is None:
116
+ try:
117
+ gaia_files_cache = list_repo_files(
118
+ gaia_repo, repo_type="dataset", token=token
119
+ )
120
+ print(f"GAIA repo file count: {len(gaia_files_cache)}")
121
+ except Exception as e:
122
+ print(f"Failed to list GAIA repo files: {e}")
123
+ gaia_files_cache = []
124
+ matches = []
125
+ if gaia_files_cache:
126
+ # First try an exact filename match, then any path containing the task_id.
127
+ matches = [p for p in gaia_files_cache if p.endswith(fname)]
128
+ if not matches:
129
+ matches = [p for p in gaia_files_cache if task_id in p]
130
+ if not matches:
131
+ print(f"GAIA file not found for task {task_id} (looking for {fname}).")
132
+ continue
133
+ match_path = matches[0]
134
+ try:
135
+ local_path = hf_hub_download(
136
+ gaia_repo,
137
+ match_path,
138
+ repo_type="dataset",
139
+ token=token,
140
+ )
141
+ print(f"Downloaded GAIA file for task {task_id} to {local_path}")
142
+ except Exception as e:
143
+ print(f"Failed to download GAIA file for task {task_id} ({match_path}): {e}")
144
  except requests.exceptions.RequestException as e:
145
  print(f"Error fetching questions: {e}")
146
  return f"Error fetching questions: {e}", None
requirements.txt CHANGED
@@ -2,4 +2,5 @@ gradio
2
  requests
3
 
4
  langgraph
5
- langchain_openai
 
 
2
  requests
3
 
4
  langgraph
5
+ langchain_openai
6
+ huggingface_hub