feat: leaderboard
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ import time
|
|
| 9 |
|
| 10 |
import os
|
| 11 |
import sys
|
|
|
|
| 12 |
import pandas as pd
|
| 13 |
import json
|
| 14 |
import shutil
|
|
@@ -262,6 +263,70 @@ def certification(hf_username, first_name, last_name):
|
|
| 262 |
return message, pdf, certificate, output_row.update(visible=visible)
|
| 263 |
|
| 264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
with gr.Blocks() as demo:
|
| 266 |
gr.Markdown(
|
| 267 |
'<img style="display: block; margin-left: auto; margin-right: auto; height: 10em;"'
|
|
@@ -313,5 +378,16 @@ with gr.Blocks() as demo:
|
|
| 313 |
Don't hesitate to share your contributions on Twitter (tag me [@wonhseo](https://twitter.com/wonhseo) and [@huggingface](https://twitter.com/huggingface)) and on LinkedIn.
|
| 314 |
"""
|
| 315 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
demo.launch(debug=True)
|
|
|
|
| 9 |
|
| 10 |
import os
|
| 11 |
import sys
|
| 12 |
+
from collections import defaultdict
|
| 13 |
import pandas as pd
|
| 14 |
import json
|
| 15 |
import shutil
|
|
|
|
| 263 |
return message, pdf, certificate, output_row.update(visible=visible)
|
| 264 |
|
| 265 |
|
| 266 |
+
def make_clickable_repo(name, repo_type):
|
| 267 |
+
if repo_type == "space":
|
| 268 |
+
link = "https://huggingface.co/" + "spaces/" + name
|
| 269 |
+
elif repo_type == "model":
|
| 270 |
+
link = "https://huggingface.co/" + name
|
| 271 |
+
elif repo_type == "dataset":
|
| 272 |
+
link = "https://huggingface.co/" + "datasets/" + name
|
| 273 |
+
return f'<a target="_blank" href="{link}">{name.split("/")[-1]}</a>'
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
def make_clickable_user(user_id):
|
| 277 |
+
link = "https://huggingface.co/" + user_id
|
| 278 |
+
return f'<a target="_blank" href="{link}">{user_id}</a>'
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
def leaderboard():
|
| 282 |
+
"""
|
| 283 |
+
Get the leaderboard of the hackathon.
|
| 284 |
+
|
| 285 |
+
The leaderboard is a Pandas DataFrame with the following columns:
|
| 286 |
+
- Rank: the rank of the user in the leaderboard
|
| 287 |
+
- User: the Hugging Face username of the user
|
| 288 |
+
- Contributions: the list of contributions of the user (models, datasets, spaces)
|
| 289 |
+
- Likes: the total number of likes of the user's contributions
|
| 290 |
+
"""
|
| 291 |
+
repo_list = {
|
| 292 |
+
'model': api.list_models,
|
| 293 |
+
'dataset': api.list_datasets,
|
| 294 |
+
'space': api.list_spaces
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
# Repos that should not be included in the leaderboard
|
| 298 |
+
not_included = [
|
| 299 |
+
# 'README',
|
| 300 |
+
# '2023-Hackathon-Certification',
|
| 301 |
+
# 'huggingface-krew-hackathon2023'
|
| 302 |
+
]
|
| 303 |
+
|
| 304 |
+
contributions = defaultdict(list)
|
| 305 |
+
|
| 306 |
+
for repo_type in repo_list:
|
| 307 |
+
for repo in repo_list[repo_type](author=ORGANIZATION):
|
| 308 |
+
if repo.id.split('/')[-1] in not_included:
|
| 309 |
+
continue
|
| 310 |
+
commits = api.list_repo_commits(repo.id, repo_type=repo_type)
|
| 311 |
+
for author in set(author for commit in commits for author in commit.authors):
|
| 312 |
+
contributions[author].append((repo_type, repo.id, repo.likes))
|
| 313 |
+
|
| 314 |
+
leaderboard = []
|
| 315 |
+
for user, repo_likes in contributions.items():
|
| 316 |
+
repos = []
|
| 317 |
+
user_likes = 0
|
| 318 |
+
for repo_type, repo, likes in repo_likes:
|
| 319 |
+
repos.append(make_clickable_repo(repo, repo_type))
|
| 320 |
+
user_likes += likes
|
| 321 |
+
leaderboard.append([make_clickable_user(user), '- ' + '\n- '.join(repos), user_likes])
|
| 322 |
+
|
| 323 |
+
df = pd.DataFrame(data=leaderboard, columns=["User", "Contributions", "Likes"])
|
| 324 |
+
df.sort_values(by=["Likes"], ascending=False, inplace=True)
|
| 325 |
+
df.insert(0, "Rank", list(range(1, len(df) + 1)))
|
| 326 |
+
|
| 327 |
+
return df
|
| 328 |
+
|
| 329 |
+
|
| 330 |
with gr.Blocks() as demo:
|
| 331 |
gr.Markdown(
|
| 332 |
'<img style="display: block; margin-left: auto; margin-right: auto; height: 10em;"'
|
|
|
|
| 378 |
Don't hesitate to share your contributions on Twitter (tag me [@wonhseo](https://twitter.com/wonhseo) and [@huggingface](https://twitter.com/huggingface)) and on LinkedIn.
|
| 379 |
"""
|
| 380 |
)
|
| 381 |
+
with gr.Row():
|
| 382 |
+
repos_data = gr.components.Dataframe(
|
| 383 |
+
type="pandas", datatype=["number", "markdown", "markdown", "number"]
|
| 384 |
+
)
|
| 385 |
+
with gr.Row():
|
| 386 |
+
data_run = gr.Button("Refresh")
|
| 387 |
+
data_run.click(
|
| 388 |
+
leaderboard, outputs=repos_data
|
| 389 |
+
)
|
| 390 |
+
|
| 391 |
+
demo.load(leaderboard, outputs=repos_data)
|
| 392 |
|
| 393 |
demo.launch(debug=True)
|