Quazim0t0 commited on
Commit
6e3ef2c
·
verified ·
1 Parent(s): a76fbde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -173
app.py CHANGED
@@ -1,6 +1,5 @@
1
  """
2
  Main application for Dynamic Highscores system.
3
-
4
  This file integrates all components into a unified application.
5
  """
6
 
@@ -14,7 +13,7 @@ from benchmark_selection import BenchmarkSelector, create_benchmark_selection_ui
14
  from evaluation_queue import EvaluationQueue, create_model_submission_ui
15
  from leaderboard import Leaderboard, create_leaderboard_ui
16
  from sample_benchmarks import add_sample_benchmarks
17
- os.environ["OAUTH_SCOPES"] = "inference"
18
  # Initialize components in main thread
19
  db = DynamicHighscoresDB()
20
  auth_manager = HuggingFaceAuth(db)
@@ -28,31 +27,13 @@ benchmarks = db.get_benchmarks()
28
  if not benchmarks or len(benchmarks) == 0:
29
  print("No benchmarks found. Adding sample benchmarks...")
30
  try:
31
- # Make sure the database path is clear
32
- print(f"Database path: {db.db_path}")
33
-
34
- # Import and call the function directly
35
  num_added = add_sample_benchmarks()
36
  print(f"Added {num_added} sample benchmarks.")
37
  except Exception as e:
38
  print(f"Error adding sample benchmarks: {str(e)}")
