Update app.py
Browse files
app.py
CHANGED
|
@@ -234,15 +234,28 @@ class SmartAgent:
|
|
| 234 |
logging.info("SmartAgent resources cleaned up.")
|
| 235 |
|
| 236 |
# --- Main Function ---
|
| 237 |
-
def run_and_submit_all(
|
| 238 |
"""Run agent evaluation and submit results"""
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
|
| 244 |
-
|
| 245 |
-
logging.info(f"User logged in: {username}")
|
| 246 |
|
| 247 |
api_url = DEFAULT_API_URL
|
| 248 |
space_id = os.getenv("SPACE_ID")
|
|
@@ -381,10 +394,9 @@ with gr.Blocks() as demo:
|
|
| 381 |
|
| 382 |
run_button.click(
|
| 383 |
fn=run_and_submit_all,
|
| 384 |
-
inputs=[gr.LoginButton()],
|
| 385 |
outputs=[status_output, results_table],
|
| 386 |
show_progress=True,
|
| 387 |
)
|
| 388 |
|
| 389 |
if __name__ == "__main__":
|
| 390 |
-
demo.launch(debug=True, share=False)
|
|
|
|
| 234 |
logging.info("SmartAgent resources cleaned up.")
|
| 235 |
|
| 236 |
# --- Main Function ---
|
| 237 |
+
def run_and_submit_all(request: gr.Request):
|
| 238 |
"""Run agent evaluation and submit results"""
|
| 239 |
+
# Try to get username from request or fallback to space owner
|
| 240 |
+
username = None
|
| 241 |
+
|
| 242 |
+
# Check for oauth profile
|
| 243 |
+
if hasattr(request, 'oauth_profile') and request.oauth_profile:
|
| 244 |
+
username = request.oauth_profile.username
|
| 245 |
+
logging.info(f"Found username via oauth_profile: {username}")
|
| 246 |
+
|
| 247 |
+
# Fallback to space owner
|
| 248 |
+
if not username:
|
| 249 |
+
space_id = os.getenv("SPACE_ID", "")
|
| 250 |
+
if "/" in space_id:
|
| 251 |
+
username = space_id.split("/")[0]
|
| 252 |
+
logging.info(f"Using fallback username from SPACE_ID: {username}")
|
| 253 |
+
else:
|
| 254 |
+
logging.info("No authentication detected.")
|
| 255 |
+
yield "❌ Unable to detect logged-in user. Please make sure you're logged in to Hugging Face.", pd.DataFrame([])
|
| 256 |
+
return
|
| 257 |
|
| 258 |
+
logging.info(f"Processing with username: {username}")
|
|
|
|
| 259 |
|
| 260 |
api_url = DEFAULT_API_URL
|
| 261 |
space_id = os.getenv("SPACE_ID")
|
|
|
|
| 394 |
|
| 395 |
run_button.click(
|
| 396 |
fn=run_and_submit_all,
|
|
|
|
| 397 |
outputs=[status_output, results_table],
|
| 398 |
show_progress=True,
|
| 399 |
)
|
| 400 |
|
| 401 |
if __name__ == "__main__":
|
| 402 |
+
demo.launch(debug=True, share=False)
|