k-mktr commited on
Commit
b49e002
·
verified ·
1 Parent(s): 3f10ec6

Update leaderboard.py

Browse files
Files changed (1) hide show
  1. leaderboard.py +12 -14
leaderboard.py CHANGED
@@ -1,24 +1,22 @@
1
  from nc_py_api import Nextcloud
2
  import json
3
  from typing import Dict, Any
4
- import os
5
  import time
6
  from datetime import datetime
7
  import threading
8
- import arena_config
9
- import sys
10
  import math
11
  import plotly.graph_objects as go
12
 
13
  # Initialize Nextcloud client
14
- nc = Nextcloud(nextcloud_url=arena_config.NEXTCLOUD_URL, nc_auth_user=arena_config.NEXTCLOUD_USERNAME, nc_auth_pass=arena_config.NEXTCLOUD_PASSWORD)
15
 
16
  # Dictionary to store ELO ratings
17
  elo_ratings = {}
18
 
19
  def load_leaderboard() -> Dict[str, Any]:
20
  try:
21
- file_content = nc.files.download(arena_config.NEXTCLOUD_LEADERBOARD_PATH)
22
  return json.loads(file_content.decode('utf-8'))
23
  except Exception as e:
24
  print(f"Error loading leaderboard: {str(e)}")
@@ -27,14 +25,14 @@ def load_leaderboard() -> Dict[str, Any]:
27
  def save_leaderboard(leaderboard_data: Dict[str, Any]) -> bool:
28
  try:
29
  json_data = json.dumps(leaderboard_data, indent=2)
30
- nc.files.upload(arena_config.NEXTCLOUD_LEADERBOARD_PATH, json_data.encode('utf-8'))
31
  return True
32
  except Exception as e:
33
  print(f"Error saving leaderboard: {str(e)}")
34
  return False
35
 
36
  def get_model_size(model_name):
37
- for model, human_readable in arena_config.APPROVED_MODELS:
38
  if model == model_name:
39
  size = float(human_readable.split('(')[1].split('B')[0])
40
  return size
@@ -55,7 +53,7 @@ def update_elo_ratings(winner, loser):
55
 
56
  winner_size = get_model_size(winner)
57
  loser_size = get_model_size(loser)
58
- max_size = max(get_model_size(model) for model, _ in arena_config.APPROVED_MODELS)
59
 
60
  k_factor = min(64, 32 * (1 + (loser_size - winner_size) / max_size))
61
 
@@ -64,7 +62,7 @@ def update_elo_ratings(winner, loser):
64
 
65
  def initialize_elo_ratings():
66
  leaderboard = load_leaderboard()
67
- for model, _ in arena_config.APPROVED_MODELS:
68
  size = get_model_size(model)
69
  elo_ratings[model] = 1000 + (size * 100)
70
 
@@ -108,7 +106,7 @@ def get_current_leaderboard() -> Dict[str, Any]:
108
  return load_leaderboard()
109
 
110
  def get_human_readable_name(model_name: str) -> str:
111
- model_dict = dict(arena_config.APPROVED_MODELS)
112
  return model_dict.get(model_name, model_name)
113
 
114
  def get_leaderboard():
@@ -220,7 +218,7 @@ def calculate_elo_impact(model):
220
  for opponent, results in leaderboard[model]['opponents'].items():
221
  model_size = get_model_size(model)
222
  opponent_size = get_model_size(opponent)
223
- max_size = max(get_model_size(m) for m, _ in arena_config.APPROVED_MODELS)
224
 
225
  size_difference = (opponent_size - model_size) / max_size
226
 
@@ -237,7 +235,7 @@ def get_elo_leaderboard():
237
  leaderboard = load_leaderboard()
238
 
239
  # Create a list of all models, including those from APPROVED_MODELS that might not be in the leaderboard yet
240
- all_models = set(dict(arena_config.APPROVED_MODELS).keys()) | set(leaderboard.keys())
241
 
242
  elo_data = []
243
  for model in all_models:
@@ -336,7 +334,7 @@ def create_backup():
336
  leaderboard_data = load_leaderboard()