39
- # Try direct DB insertion as fallback
40
- try:
41
- print("Attempting direct benchmark insertion...")
42
- db.add_benchmark(
43
- name="MMLU (Massive Multitask Language Understanding)",
44
- dataset_id="cais/mmlu",
45
- description="Tests knowledge across 57 subjects"
46
- )
47
- print("Added fallback benchmark.")
48
- except Exception as inner_e:
49
- print(f"Fallback insertion failed: {str(inner_e)}")
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 {
57
  background-color: rgba(53, 130, 220, 0.1);
58
  padding: 12px;
@@ -60,110 +41,10 @@ css = """
60
  border-left: 4px solid #3498db;
61
  margin: 12px 0;
62
  }
63
-
64
- /* High-contrast text for elements - works in light and dark themes */
65
- .info-text, .header, .footer, .tab-content,
66
- button, input, textarea, select, option,
67
- .gradio-container *, .markdown-text {
68
- color: var(--text-color, inherit) !important;
69
- }
70
-
71
- /* Container styling */
72
- .container {
73
- max-width: 1200px;
74
- margin: 0 auto;
75
- }
76
-
77
- /* Header styling */
78
- .header {
79
- text-align: center;
80
- margin-bottom: 20px;
81
- font-weight: bold;
82
- font-size: 24px;
83
- }
84
-
85
- /* Footer styling */
86
- .footer {
87
- text-align: center;
88
- margin-top: 40px;
89
- padding: 20px;
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;
112
- color: var(--body-text-color) !important;
113
- }
114
-
115
- /* Force text visibility in multiple contexts */
116
- .gradio-markdown p, .gradio-markdown h1, .gradio-markdown h2,
117
- .gradio-markdown h3, .gradio-markdown h4, .gradio-markdown li {
118
- color: var(--body-text-color) !important;
119
- }
120
-
121
- /* Fix dark mode text visibility */
122
- @media (prefers-color-scheme: dark) {
123
- input, textarea, select {
124
- color: #ffffff !important;
125
- }
126
-
127
- ::placeholder {
128
- color: rgba(255, 255, 255, 0.5) !important;
129
- }
130
- }
131
  """
132
 
133
- # Check if the server is running in a HuggingFace Space
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
149
- time.sleep(2)
150
- try:
151
- print("Starting evaluation queue worker...")
152
- evaluation_queue.start_worker()
153
- except Exception as e:
154
- print(f"Error starting queue worker: {e}")
155
-
156
- # Create Gradio app
157
- with gr.Blocks(css=css, title="Dynamic Highscores", theme=gr.themes.Soft()) as app:
158
- gr.LoginButton(min_width=250, size="lg", variant="primary")
159
- auth_status = gr.State(None) # Store user auth state
160
-
161
- # Add a prominent login section at the top
162
- with gr.Row(visible=True, elem_classes=["login-section"]) as login_section:
163
- with gr.Column():
164
- login_status = gr.Markdown("### 🔒 Not logged in", elem_id="login-status")
165
- login_button = gr.Button("Login with HuggingFace", size="lg", variant="primary", elem_classes=["login-button"])
166
-
167
  gr.Markdown("# 🏆 Dynamic Highscores", elem_classes=["header"])
168
  gr.Markdown("""
169
  Welcome to Dynamic Highscores - a community benchmark platform for evaluating and comparing language models.
@@ -184,57 +65,7 @@ with gr.Blocks(css=css, title="Dynamic Highscores", theme=gr.themes.Soft()) as a
184
 
185
  with gr.TabItem("🔍 Benchmarks", id=2):
186
  benchmark_ui = create_benchmark_selection_ui(benchmark_selector, auth_manager)
187
-
188
- gr.Markdown("""
189
- ### About Dynamic Highscores
190
-
191
- This platform allows users to select benchmarks from HuggingFace datasets and evaluate models against them.
192
- Each user can submit one benchmark per day (admin users are exempt from this limit).
193
- All evaluations run on CPU only to ensure fair comparisons.
194
-
195
- Created by Quazim0t0
196
- """, elem_classes=["footer"])
197
-
198
- # Auth status check on page load
199
- def check_auth_on_load(request: gr.Request):
200
- # Check if running in HF Space with OAuth
201
- if is_running_in_hf_space():
202
- username = request.headers.get("HF-User")
203
- if username:
204
- print(f"Detected logged-in user via Space OAuth: {username}")
205
- # Get or create user
206
- user = db.get_user_by_username(username)
207
- if not user:
208
- print(f"Creating new user: {username}")
209
- is_admin = (username == "Quazim0t0") # Replace with your admin username
210
- db.add_user(username, username, is_admin)
211
- user = db.get_user_by_username(username)
212
-
213
- # Update UI for logged in state
214
- return user, f"### ✅ Logged in as {username}", gr.update(visible=False)
215
-
216
- # Not logged in - make sure login section is visible
217
- return None, "### 🔒 Not logged in", gr.update(visible=True)
218
-
219
- # Connect event handlers
220
- login_button.click(
221
- fn=trigger_hf_oauth,
222
- inputs=[],
223
- outputs=[gr.HTML()]
224
- )
225
-
226
- # Check auth on load
227
- app.load(
228
- fn=check_auth_on_load,
229
- inputs=[],
230
- outputs=[auth_status, login_status, login_section]
231
- )
232
 
233
  # Launch the app
234
  if __name__ == "__main__":
235
- # Start queue worker in a separate thread
236
- queue_thread = threading.Thread(target=start_queue_worker)
237
- queue_thread.daemon = True
238
- queue_thread.start()
239
-
240
  app.launch()
 
1
  """
2
  Main application for Dynamic Highscores system.
 
3
  This file integrates all components into a unified application.
4
  """
5
 
 
13
  from evaluation_queue import EvaluationQueue, create_model_submission_ui
14
  from leaderboard import Leaderboard, create_leaderboard_ui
15
  from sample_benchmarks import add_sample_benchmarks
16
+
17
  # Initialize components in main thread
18
  db = DynamicHighscoresDB()
19
  auth_manager = HuggingFaceAuth(db)
 
27
  if not benchmarks or len(benchmarks) == 0:
28
  print("No benchmarks found. Adding sample benchmarks...")
29
  try:
 
 
 
 
30
  num_added = add_sample_benchmarks()
31
  print(f"Added {num_added} sample benchmarks.")
32
  except Exception as e:
33
  print(f"Error adding sample benchmarks: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
+ # Custom CSS
36
  css = """
 
37
  .info-text {
38
  background-color: rgba(53, 130, 220, 0.1);
39
  padding: 12px;
 
41
  border-left: 4px solid #3498db;
42
  margin: 12px 0;
43
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  """
45
 
46
+ # Create Gradio app - NO THEME, NO OAUTH
47
+ with gr.Blocks(css=css, title="Dynamic Highscores") as app:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  gr.Markdown("# 🏆 Dynamic Highscores", elem_classes=["header"])
49
  gr.Markdown("""
50
  Welcome to Dynamic Highscores - a community benchmark platform for evaluating and comparing language models.
 
65
 
66
  with gr.TabItem("🔍 Benchmarks", id=2):
67
  benchmark_ui = create_benchmark_selection_ui(benchmark_selector, auth_manager)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  # Launch the app
70
  if __name__ == "__main__":
 
 
 
 
 
71
  app.launch()