Spaces:
Build error
Build error
Added debugging for Hex
Browse files- ui/utils.py +49 -0
ui/utils.py
CHANGED
|
@@ -5,6 +5,55 @@ This module contains utility functions for the Gradio interface,
|
|
| 5 |
including model name cleaning and display formatting.
|
| 6 |
"""
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def clean_model_name(model_name: str) -> str:
|
| 10 |
"""
|
|
|
|
| 5 |
including model name cleaning and display formatting.
|
| 6 |
"""
|
| 7 |
|
| 8 |
+
import os
|
| 9 |
+
import sqlite3
|
| 10 |
+
import glob
|
| 11 |
+
from typing import Set
|
| 12 |
+
import logging
|
| 13 |
+
|
| 14 |
+
log = logging.getLogger(__name__)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def get_games_from_databases() -> Set[str]:
|
| 18 |
+
"""
|
| 19 |
+
Extract unique game names from all database files in the workspace.
|
| 20 |
+
|
| 21 |
+
Returns:
|
| 22 |
+
Set of game names found in database files
|
| 23 |
+
"""
|
| 24 |
+
unique_games = set()
|
| 25 |
+
|
| 26 |
+
# Find all .db files in the workspace
|
| 27 |
+
db_files = glob.glob("**/*.db", recursive=True)
|
| 28 |
+
|
| 29 |
+
for db_file in db_files:
|
| 30 |
+
if not os.path.exists(db_file):
|
| 31 |
+
continue
|
| 32 |
+
|
| 33 |
+
try:
|
| 34 |
+
with sqlite3.connect(db_file) as conn:
|
| 35 |
+
cursor = conn.cursor()
|
| 36 |
+
|
| 37 |
+
# Check if game_results table exists and get unique game names
|
| 38 |
+
cursor.execute(
|
| 39 |
+
"SELECT name FROM sqlite_master WHERE type='table' "
|
| 40 |
+
"AND name='game_results'"
|
| 41 |
+
)
|
| 42 |
+
if cursor.fetchone():
|
| 43 |
+
cursor.execute(
|
| 44 |
+
"SELECT DISTINCT game_name FROM game_results "
|
| 45 |
+
"WHERE game_name IS NOT NULL"
|
| 46 |
+
)
|
| 47 |
+
games_in_db = cursor.fetchall()
|
| 48 |
+
for (game_name,) in games_in_db:
|
| 49 |
+
if game_name: # Skip None/empty values
|
| 50 |
+
unique_games.add(game_name)
|
| 51 |
+
|
| 52 |
+
except Exception as e:
|
| 53 |
+
log.warning("Error reading database %s: %s", db_file, e)
|
| 54 |
+
|
| 55 |
+
return unique_games
|
| 56 |
+
|
| 57 |
|
| 58 |
def clean_model_name(model_name: str) -> str:
|
| 59 |
"""
|