Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
•
2c89463
1
Parent(s):
00a2513
Update app.py
Browse files
app.py
CHANGED
@@ -77,37 +77,6 @@ def create_db_if_missing():
|
|
77 |
def get_db():
|
78 |
return sqlite3.connect(DB_PATH)
|
79 |
|
80 |
-
def get_leaderboard(reveal_prelim: bool):
|
81 |
-
conn = get_db()
|
82 |
-
cursor = conn.cursor()
|
83 |
-
sql = 'SELECT name, upvote, downvote FROM model'
|
84 |
-
if not reveal_prelim: sql += ' WHERE EXISTS (SELECT 1 FROM model WHERE (upvote + downvote) > 750)'
|
85 |
-
cursor.execute(sql)
|
86 |
-
data = cursor.fetchall()
|
87 |
-
df = pd.DataFrame(data, columns=['name', 'upvote', 'downvote'])
|
88 |
-
df['license'] = df['name'].map(model_licenses).fillna("Unknown")
|
89 |
-
df['name'] = df['name'].replace(model_names)
|
90 |
-
df['votes'] = df['upvote'] + df['downvote']
|
91 |
-
# df['score'] = round((df['upvote'] / df['votes']) * 100, 2) # Percentage score
|
92 |
-
|
93 |
-
## ELO SCORE
|
94 |
-
df['score'] = 1200
|
95 |
-
for i in range(len(df)):
|
96 |
-
for j in range(len(df)):
|
97 |
-
if i != j:
|
98 |
-
expected_a = 1 / (1 + 10 ** ((df['score'][j] - df['score'][i]) / 400))
|
99 |
-
expected_b = 1 / (1 + 10 ** ((df['score'][i] - df['score'][j]) / 400))
|
100 |
-
actual_a = df['upvote'][i] / df['votes'][i]
|
101 |
-
actual_b = df['upvote'][j] / df['votes'][j]
|
102 |
-
df.at[i, 'score'] += 32 * (actual_a - expected_a)
|
103 |
-
df.at[j, 'score'] += 32 * (actual_b - expected_b)
|
104 |
-
df['score'] = round(df['score'])
|
105 |
-
## ELO SCORE
|
106 |
-
df = df.sort_values(by='score', ascending=False)
|
107 |
-
df['order'] = ['#' + str(i + 1) for i in range(len(df))]
|
108 |
-
# df = df[['name', 'score', 'upvote', 'votes']]
|
109 |
-
df = df[['order', 'name', 'score', 'license', 'votes']]
|
110 |
-
return df
|
111 |
|
112 |
|
113 |
####################################
|
@@ -318,6 +287,41 @@ model_links = {
|
|
318 |
# choice1 = get_random_split()
|
319 |
# choice2 = get_random_split(choice1)
|
320 |
# return (choice1, choice2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
def mkuuid(uid):
|
322 |
if not uid:
|
323 |
uid = uuid.uuid4()
|
|
|
77 |
def get_db():
|
78 |
return sqlite3.connect(DB_PATH)
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
|
82 |
####################################
|
|
|
287 |
# choice1 = get_random_split()
|
288 |
# choice2 = get_random_split(choice1)
|
289 |
# return (choice1, choice2)
|
290 |
+
def model_license(name):
|
291 |
+
if name in model_licenses.keys():
|
292 |
+
return model_licenses[name]
|
293 |
+
return 'Unknown'
|
294 |
+
def get_leaderboard(reveal_prelim: bool):
|
295 |
+
conn = get_db()
|
296 |
+
cursor = conn.cursor()
|
297 |
+
sql = 'SELECT name, upvote, downvote FROM model'
|
298 |
+
if not reveal_prelim: sql += ' WHERE EXISTS (SELECT 1 FROM model WHERE (upvote + downvote) > 750)'
|
299 |
+
cursor.execute(sql)
|
300 |
+
data = cursor.fetchall()
|
301 |
+
df = pd.DataFrame(data, columns=['name', 'upvote', 'downvote'])
|
302 |
+
df['license'] = df['name'].map(model_license).fillna("Unknown")
|
303 |
+
df['name'] = df['name'].replace(model_names)
|
304 |
+
df['votes'] = df['upvote'] + df['downvote']
|
305 |
+
# df['score'] = round((df['upvote'] / df['votes']) * 100, 2) # Percentage score
|
306 |
+
|
307 |
+
## ELO SCORE
|
308 |
+
df['score'] = 1200
|
309 |
+
for i in range(len(df)):
|
310 |
+
for j in range(len(df)):
|
311 |
+
if i != j:
|
312 |
+
expected_a = 1 / (1 + 10 ** ((df['score'][j] - df['score'][i]) / 400))
|
313 |
+
expected_b = 1 / (1 + 10 ** ((df['score'][i] - df['score'][j]) / 400))
|
314 |
+
actual_a = df['upvote'][i] / df['votes'][i]
|
315 |
+
actual_b = df['upvote'][j] / df['votes'][j]
|
316 |
+
df.at[i, 'score'] += 32 * (actual_a - expected_a)
|
317 |
+
df.at[j, 'score'] += 32 * (actual_b - expected_b)
|
318 |
+
df['score'] = round(df['score'])
|
319 |
+
## ELO SCORE
|
320 |
+
df = df.sort_values(by='score', ascending=False)
|
321 |
+
df['order'] = ['#' + str(i + 1) for i in range(len(df))]
|
322 |
+
# df = df[['name', 'score', 'upvote', 'votes']]
|
323 |
+
df = df[['order', 'name', 'score', 'license', 'votes']]
|
324 |
+
return df
|
325 |
def mkuuid(uid):
|
326 |
if not uid:
|
327 |
uid = uuid.uuid4()
|