Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,7 +50,7 @@ if not benchmarks or len(benchmarks) == 0:
|
|
| 50 |
else:
|
| 51 |
print(f"Found {len(benchmarks)} existing benchmarks.")
|
| 52 |
|
| 53 |
-
# Custom CSS with
|
| 54 |
css = """
|
| 55 |
/* Theme-adaptive colored info box */
|
| 56 |
.info-text {
|
|
@@ -102,40 +102,22 @@ input[type="text"], input[type="password"], textarea {
|
|
| 102 |
color: var(--body-text-color) !important;
|
| 103 |
}
|
| 104 |
|
| 105 |
-
/*
|
| 106 |
-
::placeholder {
|
| 107 |
-
color: var(--body-text-color-subdued) !important;
|
| 108 |
-
opacity: 0.7 !important;
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
/* Make tab labels more visible */
|
| 112 |
-
.tab-nav button {
|
| 113 |
-
color: var(--body-text-color) !important;
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
/* Improve contrast in dataframes */
|
| 117 |
-
table.dataframe th, table.dataframe td {
|
| 118 |
-
color: var(--body-text-color) !important;
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
/* Ensure buttons have visible text */
|
| 122 |
-
button.primary {
|
| 123 |
-
color: white !important;
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
/* Force high contrast for dropdown/select options */
|
| 127 |
-
.select-option {
|
| 128 |
-
color: var(--body-text-color) !important;
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
/* Improve visibility in dark mode specifically */
|
| 132 |
@media (prefers-color-scheme: dark) {
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
}
|
| 136 |
}
|
| 137 |
"""
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
# Start evaluation queue worker
|
| 140 |
def start_queue_worker():
|
| 141 |
# Wait a moment to ensure app is initialized
|
|
@@ -147,7 +129,32 @@ def start_queue_worker():
|
|
| 147 |
print(f"Error starting queue worker: {e}")
|
| 148 |
|
| 149 |
# Create Gradio app
|
| 150 |
-
with gr.Blocks(css=css, title="Dynamic Highscores", theme=gr.themes.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
gr.Markdown("# 🏆 Dynamic Highscores", elem_classes=["header"])
|
| 152 |
gr.Markdown("""
|
| 153 |
Welcome to Dynamic Highscores - a community benchmark platform for evaluating and comparing language models.
|
|
@@ -159,8 +166,8 @@ with gr.Blocks(css=css, title="Dynamic Highscores", theme=gr.themes.Default()) a
|
|
| 159 |
""", elem_classes=["info-text"])
|
| 160 |
|
| 161 |
# Authentication UI
|
| 162 |
-
login_button, logout_button,
|
| 163 |
-
setup_auth_handlers(login_button, logout_button,
|
| 164 |
|
| 165 |
# Main tabs
|
| 166 |
with gr.Tabs() as tabs:
|
|
@@ -182,6 +189,13 @@ with gr.Blocks(css=css, title="Dynamic Highscores", theme=gr.themes.Default()) a
|
|
| 182 |
|
| 183 |
Created by Quazim0t0
|
| 184 |
""", elem_classes=["footer"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
# Launch the app
|
| 187 |
if __name__ == "__main__":
|
|
|
|
| 50 |
else:
|
| 51 |
print(f"Found {len(benchmarks)} existing benchmarks.")
|
| 52 |
|
| 53 |
+
# Custom CSS with theme awareness
|
| 54 |
css = """
|
| 55 |
/* Theme-adaptive colored info box */
|
| 56 |
.info-text {
|
|
|
|
| 102 |
color: var(--body-text-color) !important;
|
| 103 |
}
|
| 104 |
|
| 105 |
+
/* Fix dark mode text visibility */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
@media (prefers-color-scheme: dark) {
|
| 107 |
+
input, textarea, select {
|
| 108 |
+
color: #ffffff !important;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
::placeholder {
|
| 112 |
+
color: rgba(255, 255, 255, 0.5) !important;
|
| 113 |
}
|
| 114 |
}
|
| 115 |
"""
|
| 116 |
|
| 117 |
+
# Check if the server is running in a HuggingFace Space
|
| 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
|
|
|
|
| 129 |
print(f"Error starting queue worker: {e}")
|
| 130 |
|
| 131 |
# Create Gradio app
|
| 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 |
+
# Auth status check on page load
|
| 136 |
+
def check_auth_on_load(request: gr.Request):
|
| 137 |
+
# Check if running in HF Space with OAuth
|
| 138 |
+
if is_running_in_hf_space():
|
| 139 |
+
username = request.headers.get("HF-User")
|
| 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("""
|
| 160 |
Welcome to Dynamic Highscores - a community benchmark platform for evaluating and comparing language models.
|
|
|
|
| 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:
|
|
|
|
| 189 |
|
| 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, user_info]
|
| 198 |
+
)
|
| 199 |
|
| 200 |
# Launch the app
|
| 201 |
if __name__ == "__main__":
|