337
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
338
  backup_file_name = f"leaderboard_backup_{timestamp}.json"
339
- backup_path = f"{arena_config.NEXTCLOUD_BACKUP_FOLDER}/{backup_file_name}"
340
  json_data = json.dumps(leaderboard_data, indent=2)
341
  nc.files.upload(backup_path, json_data.encode('utf-8'))
342
  print(f"Backup created on Nextcloud: {backup_path}")
@@ -419,4 +417,4 @@ def get_leaderboard_chart():
419
  )
420
  )
421
 
422
- return fig
 
1
  from nc_py_api import Nextcloud
2
  import json
3
  from typing import Dict, Any
 
4
  import time
5
  from datetime import datetime
6
  import threading
7
+ import config
 
8
  import math
9
  import plotly.graph_objects as go
10
 
11
  # Initialize Nextcloud client
12
+ nc = Nextcloud(nextcloud_url=config.NEXTCLOUD_URL, nc_auth_user=config.NEXTCLOUD_USERNAME, nc_auth_pass=config.NEXTCLOUD_PASSWORD)
13
 
14
  # Dictionary to store ELO ratings
15
  elo_ratings = {}
16
 
17
  def load_leaderboard() -> Dict[str, Any]:
18
  try:
19
+ file_content = nc.files.download(config.NEXTCLOUD_LEADERBOARD_PATH)
20
  return json.loads(file_content.decode('utf-8'))
21
  except Exception as e:
22
  print(f"Error loading leaderboard: {str(e)}")
 
25
  def save_leaderboard(leaderboard_data: Dict[str, Any]) -> bool:
26
  try:
27
  json_data = json.dumps(leaderboard_data, indent=2)
28
+ nc.files.upload(config.NEXTCLOUD_LEADERBOARD_PATH, json_data.encode('utf-8'))
29
  return True
30
  except Exception as e:
31
  print(f"Error saving leaderboard: {str(e)}")
32
  return False
33
 
34
  def get_model_size(model_name):
35
+ for model, human_readable in config.get_approved_models():
36
  if model == model_name:
37
  size = float(human_readable.split('(')[1].split('B')[0])
38
  return size
 
53
 
54
  winner_size = get_model_size(winner)
55
  loser_size = get_model_size(loser)
56
+ max_size = max(get_model_size(model) for model, _ in config.get_approved_models())
57
 
58
  k_factor = min(64, 32 * (1 + (loser_size - winner_size) / max_size))
59
 
 
62
 
63
  def initialize_elo_ratings():
64
  leaderboard = load_leaderboard()
65
+ for model, _ in config.get_approved_models():
66
  size = get_model_size(model)
67
  elo_ratings[model] = 1000 + (size * 100)
68
 
 
106
  return load_leaderboard()
107
 
108
  def get_human_readable_name(model_name: str) -> str:
109
+ model_dict = dict(config.get_approved_models())
110
  return model_dict.get(model_name, model_name)
111
 
112
  def get_leaderboard():
 
218
  for opponent, results in leaderboard[model]['opponents'].items():
219
  model_size = get_model_size(model)
220
  opponent_size = get_model_size(opponent)
221
+ max_size = max(get_model_size(m) for m, _ in config.get_approved_models())
222
 
223
  size_difference = (opponent_size - model_size) / max_size
224
 
 
235
  leaderboard = load_leaderboard()
236
 
237
  # Create a list of all models, including those from APPROVED_MODELS that might not be in the leaderboard yet
238
+ all_models = set(dict(config.get_approved_models()).keys()) | set(leaderboard.keys())
239
 
240
  elo_data = []
241
  for model in all_models:
 
334
  leaderboard_data = load_leaderboard()
335
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
336
  backup_file_name = f"leaderboard_backup_{timestamp}.json"
337
+ backup_path = f"{config.NEXTCLOUD_BACKUP_FOLDER}/{backup_file_name}"
338
  json_data = json.dumps(leaderboard_data, indent=2)
339
  nc.files.upload(backup_path, json_data.encode('utf-8'))
340
  print(f"Backup created on Nextcloud: {backup_path}")
 
417
  )
418
  )
419
 
420
+ return fig