Spaces:
Running
on
Zero
Running
on
Zero
Leaderboard: names; percentage; sort by elo&votes
Browse files- app/leaderboard.py +66 -29
- app/ui_leaderboard.py +1 -1
app/leaderboard.py
CHANGED
@@ -12,40 +12,51 @@ def get_leaderboard(reveal_prelim = False):
|
|
12 |
|
13 |
conn = get_db()
|
14 |
cursor = conn.cursor()
|
15 |
-
sql = 'SELECT
|
16 |
prelim_votes = 300
|
17 |
-
if not reveal_prelim: sql += ' WHERE (
|
18 |
cursor.execute(sql)
|
19 |
data = cursor.fetchall()
|
20 |
-
df = pd.DataFrame(data, columns=['
|
21 |
-
# df['
|
22 |
-
df['
|
23 |
for i in range(len(df)):
|
24 |
-
df.loc[i, "
|
25 |
|
26 |
# Calculate total votes and win rate
|
27 |
-
df['
|
28 |
-
df['
|
29 |
-
#
|
|
|
|
|
|
|
30 |
|
31 |
## ELO SCORE
|
32 |
-
df['
|
33 |
-
df['
|
34 |
for i in range(len(df)):
|
35 |
for j in range(len(df)):
|
36 |
if i != j:
|
37 |
try:
|
38 |
-
expected_a = 1 / (1 + 10 ** ((df['
|
39 |
-
expected_b = 1 / (1 + 10 ** ((df['
|
40 |
-
actual_a = df['
|
41 |
-
actual_b = df['
|
42 |
-
df.at[i, '
|
43 |
-
df.at[j, '
|
44 |
except Exception as e:
|
45 |
print(f"Error in ELO calculation for rows {i} and {j}: {str(e)}")
|
46 |
continue
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
if (
|
51 |
reveal_prelim == False
|
@@ -57,7 +68,7 @@ def get_leaderboard(reveal_prelim = False):
|
|
57 |
try:
|
58 |
if (reveal_prelim == False):
|
59 |
for i in range(len(df)):
|
60 |
-
elo_diff = (df['
|
61 |
if (elo_diff == 0):
|
62 |
continue
|
63 |
if (elo_diff > 0):
|
@@ -65,17 +76,24 @@ def get_leaderboard(reveal_prelim = False):
|
|
65 |
else:
|
66 |
plus = '<em style="color: red; font-family: monospace">'
|
67 |
|
68 |
-
df.at[i, '
|
69 |
except:
|
70 |
# FIXME: crashes when a TTS from premilinary results passes the vote threshold
|
71 |
pass
|
72 |
|
73 |
-
|
74 |
-
df = df.sort_values(by='
|
|
|
|
|
|
|
75 |
# medals
|
76 |
-
def assign_medal(rank, assign):
|
77 |
rank = str(rank + 1)
|
78 |
-
if
|
|
|
|
|
|
|
|
|
79 |
if rank == '1':
|
80 |
rank += '🥇'
|
81 |
elif rank == '2':
|
@@ -83,11 +101,30 @@ def get_leaderboard(reveal_prelim = False):
|
|
83 |
elif rank == '3':
|
84 |
rank += '🥉'
|
85 |
|
|
|
|
|
86 |
return '#'+ rank
|
87 |
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
# fetch top_five
|
90 |
-
for orig_name in df['
|
91 |
if (
|
92 |
reveal_prelim
|
93 |
and len(top_five) < 5
|
@@ -95,6 +132,6 @@ def get_leaderboard(reveal_prelim = False):
|
|
95 |
):
|
96 |
top_five.append(orig_name)
|
97 |
|
98 |
-
df['
|
99 |
-
df = df[['
|
100 |
return df
|
|
|
12 |
|
13 |
conn = get_db()
|
14 |
cursor = conn.cursor()
|
15 |
+
sql = 'SELECT Name, Upvote, Downvote, name AS OrigName FROM model'
|
16 |
prelim_votes = 300
|
17 |
+
if not reveal_prelim: sql += ' WHERE (Upvote + Downvote) > '+ str(prelim_votes)
|
18 |
cursor.execute(sql)
|
19 |
data = cursor.fetchall()
|
20 |
+
df = pd.DataFrame(data, columns=['Name', 'Upvote', 'Downvote', 'OrigName'])
|
21 |
+
# df['License'] = df['Name'].map(model_license)
|
22 |
+
df['Name'] = df['Name'].replace(model_names)
|
23 |
for i in range(len(df)):
|
24 |
+
df.loc[i, "Name"] = make_link_to_space(df['Name'][i], True)
|
25 |
|
26 |
# Calculate total votes and win rate
|
27 |
+
df['Votes'] = df['Upvote'] + df['Downvote']
|
28 |
+
df['Win Rate'] = (df['Upvote'] / df['Votes'] * 100).round(1)
|
29 |
+
# convert to string
|
30 |
+
df['Win Rate'] = df['Win Rate'].astype(str) + '%'
|
31 |
+
|
32 |
+
# df['Score'] = round((df['Upvote'] / df['Votes']) * 100, 2) # Percentage score
|
33 |
|
34 |
## ELO SCORE
|
35 |
+
df['Elo'] = 1200
|
36 |
+
df['Elo Diff'] = ""
|
37 |
for i in range(len(df)):
|
38 |
for j in range(len(df)):
|
39 |
if i != j:
|
40 |
try:
|
41 |
+
expected_a = 1 / (1 + 10 ** ((df['Elo'].iloc[j] - df['Elo'].iloc[i]) / 400))
|
42 |
+
expected_b = 1 / (1 + 10 ** ((df['Elo'].iloc[i] - df['Elo'].iloc[j]) / 400))
|
43 |
+
actual_a = df['Upvote'].iloc[i] / df['Votes'].iloc[i] if df['Votes'].iloc[i] > 0 else 0.5
|
44 |
+
actual_b = df['Upvote'].iloc[j] / df['Votes'].iloc[j] if df['Votes'].iloc[j] > 0 else 0.5
|
45 |
+
df.at[i, 'Elo'] += round(32 * (actual_a - expected_a))
|
46 |
+
df.at[j, 'Elo'] += round(32 * (actual_b - expected_b))
|
47 |
except Exception as e:
|
48 |
print(f"Error in ELO calculation for rows {i} and {j}: {str(e)}")
|
49 |
continue
|
50 |
+
|
51 |
+
# add link to vote dataset
|
52 |
+
orig_name = df['OrigName'].iloc[i]
|
53 |
+
if ('/' in orig_name):
|
54 |
+
# win rate dataset
|
55 |
+
df.at[i, 'Win Rate'] = f'<a target="_blank" href="https://huggingface.co/datasets/{DB_DATASET_ID}/viewer/summary/rejections?f[rejected][value]=%27{orig_name}%27">' + df['Win Rate'].iloc[i] + '</a>'
|
56 |
+
# df['Win Rate'].iloc[i] = f'<a target="_blank" href="https://huggingface.co/datasets/{DB_DATASET_ID}/viewer/summary/rejections?f[rejected][value]=%27{orig_name}%27">' + df['Win Rate'].iloc[i] + '</a>'
|
57 |
+
# df.loc[i,"Win Rate"] = f'<a target="_blank" href="https://huggingface.co/datasets/{DB_DATASET_ID}/viewer/summary/rejections?f[rejected][value]=%27{orig_name}%27">' + df['Win Rate'].iloc[i] + '</a>'
|
58 |
+
df['Elo'] = round(df['Elo'])
|
59 |
+
df['Elo Diff'] = df['Elo']
|
60 |
|
61 |
if (
|
62 |
reveal_prelim == False
|
|
|
68 |
try:
|
69 |
if (reveal_prelim == False):
|
70 |
for i in range(len(df)):
|
71 |
+
elo_diff = (df['Elo'].iloc[i] - leaderboard_df['Elo'].iloc[i])
|
72 |
if (elo_diff == 0):
|
73 |
continue
|
74 |
if (elo_diff > 0):
|
|
|
76 |
else:
|
77 |
plus = '<em style="color: red; font-family: monospace">'
|
78 |
|
79 |
+
df.at[i, 'Elo Diff'] = str(df['Elo'].iloc[i]) + plus + str(elo_diff) +'</em>'
|
80 |
except:
|
81 |
# FIXME: crashes when a TTS from premilinary results passes the vote threshold
|
82 |
pass
|
83 |
|
84 |
+
# Sort by ELO score and then by Vote count
|
85 |
+
df = df.sort_values(by=['Elo', 'Votes'], ascending=[False, False])
|
86 |
+
|
87 |
+
# last in model series from models.py
|
88 |
+
last_series = []
|
89 |
# medals
|
90 |
+
def assign_medal(rank, model_series, last_series, assign):
|
91 |
rank = str(rank + 1)
|
92 |
+
if (
|
93 |
+
assign
|
94 |
+
# and last_series != ''
|
95 |
+
# and model_series != last_series
|
96 |
+
):
|
97 |
if rank == '1':
|
98 |
rank += '🥇'
|
99 |
elif rank == '2':
|
|
|
101 |
elif rank == '3':
|
102 |
rank += '🥉'
|
103 |
|
104 |
+
if (model_series != last_series):
|
105 |
+
last_series = model_series
|
106 |
return '#'+ rank
|
107 |
|
108 |
+
try:
|
109 |
+
df['Order'] = [
|
110 |
+
assign_medal(
|
111 |
+
i,
|
112 |
+
HF_SPACES[df['OrigName'].iloc[i]]['series'],
|
113 |
+
last_series,
|
114 |
+
not reveal_prelim and len(df) > 2
|
115 |
+
) for i in range(len(df))
|
116 |
+
]
|
117 |
+
except:
|
118 |
+
df['Order'] = [assign_medal(
|
119 |
+
i,
|
120 |
+
'',
|
121 |
+
'',
|
122 |
+
not reveal_prelim and len(df) > 2) for i in range(len(df))
|
123 |
+
]
|
124 |
+
pass
|
125 |
+
|
126 |
# fetch top_five
|
127 |
+
for orig_name in df['OrigName']:
|
128 |
if (
|
129 |
reveal_prelim
|
130 |
and len(top_five) < 5
|
|
|
132 |
):
|
133 |
top_five.append(orig_name)
|
134 |
|
135 |
+
df['Elo'] = df['Elo Diff']
|
136 |
+
df = df[['Order', 'Name', 'Win Rate', 'Elo', 'Votes']]
|
137 |
return df
|
app/ui_leaderboard.py
CHANGED
@@ -10,7 +10,7 @@ with gr.Blocks() as leaderboard:
|
|
10 |
min_width=0,
|
11 |
wrap=False,
|
12 |
column_widths=[30, 200, 50, 50, 50],
|
13 |
-
datatype=["str", "html", "
|
14 |
)
|
15 |
reloadbtn = gr.Button("Refresh")
|
16 |
with gr.Row():
|
|
|
10 |
min_width=0,
|
11 |
wrap=False,
|
12 |
column_widths=[30, 200, 50, 50, 50],
|
13 |
+
datatype=["str", "html", "html", "html", "html"],
|
14 |
)
|
15 |
reloadbtn = gr.Button("Refresh")
|
16 |
with gr.Row():
|