Quazim0t0 commited on
Commit
d8a1516
Β·
verified Β·
1 Parent(s): 98ee42b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -19
app.py CHANGED
@@ -7,18 +7,16 @@ This file integrates all components into a unified application.
7
  import os
8
  import gradio as gr
9
  import threading
10
- import queue
11
- from database_schema import init_db
12
  from auth import HuggingFaceAuth, create_login_ui, setup_auth_handlers
13
  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
 
18
- # Initialize database
19
- db = init_db()
20
-
21
- # Initialize components
22
  auth_manager = HuggingFaceAuth(db)
23
  benchmark_selector = BenchmarkSelector(db, auth_manager)
24
  evaluation_queue = EvaluationQueue(db, auth_manager)
@@ -28,8 +26,11 @@ leaderboard = Leaderboard(db)
28
  benchmarks = db.get_benchmarks()
29
  if not benchmarks or len(benchmarks) == 0:
30
  print("No benchmarks found. Adding sample benchmarks...")
31
- num_added = add_sample_benchmarks()
32
- print(f"Added {num_added} sample benchmarks.")
 
 
 
33
 
34
  # Custom CSS
35
  css = """
@@ -59,6 +60,16 @@ css = """
59
  }
60
  """
61
 
 
 
 
 
 
 
 
 
 
 
62
  # Create Gradio app
63
  with gr.Blocks(css=css, title="Dynamic Highscores") as app:
64
  gr.Markdown("# πŸ† Dynamic Highscores", elem_classes=["header"])
@@ -78,7 +89,6 @@ with gr.Blocks(css=css, title="Dynamic Highscores") as app:
78
  # Main tabs
79
  with gr.Tabs() as tabs:
80
  with gr.TabItem("πŸ“Š Leaderboard", id=0):
81
- # Fix: Pass db_manager parameter to create_leaderboard_ui
82
  leaderboard_ui = create_leaderboard_ui(leaderboard, db)
83
 
84
  with gr.TabItem("πŸš€ Submit Model", id=1):
@@ -97,19 +107,11 @@ with gr.Blocks(css=css, title="Dynamic Highscores") as app:
97
  Created by Quazim0t0
98
  """, elem_classes=["footer"])
99
 
100
- # Start evaluation queue worker after app is defined
101
- # This prevents the worker from starting before the app is fully initialized
102
- def start_queue_worker():
103
- # Wait a moment to ensure app is initialized
104
- import time
105
- time.sleep(2)
106
- evaluation_queue.start_worker()
107
-
108
  # Launch the app
109
  if __name__ == "__main__":
110
- # Start queue worker in a separate thread to avoid SQLite thread issues
111
  queue_thread = threading.Thread(target=start_queue_worker)
112
  queue_thread.daemon = True
113
  queue_thread.start()
114
 
115
- app.launch()
 
7
  import os
8
  import gradio as gr
9
  import threading
10
+ import time
11
+ from database_schema import DynamicHighscoresDB
12
  from auth import HuggingFaceAuth, create_login_ui, setup_auth_handlers
13
  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
 
18
+ # Initialize components in main thread
19
+ db = DynamicHighscoresDB()
 
 
20
  auth_manager = HuggingFaceAuth(db)
21
  benchmark_selector = BenchmarkSelector(db, auth_manager)
22
  evaluation_queue = EvaluationQueue(db, auth_manager)
 
26
  benchmarks = db.get_benchmarks()
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: {e}")
34
 
35
  # Custom CSS
36
  css = """
 
60
  }
61
  """
62
 
63
+ # Start evaluation queue worker
64
+ def start_queue_worker():
65
+ # Wait a moment to ensure app is initialized
66
+ time.sleep(2)
67
+ try:
68
+ print("Starting evaluation queue worker...")
69
+ evaluation_queue.start_worker()
70
+ except Exception as e:
71
+ print(f"Error starting queue worker: {e}")
72
+
73
  # Create Gradio app
74
  with gr.Blocks(css=css, title="Dynamic Highscores") as app:
75
  gr.Markdown("# πŸ† Dynamic Highscores", elem_classes=["header"])
 
89
  # Main tabs
90
  with gr.Tabs() as tabs:
91
  with gr.TabItem("πŸ“Š Leaderboard", id=0):
 
92
  leaderboard_ui = create_leaderboard_ui(leaderboard, db)
93
 
94
  with gr.TabItem("πŸš€ Submit Model", id=1):
 
107
  Created by Quazim0t0
108
  """, elem_classes=["footer"])
109
 
 
 
 
 
 
 
 
 
110
  # Launch the app
111
  if __name__ == "__main__":
112
+ # Start queue worker in a separate thread
113
  queue_thread = threading.Thread(target=start_queue_worker)
114
  queue_thread.daemon = True
115
  queue_thread.start()
116
 
117
+ app.launch()