Spaces:
Sleeping
Sleeping
Fix local authentication bypass for development and testing
Browse files- Remove auth requirement when running locally (no SPACE_HOST)
- Add HF_USERNAME environment variable support for local testing
- Conditionally show login button only in HF Spaces environment
- Default to "local_user" for testing without breaking functionality
- Enable full GAIA evaluation testing locally without HF OAuth issues
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -241,7 +241,7 @@ class BasicAgent:
|
|
| 241 |
print(f"Error: {e}")
|
| 242 |
return "Error processing question"
|
| 243 |
|
| 244 |
-
def run_and_submit_all(
|
| 245 |
"""
|
| 246 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 247 |
and displays the results.
|
|
@@ -249,12 +249,17 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 249 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
| 250 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
| 251 |
|
|
|
|
| 252 |
if profile:
|
| 253 |
-
username= f"{profile.username}"
|
| 254 |
print(f"User logged in: {username}")
|
| 255 |
else:
|
| 256 |
-
|
| 257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
|
| 259 |
api_url = DEFAULT_API_URL
|
| 260 |
questions_url = f"{api_url}/questions"
|
|
@@ -267,7 +272,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 267 |
print(f"Error instantiating agent: {e}")
|
| 268 |
return f"Error initializing agent: {e}", None
|
| 269 |
# In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
|
| 270 |
-
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 271 |
print(agent_code)
|
| 272 |
|
| 273 |
# 2. Fetch Questions
|
|
@@ -417,14 +422,20 @@ with gr.Blocks() as demo:
|
|
| 417 |
gr.Markdown(
|
| 418 |
"""
|
| 419 |
**Instructions:**
|
| 420 |
-
1. Log in to your
|
| 421 |
-
2.
|
|
|
|
| 422 |
|
| 423 |
**Note:** This can take several minutes as the agent processes all questions.
|
| 424 |
"""
|
| 425 |
)
|
| 426 |
|
| 427 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 428 |
|
| 429 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
| 430 |
|
|
|
|
| 241 |
print(f"Error: {e}")
|
| 242 |
return "Error processing question"
|
| 243 |
|
| 244 |
+
def run_and_submit_all(profile: gr.OAuthProfile | None = None):
|
| 245 |
"""
|
| 246 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 247 |
and displays the results.
|
|
|
|
| 249 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
| 250 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
| 251 |
|
| 252 |
+
# Handle both authenticated and local testing scenarios
|
| 253 |
if profile:
|
| 254 |
+
username = f"{profile.username}"
|
| 255 |
print(f"User logged in: {username}")
|
| 256 |
else:
|
| 257 |
+
# For local testing, use a default username or environment variable
|
| 258 |
+
username = os.getenv("HF_USERNAME", "local_user")
|
| 259 |
+
if username == "local_user":
|
| 260 |
+
print("Running in local mode - no authentication required")
|
| 261 |
+
else:
|
| 262 |
+
print(f"Using HF_USERNAME from environment: {username}")
|
| 263 |
|
| 264 |
api_url = DEFAULT_API_URL
|
| 265 |
questions_url = f"{api_url}/questions"
|
|
|
|
| 272 |
print(f"Error instantiating agent: {e}")
|
| 273 |
return f"Error initializing agent: {e}", None
|
| 274 |
# In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
|
| 275 |
+
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main" if space_id else "local_testing"
|
| 276 |
print(agent_code)
|
| 277 |
|
| 278 |
# 2. Fetch Questions
|
|
|
|
| 422 |
gr.Markdown(
|
| 423 |
"""
|
| 424 |
**Instructions:**
|
| 425 |
+
1. **In Hugging Face Spaces**: Log in to your HF account using the button below
|
| 426 |
+
2. **Local Testing**: Set HF_USERNAME environment variable (optional) or use default "local_user"
|
| 427 |
+
3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score
|
| 428 |
|
| 429 |
**Note:** This can take several minutes as the agent processes all questions.
|
| 430 |
"""
|
| 431 |
)
|
| 432 |
|
| 433 |
+
# Only show login button if we're likely in a Space environment
|
| 434 |
+
space_host = os.getenv("SPACE_HOST")
|
| 435 |
+
if space_host:
|
| 436 |
+
gr.LoginButton()
|
| 437 |
+
else:
|
| 438 |
+
gr.Markdown("🔧 **Local Mode**: No login required. Set `HF_USERNAME` environment variable to use your username.")
|
| 439 |
|
| 440 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
| 441 |
|