Spaces:
Running
Running
zhimin-z
commited on
Commit
·
2b30f34
1
Parent(s):
351e03f
refine
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ import os
|
|
| 11 |
import random
|
| 12 |
import re
|
| 13 |
import threading
|
|
|
|
| 14 |
|
| 15 |
import gradio as gr
|
| 16 |
import pandas as pd
|
|
@@ -650,24 +651,14 @@ def toggle_submit_button(text):
|
|
| 650 |
# Function to check initial authentication status
|
| 651 |
def check_auth_on_load(request: gr.Request):
|
| 652 |
"""Check if user is already authenticated when page loads."""
|
| 653 |
-
print(f"DEBUG: Checking auth on load")
|
| 654 |
-
print(f"DEBUG: Has username attr: {hasattr(request, 'username')}")
|
| 655 |
-
if hasattr(request, 'username'):
|
| 656 |
-
print(f"DEBUG: Username: {request.username}")
|
| 657 |
-
|
| 658 |
# Try to get token from environment (for Spaces) or HfApi (for local)
|
| 659 |
token = os.getenv("HF_TOKEN") or HfApi().token
|
| 660 |
|
| 661 |
# Check if user is authenticated via OAuth
|
| 662 |
is_authenticated = (hasattr(request, 'username') and request.username is not None and request.username != "")
|
| 663 |
|
| 664 |
-
print(f"DEBUG: Is authenticated: {is_authenticated}")
|
| 665 |
-
print(f"DEBUG: Token available: {token is not None}")
|
| 666 |
-
|
| 667 |
if is_authenticated or token:
|
| 668 |
# User is logged in OR we have a token available
|
| 669 |
-
username = request.username if hasattr(request, 'username') else "local_user"
|
| 670 |
-
print(f"DEBUG: Enabling interface for user: {username}")
|
| 671 |
return (
|
| 672 |
gr.update(interactive=True), # repo_url
|
| 673 |
gr.update(interactive=True), # shared_input
|
|
@@ -681,7 +672,6 @@ def check_auth_on_load(request: gr.Request):
|
|
| 681 |
)
|
| 682 |
else:
|
| 683 |
# User not logged in
|
| 684 |
-
print(f"DEBUG: User not authenticated, keeping interface disabled")
|
| 685 |
return (
|
| 686 |
gr.update(interactive=False), # repo_url
|
| 687 |
gr.update(interactive=False), # shared_input
|
|
@@ -696,6 +686,8 @@ def check_auth_on_load(request: gr.Request):
|
|
| 696 |
|
| 697 |
|
| 698 |
# Gradio Interface
|
|
|
|
|
|
|
| 699 |
with gr.Blocks(title="SWE-Model-Arena", theme=gr.themes.Soft()) as app:
|
| 700 |
user_authenticated = gr.State(False)
|
| 701 |
models_state = gr.State({})
|
|
@@ -1211,20 +1203,12 @@ with gr.Blocks(title="SWE-Model-Arena", theme=gr.themes.Soft()) as app:
|
|
| 1211 |
When deployed on HF Spaces with OAuth, request contains user info.
|
| 1212 |
This is also used by the refresh button to re-check auth status.
|
| 1213 |
"""
|
| 1214 |
-
print(f"DEBUG: handle_login called")
|
| 1215 |
-
print(f"DEBUG: Has username: {hasattr(request, 'username')}")
|
| 1216 |
-
if hasattr(request, 'username'):
|
| 1217 |
-
print(f"DEBUG: Username in handle_login: {request.username}")
|
| 1218 |
-
|
| 1219 |
# Try to get token from environment (for Spaces) or HfApi (for local)
|
| 1220 |
token = os.getenv("HF_TOKEN") or HfApi().token
|
| 1221 |
|
| 1222 |
# Check if user is authenticated through HF Spaces OAuth
|
| 1223 |
is_authenticated = hasattr(request, 'username') and request.username
|
| 1224 |
|
| 1225 |
-
print(f"DEBUG: Is authenticated in handle_login: {is_authenticated}")
|
| 1226 |
-
print(f"DEBUG: Token available in handle_login: {token is not None}")
|
| 1227 |
-
|
| 1228 |
if is_authenticated or token:
|
| 1229 |
# User is logged in
|
| 1230 |
return (
|
|
|
|
| 11 |
import random
|
| 12 |
import re
|
| 13 |
import threading
|
| 14 |
+
import warnings
|
| 15 |
|
| 16 |
import gradio as gr
|
| 17 |
import pandas as pd
|
|
|
|
| 651 |
# Function to check initial authentication status
|
| 652 |
def check_auth_on_load(request: gr.Request):
|
| 653 |
"""Check if user is already authenticated when page loads."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 654 |
# Try to get token from environment (for Spaces) or HfApi (for local)
|
| 655 |
token = os.getenv("HF_TOKEN") or HfApi().token
|
| 656 |
|
| 657 |
# Check if user is authenticated via OAuth
|
| 658 |
is_authenticated = (hasattr(request, 'username') and request.username is not None and request.username != "")
|
| 659 |
|
|
|
|
|
|
|
|
|
|
| 660 |
if is_authenticated or token:
|
| 661 |
# User is logged in OR we have a token available
|
|
|
|
|
|
|
| 662 |
return (
|
| 663 |
gr.update(interactive=True), # repo_url
|
| 664 |
gr.update(interactive=True), # shared_input
|
|
|
|
| 672 |
)
|
| 673 |
else:
|
| 674 |
# User not logged in
|
|
|
|
| 675 |
return (
|
| 676 |
gr.update(interactive=False), # repo_url
|
| 677 |
gr.update(interactive=False), # shared_input
|
|
|
|
| 686 |
|
| 687 |
|
| 688 |
# Gradio Interface
|
| 689 |
+
# Suppress the deprecation warning for theme parameter until Gradio 6.0 is released
|
| 690 |
+
warnings.filterwarnings('ignore', category=DeprecationWarning, message=".*'theme' parameter.*")
|
| 691 |
with gr.Blocks(title="SWE-Model-Arena", theme=gr.themes.Soft()) as app:
|
| 692 |
user_authenticated = gr.State(False)
|
| 693 |
models_state = gr.State({})
|
|
|
|
| 1203 |
When deployed on HF Spaces with OAuth, request contains user info.
|
| 1204 |
This is also used by the refresh button to re-check auth status.
|
| 1205 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1206 |
# Try to get token from environment (for Spaces) or HfApi (for local)
|
| 1207 |
token = os.getenv("HF_TOKEN") or HfApi().token
|
| 1208 |
|
| 1209 |
# Check if user is authenticated through HF Spaces OAuth
|
| 1210 |
is_authenticated = hasattr(request, 'username') and request.username
|
| 1211 |
|
|
|
|
|
|
|
|
|
|
| 1212 |
if is_authenticated or token:
|
| 1213 |
# User is logged in
|
| 1214 |
return (
|