Spaces:
Sleeping
Sleeping
Chris
commited on
Commit
Β·
f798fcd
1
Parent(s):
fc0aaf2
Final 6.4.3
Browse files- src/app.py +71 -2
src/app.py
CHANGED
|
@@ -1429,8 +1429,77 @@ Please log in to access GAIA evaluation features with full inference access.
|
|
| 1429 |
# Event handlers for Unit 4 API
|
| 1430 |
def handle_evaluation_results(request: gr.Request):
|
| 1431 |
"""Handle evaluation and update download visibility"""
|
| 1432 |
-
#
|
| 1433 |
-
profile =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1434 |
|
| 1435 |
results = run_and_submit_all(profile)
|
| 1436 |
status, table, auth_status, csv_file, json_file, summary_file = results
|
|
|
|
| 1429 |
# Event handlers for Unit 4 API
|
| 1430 |
def handle_evaluation_results(request: gr.Request):
|
| 1431 |
"""Handle evaluation and update download visibility"""
|
| 1432 |
+
# Use the same OAuth profile extraction logic that works in other functions
|
| 1433 |
+
profile = None
|
| 1434 |
+
oauth_token = None
|
| 1435 |
+
username = None
|
| 1436 |
+
|
| 1437 |
+
try:
|
| 1438 |
+
# Try to get OAuth info from request using multiple methods
|
| 1439 |
+
if hasattr(request, 'user') and request.user:
|
| 1440 |
+
username = getattr(request.user, 'username', None)
|
| 1441 |
+
if username:
|
| 1442 |
+
# Create a profile-like object if we have user info
|
| 1443 |
+
class GradioProfile:
|
| 1444 |
+
def __init__(self, username):
|
| 1445 |
+
self.username = username
|
| 1446 |
+
self.oauth_token = None
|
| 1447 |
+
profile = GradioProfile(username)
|
| 1448 |
+
logger.info(f"π Found user via request.user: {username}")
|
| 1449 |
+
|
| 1450 |
+
# Try additional Gradio OAuth attributes
|
| 1451 |
+
if not profile:
|
| 1452 |
+
# Check for standard Gradio OAuth profile
|
| 1453 |
+
for attr in ['oauth_profile', 'profile', 'user_profile']:
|
| 1454 |
+
if hasattr(request, attr):
|
| 1455 |
+
oauth_profile = getattr(request, attr)
|
| 1456 |
+
logger.info(f"π DEBUG: Found request.{attr} = {type(oauth_profile)}")
|
| 1457 |
+
if oauth_profile and hasattr(oauth_profile, 'username'):
|
| 1458 |
+
profile = oauth_profile
|
| 1459 |
+
username = oauth_profile.username
|
| 1460 |
+
logger.info(f"π Found profile via request.{attr}: {username}")
|
| 1461 |
+
break
|
| 1462 |
+
|
| 1463 |
+
# Alternative: Check session or headers for OAuth token
|
| 1464 |
+
if hasattr(request, 'session'):
|
| 1465 |
+
session = request.session
|
| 1466 |
+
logger.info(f"π DEBUG: Session available, keys: {list(session.keys()) if hasattr(session, 'keys') else 'no keys method'}")
|
| 1467 |
+
oauth_token = session.get('oauth_token') or session.get('access_token')
|
| 1468 |
+
if oauth_token:
|
| 1469 |
+
logger.info("π Found OAuth token in session")
|
| 1470 |
+
|
| 1471 |
+
# Check request headers for authorization
|
| 1472 |
+
if hasattr(request, 'headers'):
|
| 1473 |
+
auth_header = request.headers.get('authorization', '')
|
| 1474 |
+
logger.info(f"π DEBUG: Authorization header present: {bool(auth_header)}")
|
| 1475 |
+
if auth_header.startswith('Bearer '):
|
| 1476 |
+
oauth_token = auth_header[7:]
|
| 1477 |
+
logger.info("π Found OAuth token in headers")
|
| 1478 |
+
|
| 1479 |
+
# Try to extract token from profile if we have one
|
| 1480 |
+
if profile and not oauth_token:
|
| 1481 |
+
profile_attrs = [attr for attr in dir(profile) if not attr.startswith('_')]
|
| 1482 |
+
logger.info(f"π DEBUG: Profile attributes: {profile_attrs}")
|
| 1483 |
+
for token_attr in ['oauth_token', 'token', 'access_token', 'id_token', 'bearer_token']:
|
| 1484 |
+
if hasattr(profile, token_attr):
|
| 1485 |
+
token = getattr(profile, token_attr)
|
| 1486 |
+
if token:
|
| 1487 |
+
oauth_token = token
|
| 1488 |
+
logger.info(f"π Found OAuth token via profile.{token_attr}")
|
| 1489 |
+
break
|
| 1490 |
+
|
| 1491 |
+
# If we found a token, add it to the profile
|
| 1492 |
+
if oauth_token and profile:
|
| 1493 |
+
profile.oauth_token = oauth_token
|
| 1494 |
+
logger.info(f"β
OAuth profile created: user={username}, token=present")
|
| 1495 |
+
elif profile and not oauth_token:
|
| 1496 |
+
logger.info(f"β
OAuth profile created: user={username}, token=missing")
|
| 1497 |
+
elif not profile and not oauth_token:
|
| 1498 |
+
logger.warning("β οΈ No OAuth profile or token found in request")
|
| 1499 |
+
|
| 1500 |
+
except Exception as e:
|
| 1501 |
+
logger.error(f"β Error extracting OAuth profile: {e}")
|
| 1502 |
+
profile = None
|
| 1503 |
|
| 1504 |
results = run_and_submit_all(profile)
|
| 1505 |
status, table, auth_status, csv_file, json_file, summary_file = results
|