Spaces:
Sleeping
Sleeping
Chris
commited on
Commit
Β·
1e17e7f
1
Parent(s):
65443cb
Final 5.5.3
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- src/app.py +149 -2
- src/requirements.txt +20 -0
__pycache__/app.cpython-310.pyc
ADDED
|
Binary file (6.84 kB). View file
|
|
|
src/app.py
CHANGED
|
@@ -227,6 +227,136 @@ class GAIAAgentApp:
|
|
| 227 |
"How many studio albums were published by Mercedes Sosa between 2000 and 2009?",
|
| 228 |
]
|
| 229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 231 |
"""
|
| 232 |
Fetches all questions from Unit 4 API, runs the GAIA Agent on them, submits all answers,
|
|
@@ -243,7 +373,6 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 243 |
# Check if OAuth token has sufficient scopes
|
| 244 |
if oauth_token:
|
| 245 |
try:
|
| 246 |
-
import requests
|
| 247 |
headers = {"Authorization": f"Bearer {oauth_token}"}
|
| 248 |
test_response = requests.get("https://huggingface.co/api/whoami", headers=headers, timeout=5)
|
| 249 |
|
|
@@ -698,7 +827,13 @@ def create_interface():
|
|
| 698 |
for basic questions but may have reduced performance on complex queries.
|
| 699 |
""")
|
| 700 |
|
| 701 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 702 |
|
| 703 |
unit4_run_button = gr.Button(
|
| 704 |
"π Run GAIA Evaluation & Submit All Answers",
|
|
@@ -789,6 +924,18 @@ def create_interface():
|
|
| 789 |
outputs=[unit4_status_output, unit4_results_table]
|
| 790 |
)
|
| 791 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 792 |
# Event handlers for manual testing
|
| 793 |
def process_and_update(question, file_input, show_reasoning):
|
| 794 |
answer, details, reasoning = app.process_question_detailed(question, file_input, show_reasoning)
|
|
|
|
| 227 |
"How many studio albums were published by Mercedes Sosa between 2000 and 2009?",
|
| 228 |
]
|
| 229 |
|
| 230 |
+
def check_oauth_scopes(oauth_token: str) -> Dict[str, any]:
|
| 231 |
+
"""
|
| 232 |
+
Check what scopes are available with the OAuth token
|
| 233 |
+
Returns a dictionary with scope information and capabilities
|
| 234 |
+
"""
|
| 235 |
+
if not oauth_token:
|
| 236 |
+
return {
|
| 237 |
+
"logged_in": False,
|
| 238 |
+
"scopes": [],
|
| 239 |
+
"can_inference": False,
|
| 240 |
+
"can_read": False,
|
| 241 |
+
"message": "Not logged in"
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
try:
|
| 245 |
+
headers = {"Authorization": f"Bearer {oauth_token}"}
|
| 246 |
+
|
| 247 |
+
# Test whoami endpoint (requires read scope)
|
| 248 |
+
whoami_response = requests.get("https://huggingface.co/api/whoami", headers=headers, timeout=5)
|
| 249 |
+
can_read = whoami_response.status_code == 200
|
| 250 |
+
|
| 251 |
+
# Test inference capability by trying a simple model call
|
| 252 |
+
can_inference = False
|
| 253 |
+
try:
|
| 254 |
+
# Try a very simple inference call to test scope
|
| 255 |
+
inference_url = "https://api-inference.huggingface.co/models/microsoft/DialoGPT-medium"
|
| 256 |
+
test_payload = {"inputs": "test", "options": {"wait_for_model": False, "use_cache": True}}
|
| 257 |
+
inference_response = requests.post(inference_url, headers=headers, json=test_payload, timeout=10)
|
| 258 |
+
# 200 = success, 503 = model loading (but scope works), 401/403 = no scope
|
| 259 |
+
can_inference = inference_response.status_code in [200, 503]
|
| 260 |
+
except:
|
| 261 |
+
can_inference = False
|
| 262 |
+
|
| 263 |
+
# Determine probable scopes based on capabilities
|
| 264 |
+
probable_scopes = []
|
| 265 |
+
if can_read:
|
| 266 |
+
probable_scopes.append("read")
|
| 267 |
+
if can_inference:
|
| 268 |
+
probable_scopes.append("inference")
|
| 269 |
+
|
| 270 |
+
# Get user info if available
|
| 271 |
+
user_info = {}
|
| 272 |
+
if can_read:
|
| 273 |
+
try:
|
| 274 |
+
user_data = whoami_response.json()
|
| 275 |
+
user_info = {
|
| 276 |
+
"name": user_data.get("name", "Unknown"),
|
| 277 |
+
"fullname": user_data.get("fullName", ""),
|
| 278 |
+
"avatar": user_data.get("avatarUrl", "")
|
| 279 |
+
}
|
| 280 |
+
except:
|
| 281 |
+
pass
|
| 282 |
+
|
| 283 |
+
return {
|
| 284 |
+
"logged_in": True,
|
| 285 |
+
"scopes": probable_scopes,
|
| 286 |
+
"can_inference": can_inference,
|
| 287 |
+
"can_read": can_read,
|
| 288 |
+
"user_info": user_info,
|
| 289 |
+
"message": f"Logged in with scopes: {', '.join(probable_scopes) if probable_scopes else 'limited'}"
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
except Exception as e:
|
| 293 |
+
return {
|
| 294 |
+
"logged_in": True,
|
| 295 |
+
"scopes": ["unknown"],
|
| 296 |
+
"can_inference": False,
|
| 297 |
+
"can_read": False,
|
| 298 |
+
"message": f"Could not determine scopes: {str(e)}"
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
def format_auth_status(profile: gr.OAuthProfile | None) -> str:
|
| 302 |
+
"""Format authentication status for display in UI"""
|
| 303 |
+
if not profile:
|
| 304 |
+
return """
|
| 305 |
+
### π Authentication Status: Not Logged In
|
| 306 |
+
|
| 307 |
+
Please log in to access GAIA evaluation features.
|
| 308 |
+
|
| 309 |
+
**What you can do:**
|
| 310 |
+
- β
Manual question testing (limited functionality)
|
| 311 |
+
- β Official GAIA benchmark evaluation (requires login)
|
| 312 |
+
"""
|
| 313 |
+
|
| 314 |
+
username = profile.username
|
| 315 |
+
oauth_token = getattr(profile, 'oauth_token', None) or getattr(profile, 'token', None)
|
| 316 |
+
|
| 317 |
+
scope_info = check_oauth_scopes(oauth_token)
|
| 318 |
+
|
| 319 |
+
status_parts = [f"### π Authentication Status: Logged In as {username}"]
|
| 320 |
+
|
| 321 |
+
if scope_info["user_info"]:
|
| 322 |
+
user_info = scope_info["user_info"]
|
| 323 |
+
if user_info.get("fullname"):
|
| 324 |
+
status_parts.append(f"**Full Name**: {user_info['fullname']}")
|
| 325 |
+
|
| 326 |
+
status_parts.append(f"**Scopes**: {', '.join(scope_info['scopes']) if scope_info['scopes'] else 'None detected'}")
|
| 327 |
+
status_parts.append("")
|
| 328 |
+
status_parts.append("**Available Features:**")
|
| 329 |
+
|
| 330 |
+
if scope_info["can_inference"]:
|
| 331 |
+
status_parts.extend([
|
| 332 |
+
"- β
**Advanced Model Access**: Full Qwen model capabilities",
|
| 333 |
+
"- β
**High Performance**: 30%+ expected GAIA score",
|
| 334 |
+
"- β
**Complete Pipeline**: All agents and tools fully functional"
|
| 335 |
+
])
|
| 336 |
+
else:
|
| 337 |
+
status_parts.extend([
|
| 338 |
+
"- β οΈ **Limited Model Access**: Using fallback SimpleClient",
|
| 339 |
+
"- β οΈ **Basic Performance**: 15%+ expected GAIA score",
|
| 340 |
+
"- β
**Reliable Responses**: Rule-based answers for common questions"
|
| 341 |
+
])
|
| 342 |
+
|
| 343 |
+
if scope_info["can_read"]:
|
| 344 |
+
status_parts.append("- β
**Profile Access**: Can read user information")
|
| 345 |
+
|
| 346 |
+
status_parts.extend([
|
| 347 |
+
"- β
**Manual Testing**: Individual question processing",
|
| 348 |
+
"- β
**Official Evaluation**: GAIA benchmark submission"
|
| 349 |
+
])
|
| 350 |
+
|
| 351 |
+
if not scope_info["can_inference"]:
|
| 352 |
+
status_parts.extend([
|
| 353 |
+
"",
|
| 354 |
+
"π‘ **Note**: Your OAuth token has limited scopes (common with Gradio OAuth).",
|
| 355 |
+
"The system automatically uses reliable fallback methods to ensure functionality."
|
| 356 |
+
])
|
| 357 |
+
|
| 358 |
+
return "\n".join(status_parts)
|
| 359 |
+
|
| 360 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 361 |
"""
|
| 362 |
Fetches all questions from Unit 4 API, runs the GAIA Agent on them, submits all answers,
|
|
|
|
| 373 |
# Check if OAuth token has sufficient scopes
|
| 374 |
if oauth_token:
|
| 375 |
try:
|
|
|
|
| 376 |
headers = {"Authorization": f"Bearer {oauth_token}"}
|
| 377 |
test_response = requests.get("https://huggingface.co/api/whoami", headers=headers, timeout=5)
|
| 378 |
|
|
|
|
| 827 |
for basic questions but may have reduced performance on complex queries.
|
| 828 |
""")
|
| 829 |
|
| 830 |
+
# Authentication status section
|
| 831 |
+
auth_status_display = gr.Markdown(
|
| 832 |
+
format_auth_status(None),
|
| 833 |
+
elem_classes=["oauth-login"]
|
| 834 |
+
)
|
| 835 |
+
|
| 836 |
+
login_button = gr.LoginButton()
|
| 837 |
|
| 838 |
unit4_run_button = gr.Button(
|
| 839 |
"π Run GAIA Evaluation & Submit All Answers",
|
|
|
|
| 924 |
outputs=[unit4_status_output, unit4_results_table]
|
| 925 |
)
|
| 926 |
|
| 927 |
+
# Update authentication status on login/logout
|
| 928 |
+
login_button.change(
|
| 929 |
+
fn=format_auth_status,
|
| 930 |
+
outputs=[auth_status_display]
|
| 931 |
+
)
|
| 932 |
+
|
| 933 |
+
# Also update auth status when the interface loads
|
| 934 |
+
interface.load(
|
| 935 |
+
fn=format_auth_status,
|
| 936 |
+
outputs=[auth_status_display]
|
| 937 |
+
)
|
| 938 |
+
|
| 939 |
# Event handlers for manual testing
|
| 940 |
def process_and_update(question, file_input, show_reasoning):
|
| 941 |
answer, details, reasoning = app.process_question_detailed(question, file_input, show_reasoning)
|
src/requirements.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Core dependencies
|
| 2 |
+
gradio==4.44.0
|
| 3 |
+
langchain==0.3.9
|
| 4 |
+
langchain-community==0.3.7
|
| 5 |
+
langchain-core==0.3.18
|
| 6 |
+
langgraph==0.2.45
|
| 7 |
+
requests==2.32.3
|
| 8 |
+
pandas==2.2.3
|
| 9 |
+
huggingface-hub==0.26.2
|
| 10 |
+
transformers==4.46.3
|
| 11 |
+
wikipedia-api==0.7.1
|
| 12 |
+
duckduckgo-search==6.3.4
|
| 13 |
+
Pillow==10.4.0
|
| 14 |
+
openpyxl==3.1.5
|
| 15 |
+
pydub==0.25.1
|
| 16 |
+
speechrecognition==3.11.0
|
| 17 |
+
|
| 18 |
+
# OAuth dependencies for Gradio
|
| 19 |
+
itsdangerous>=2.0.0
|
| 20 |
+
gradio[oauth]
|