Quazim0t0's picture
Update app.py
c73c631 verified
raw
history blame
6.22 kB
"""
Main application for Dynamic Highscores system.
This file integrates all components into a unified application.
"""
import os
import gradio as gr
import threading
import time
from database_schema import DynamicHighscoresDB
from auth import HuggingFaceAuth, create_login_ui, setup_auth_handlers
from benchmark_selection import BenchmarkSelector, create_benchmark_selection_ui
from evaluation_queue import EvaluationQueue, create_model_submission_ui
from leaderboard import Leaderboard, create_leaderboard_ui
from sample_benchmarks import add_sample_benchmarks
# Initialize components in main thread
db = DynamicHighscoresDB()
auth_manager = HuggingFaceAuth(db)
benchmark_selector = BenchmarkSelector(db, auth_manager)
evaluation_queue = EvaluationQueue(db, auth_manager)
leaderboard = Leaderboard(db)
# Initialize sample benchmarks if none exist
print("Checking for existing benchmarks...")
benchmarks = db.get_benchmarks()
if not benchmarks or len(benchmarks) == 0:
print("No benchmarks found. Adding sample benchmarks...")
try:
# Make sure the database path is clear
print(f"Database path: {db.db_path}")
# Import and call the function directly
num_added = add_sample_benchmarks()
print(f"Added {num_added} sample benchmarks.")
except Exception as e:
print(f"Error adding sample benchmarks: {str(e)}")
# Try direct DB insertion as fallback
try:
print("Attempting direct benchmark insertion...")
db.add_benchmark(
name="MMLU (Massive Multitask Language Understanding)",
dataset_id="cais/mmlu",
description="Tests knowledge across 57 subjects"
)
print("Added fallback benchmark.")
except Exception as inner_e:
print(f"Fallback insertion failed: {str(inner_e)}")
else:
print(f"Found {len(benchmarks)} existing benchmarks.")
# Custom CSS with better theme compatibility
css = """
/* Theme-adaptive colored info box */
.info-text {
background-color: rgba(53, 130, 220, 0.1);
padding: 12px;
border-radius: 8px;
border-left: 4px solid #3498db;
margin: 12px 0;
}
/* High-contrast text for elements - works in light and dark themes */
.info-text, .header, .footer, .tab-content,
button, input, textarea, select, option,
.gradio-container *, .markdown-text {
color: var(--text-color, inherit) !important;
}
/* Container styling */
.container {
max-width: 1200px;
margin: 0 auto;
}
/* Header styling */
.header {
text-align: center;
margin-bottom: 20px;
font-weight: bold;
font-size: 24px;
}
/* Footer styling */
.footer {
text-align: center;
margin-top: 40px;
padding: 20px;
border-top: 1px solid var(--border-color-primary, #eee);
}
/* Force high contrast on specific input areas */
input[type="text"], input[type="password"], textarea {
background-color: var(--background-fill-primary) !important;
color: var(--body-text-color) !important;
}
/* Force text visibility in multiple contexts */
.gradio-markdown p, .gradio-markdown h1, .gradio-markdown h2,
.gradio-markdown h3, .gradio-markdown h4, .gradio-markdown li {
color: var(--body-text-color) !important;
}
/* Make Textbox placeholders more visible */
::placeholder {
color: var(--body-text-color-subdued) !important;
opacity: 0.7 !important;
}
/* Make tab labels more visible */
.tab-nav button {
color: var(--body-text-color) !important;
}
/* Improve contrast in dataframes */
table.dataframe th, table.dataframe td {
color: var(--body-text-color) !important;
}
/* Ensure buttons have visible text */
button.primary {
color: white !important;
}
/* Force high contrast for dropdown/select options */
.select-option {
color: var(--body-text-color) !important;
}
/* Improve visibility in dark mode specifically */
@media (prefers-color-scheme: dark) {
.info-text {
background-color: rgba(53, 130, 220, 0.2);
}
}
"""
# Start evaluation queue worker
def start_queue_worker():
# Wait a moment to ensure app is initialized
time.sleep(2)
try:
print("Starting evaluation queue worker...")
evaluation_queue.start_worker()
except Exception as e:
print(f"Error starting queue worker: {e}")
# Create Gradio app
with gr.Blocks(css=css, title="Dynamic Highscores", theme=gr.themes.Default()) as app:
gr.Markdown("# ๐Ÿ† Dynamic Highscores", elem_classes=["header"])
gr.Markdown("""
Welcome to Dynamic Highscores - a community benchmark platform for evaluating and comparing language models.
- **Add your own benchmarks** from HuggingFace datasets
- **Submit your models** for CPU-only evaluation
- **Compare performance** across different models and benchmarks
- **Filter results** by model type (Merge, Agent, Reasoning, Coding, etc.)
""", elem_classes=["info-text"])
# Authentication UI
login_button, logout_button, token_input, user_info = create_login_ui()
setup_auth_handlers(login_button, logout_button, token_input, user_info, auth_manager)
# Main tabs
with gr.Tabs() as tabs:
with gr.TabItem("๐Ÿ“Š Leaderboard", id=0):
leaderboard_ui = create_leaderboard_ui(leaderboard, db)
with gr.TabItem("๐Ÿš€ Submit Model", id=1):
submission_ui = create_model_submission_ui(evaluation_queue, auth_manager, db)
with gr.TabItem("๐Ÿ” Benchmarks", id=2):
benchmark_ui = create_benchmark_selection_ui(benchmark_selector, auth_manager)
gr.Markdown("""
### About Dynamic Highscores
This platform allows users to select benchmarks from HuggingFace datasets and evaluate models against them.
Each user can submit one benchmark per day (admin users are exempt from this limit).
All evaluations run on CPU only to ensure fair comparisons.
Created by Quazim0t0
""", elem_classes=["footer"])
# Launch the app
if __name__ == "__main__":
# Start queue worker in a separate thread
queue_thread = threading.Thread(target=start_queue_worker)
queue_thread.daemon = True
queue_thread.start()
app.launch()