Update app.py
Browse files
app.py
CHANGED
@@ -90,6 +90,22 @@ button, input, textarea, select, option,
|
|
90 |
border-top: 1px solid var(--border-color-primary, #eee);
|
91 |
}
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
/* Force high contrast on specific input areas */
|
94 |
input[type="text"], input[type="password"], textarea {
|
95 |
background-color: var(--background-fill-primary) !important;
|
@@ -118,6 +134,15 @@ input[type="text"], input[type="password"], textarea {
|
|
118 |
def is_running_in_hf_space():
|
119 |
return 'SPACE_ID' in os.environ
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
# Start evaluation queue worker
|
122 |
def start_queue_worker():
|
123 |
# Wait a moment to ensure app is initialized
|
@@ -132,28 +157,11 @@ def start_queue_worker():
|
|
132 |
with gr.Blocks(css=css, title="Dynamic Highscores", theme=gr.themes.Soft()) as app:
|
133 |
auth_status = gr.State(None) # Store user auth state
|
134 |
|
135 |
-
#
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
if username:
|
141 |
-
print(f"Detected logged-in user via Space OAuth: {username}")
|
142 |
-
# Get or create user
|
143 |
-
user = db.get_user_by_username(username)
|
144 |
-
if not user:
|
145 |
-
print(f"Creating new user: {username}")
|
146 |
-
is_admin = (username == "Quazim0t0") # Replace with your admin username
|
147 |
-
db.add_user(username, username, is_admin)
|
148 |
-
user = db.get_user_by_username(username)
|
149 |
-
return user, f"Logged in as {username}"
|
150 |
-
else:
|
151 |
-
# Fallback to cookie-based auth for local development
|
152 |
-
user = auth_manager.check_login(request)
|
153 |
-
if user:
|
154 |
-
return user, f"Logged in as {user['username']}"
|
155 |
-
|
156 |
-
return None, "Not logged in"
|
157 |
|
158 |
gr.Markdown("# π Dynamic Highscores", elem_classes=["header"])
|
159 |
gr.Markdown("""
|
@@ -165,10 +173,6 @@ with gr.Blocks(css=css, title="Dynamic Highscores", theme=gr.themes.Soft()) as a
|
|
165 |
- **Filter results** by model type (Merge, Agent, Reasoning, Coding, etc.)
|
166 |
""", elem_classes=["info-text"])
|
167 |
|
168 |
-
# Authentication UI
|
169 |
-
login_button, logout_button, user_info = create_login_ui()
|
170 |
-
setup_auth_handlers(login_button, logout_button, user_info, auth_manager)
|
171 |
-
|
172 |
# Main tabs
|
173 |
with gr.Tabs() as tabs:
|
174 |
with gr.TabItem("π Leaderboard", id=0):
|
@@ -190,11 +194,39 @@ with gr.Blocks(css=css, title="Dynamic Highscores", theme=gr.themes.Soft()) as a
|
|
190 |
Created by Quazim0t0
|
191 |
""", elem_classes=["footer"])
|
192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
# Check auth on load
|
194 |
app.load(
|
195 |
fn=check_auth_on_load,
|
196 |
inputs=[],
|
197 |
-
outputs=[auth_status,
|
198 |
)
|
199 |
|
200 |
# Launch the app
|
|
|
90 |
border-top: 1px solid var(--border-color-primary, #eee);
|
91 |
}
|
92 |
|
93 |
+
/* Login section styling */
|
94 |
+
.login-section {
|
95 |
+
padding: 10px;
|
96 |
+
margin-bottom: 15px;
|
97 |
+
border-radius: 8px;
|
98 |
+
background-color: rgba(250, 250, 250, 0.1);
|
99 |
+
text-align: center;
|
100 |
+
}
|
101 |
+
|
102 |
+
/* Login button styling */
|
103 |
+
.login-button {
|
104 |
+
background-color: #4CAF50 !important;
|
105 |
+
color: white !important;
|
106 |
+
font-weight: bold;
|
107 |
+
}
|
108 |
+
|
109 |
/* Force high contrast on specific input areas */
|
110 |
input[type="text"], input[type="password"], textarea {
|
111 |
background-color: var(--background-fill-primary) !important;
|
|
|
134 |
def is_running_in_hf_space():
|
135 |
return 'SPACE_ID' in os.environ
|
136 |
|
137 |
+
# Function to trigger HuggingFace OAuth login
|
138 |
+
def trigger_hf_oauth():
|
139 |
+
return """
|
140 |
+
<script>
|
141 |
+
// Redirect to HuggingFace Space login
|
142 |
+
window.location.href = window.location.origin + "?__auth_callback=true";
|
143 |
+
</script>
|
144 |
+
"""
|
145 |
+
|
146 |
# Start evaluation queue worker
|
147 |
def start_queue_worker():
|
148 |
# Wait a moment to ensure app is initialized
|
|
|
157 |
with gr.Blocks(css=css, title="Dynamic Highscores", theme=gr.themes.Soft()) as app:
|
158 |
auth_status = gr.State(None) # Store user auth state
|
159 |
|
160 |
+
# Add a prominent login section at the top
|
161 |
+
with gr.Row(visible=True, elem_classes=["login-section"]) as login_section:
|
162 |
+
with gr.Column():
|
163 |
+
login_status = gr.Markdown("### π Not logged in", elem_id="login-status")
|
164 |
+
login_button = gr.Button("Login with HuggingFace", size="lg", variant="primary", elem_classes=["login-button"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
gr.Markdown("# π Dynamic Highscores", elem_classes=["header"])
|
167 |
gr.Markdown("""
|
|
|
173 |
- **Filter results** by model type (Merge, Agent, Reasoning, Coding, etc.)
|
174 |
""", elem_classes=["info-text"])
|
175 |
|
|
|
|
|
|
|
|
|
176 |
# Main tabs
|
177 |
with gr.Tabs() as tabs:
|
178 |
with gr.TabItem("π Leaderboard", id=0):
|
|
|
194 |
Created by Quazim0t0
|
195 |
""", elem_classes=["footer"])
|
196 |
|
197 |
+
# Auth status check on page load
|
198 |
+
def check_auth_on_load(request: gr.Request):
|
199 |
+
# Check if running in HF Space with OAuth
|
200 |
+
if is_running_in_hf_space():
|
201 |
+
username = request.headers.get("HF-User")
|
202 |
+
if username:
|
203 |
+
print(f"Detected logged-in user via Space OAuth: {username}")
|
204 |
+
# Get or create user
|
205 |
+
user = db.get_user_by_username(username)
|
206 |
+
if not user:
|
207 |
+
print(f"Creating new user: {username}")
|
208 |
+
is_admin = (username == "Quazim0t0") # Replace with your admin username
|
209 |
+
db.add_user(username, username, is_admin)
|
210 |
+
user = db.get_user_by_username(username)
|
211 |
+
|
212 |
+
# Update UI for logged in state
|
213 |
+
return user, f"### β
Logged in as {username}", gr.update(visible=False)
|
214 |
+
|
215 |
+
# Not logged in - make sure login section is visible
|
216 |
+
return None, "### π Not logged in", gr.update(visible=True)
|
217 |
+
|
218 |
+
# Connect event handlers
|
219 |
+
login_button.click(
|
220 |
+
fn=trigger_hf_oauth,
|
221 |
+
inputs=[],
|
222 |
+
outputs=[gr.HTML()]
|
223 |
+
)
|
224 |
+
|
225 |
# Check auth on load
|
226 |
app.load(
|
227 |
fn=check_auth_on_load,
|
228 |
inputs=[],
|
229 |
+
outputs=[auth_status, login_status, login_section]
|
230 |
)
|
231 |
|
232 |
# Launch the app
|