Spaces:
Sleeping
Sleeping
Add debug logging for request object
Browse files- src/mosaic/analysis.py +17 -1
src/mosaic/analysis.py
CHANGED
|
@@ -469,20 +469,36 @@ def analyze_slide(
|
|
| 469 |
username = "anonymous"
|
| 470 |
if request is not None:
|
| 471 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 472 |
# Check if user is logged in
|
| 473 |
# In HF Spaces, request.username is None for anonymous users
|
| 474 |
if hasattr(request, 'username') and request.username:
|
| 475 |
username = request.username
|
| 476 |
is_logged_in = True
|
|
|
|
|
|
|
|
|
|
|
|
|
| 477 |
# Also check request headers for auth
|
| 478 |
-
|
|
|
|
| 479 |
auth_header = request.headers.get('authorization', '')
|
| 480 |
if auth_header and 'Bearer' in auth_header:
|
| 481 |
is_logged_in = True
|
| 482 |
username = "logged-in"
|
|
|
|
|
|
|
|
|
|
| 483 |
logger.info(f"User: {username} | Logged in: {is_logged_in}")
|
| 484 |
except Exception as e:
|
| 485 |
logger.warning(f"Failed to detect user: {e}")
|
|
|
|
|
|
|
| 486 |
|
| 487 |
if is_logged_in:
|
| 488 |
logger.info("Using 300s GPU allocation (logged-in user)")
|
|
|
|
| 469 |
username = "anonymous"
|
| 470 |
if request is not None:
|
| 471 |
try:
|
| 472 |
+
# Debug: Log all request attributes
|
| 473 |
+
logger.info(f"Request object type: {type(request)}")
|
| 474 |
+
logger.info(f"Request attributes: {dir(request)}")
|
| 475 |
+
if hasattr(request, '__dict__'):
|
| 476 |
+
logger.info(f"Request dict: {request.__dict__}")
|
| 477 |
+
|
| 478 |
# Check if user is logged in
|
| 479 |
# In HF Spaces, request.username is None for anonymous users
|
| 480 |
if hasattr(request, 'username') and request.username:
|
| 481 |
username = request.username
|
| 482 |
is_logged_in = True
|
| 483 |
+
logger.info(f"Found username: {username}")
|
| 484 |
+
else:
|
| 485 |
+
logger.info(f"No username found. request.username = {getattr(request, 'username', 'ATTR_NOT_FOUND')}")
|
| 486 |
+
|
| 487 |
# Also check request headers for auth
|
| 488 |
+
if hasattr(request, 'headers'):
|
| 489 |
+
logger.info(f"Headers: {dict(request.headers)}")
|
| 490 |
auth_header = request.headers.get('authorization', '')
|
| 491 |
if auth_header and 'Bearer' in auth_header:
|
| 492 |
is_logged_in = True
|
| 493 |
username = "logged-in"
|
| 494 |
+
else:
|
| 495 |
+
logger.info("No headers attribute found")
|
| 496 |
+
|
| 497 |
logger.info(f"User: {username} | Logged in: {is_logged_in}")
|
| 498 |
except Exception as e:
|
| 499 |
logger.warning(f"Failed to detect user: {e}")
|
| 500 |
+
import traceback
|
| 501 |
+
logger.warning(traceback.format_exc())
|
| 502 |
|
| 503 |
if is_logged_in:
|
| 504 |
logger.info("Using 300s GPU allocation (logged-in user)")
|