Spaces:
Running
Running
Update leaderboard.py
Browse files- leaderboard.py +93 -0
leaderboard.py
CHANGED
@@ -71,3 +71,96 @@ def create_backup():
|
|
71 |
def start_backup_thread():
|
72 |
backup_thread = threading.Thread(target=create_backup, daemon=True)
|
73 |
backup_thread.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
def start_backup_thread():
|
72 |
backup_thread = threading.Thread(target=create_backup, daemon=True)
|
73 |
backup_thread.start()
|
74 |
+
|
75 |
+
|
76 |
+
def get_human_readable_name(model_name: str) -> str:
|
77 |
+
model_dict = dict(arena_config.APPROVED_MODELS)
|
78 |
+
return model_dict.get(model_name, model_name)
|
79 |
+
|
80 |
+
def get_leaderboard():
|
81 |
+
battle_results = get_current_leaderboard()
|
82 |
+
|
83 |
+
# Calculate scores for each model
|
84 |
+
for model, results in battle_results.items():
|
85 |
+
total_battles = results["wins"] + results["losses"]
|
86 |
+
if total_battles > 0:
|
87 |
+
win_rate = results["wins"] / total_battles
|
88 |
+
results["score"] = win_rate * (1 - 1 / (total_battles + 1))
|
89 |
+
else:
|
90 |
+
results["score"] = 0
|
91 |
+
|
92 |
+
# Sort results by score, then by total battles
|
93 |
+
sorted_results = sorted(
|
94 |
+
battle_results.items(),
|
95 |
+
key=lambda x: (x[1]["score"], x[1]["wins"] + x[1]["losses"]),
|
96 |
+
reverse=True
|
97 |
+
)
|
98 |
+
|
99 |
+
leaderboard = """
|
100 |
+
<style>
|
101 |
+
.leaderboard-table {
|
102 |
+
width: 100%;
|
103 |
+
border-collapse: collapse;
|
104 |
+
font-family: Arial, sans-serif;
|
105 |
+
}
|
106 |
+
.leaderboard-table th, .leaderboard-table td {
|
107 |
+
border: 1px solid #ddd;
|
108 |
+
padding: 8px;
|
109 |
+
text-align: left;
|
110 |
+
}
|
111 |
+
.leaderboard-table th {
|
112 |
+
background-color: rgba(255, 255, 255, 0.1);
|
113 |
+
font-weight: bold;
|
114 |
+
}
|
115 |
+
.rank-column {
|
116 |
+
width: 60px;
|
117 |
+
text-align: center;
|
118 |
+
}
|
119 |
+
.opponent-details {
|
120 |
+
font-size: 0.9em;
|
121 |
+
color: #888;
|
122 |
+
}
|
123 |
+
</style>
|
124 |
+
<table class='leaderboard-table'>
|
125 |
+
<tr>
|
126 |
+
<th class='rank-column'>Rank</th>
|
127 |
+
<th>Model</th>
|
128 |
+
<th>Score</th>
|
129 |
+
<th>Wins</th>
|
130 |
+
<th>Losses</th>
|
131 |
+
<th>Win Rate</th>
|
132 |
+
<th>Total Battles</th>
|
133 |
+
<th>Top Rival</th>
|
134 |
+
<th>Toughest Opponent</th>
|
135 |
+
</tr>
|
136 |
+
"""
|
137 |
+
|
138 |
+
for index, (model, results) in enumerate(sorted_results, start=1):
|
139 |
+
total_battles = results["wins"] + results["losses"]
|
140 |
+
win_rate = (results["wins"] / total_battles * 100) if total_battles > 0 else 0
|
141 |
+
|
142 |
+
rank_display = {1: "π₯", 2: "π₯", 3: "π₯", 18: "π", 19: "π°", 20: "π"}.get(index, f"{index}")
|
143 |
+
|
144 |
+
top_rival = max(results["opponents"].items(), key=lambda x: x[1]["wins"], default=(None, {"wins": 0}))
|
145 |
+
top_rival_name = get_human_readable_name(top_rival[0]) if top_rival[0] else "N/A"
|
146 |
+
top_rival_wins = top_rival[1]["wins"]
|
147 |
+
|
148 |
+
toughest_opponent = max(results["opponents"].items(), key=lambda x: x[1]["losses"], default=(None, {"losses": 0}))
|
149 |
+
toughest_opponent_name = get_human_readable_name(toughest_opponent[0]) if toughest_opponent[0] else "N/A"
|
150 |
+
toughest_opponent_losses = toughest_opponent[1]["losses"]
|
151 |
+
|
152 |
+
leaderboard += f"""
|
153 |
+
<tr>
|
154 |
+
<td class='rank-column'>{rank_display}</td>
|
155 |
+
<td>{get_human_readable_name(model)}</td>
|
156 |
+
<td>{results['score']:.4f}</td>
|
157 |
+
<td>{results['wins']}</td>
|
158 |
+
<td>{results['losses']}</td>
|
159 |
+
<td>{win_rate:.2f}%</td>
|
160 |
+
<td>{total_battles}</td>
|
161 |
+
<td class='opponent-details'>{top_rival_name} (W: {top_rival_wins})</td>
|
162 |
+
<td class='opponent-details'>{toughest_opponent_name} (L: {toughest_opponent_losses})</td>
|
163 |
+
</tr>
|
164 |
+
"""
|
165 |
+
leaderboard += "</table>"
|
166 |
+
return leaderboard
|