wseo commited on
Commit
3433650
1 Parent(s): 0df7ae2

feat: leaderboard-for-sns (#10)

Browse files

- docs: leaderboard column (f70205de62c6e1a42262e22d83123568d71a8fdb)
- feat: leaderboard (e8c5ed74451af40c9eedfe1ed01abb3d5516344f)
- fix: only contributors between hackathon dates (b214b0b511bd528a5391f286e2d2ba51864e3595)
- feat: add twitter button (c6ad687ef9ce4e651adf7ddfb368196215bdda62)
- fix: to prod settings (abc803b8e3ae2ccaf844fd9296cfc2015195ddad)

Files changed (3) hide show
  1. .gitignore +2 -1
  2. app.py +145 -31
  3. hfkr_logo.png +0 -0
.gitignore CHANGED
@@ -1 +1,2 @@
1
- .env
 
 
1
+ .env
2
+ __pycache__
app.py CHANGED
@@ -4,11 +4,12 @@ from huggingface_hub.repocard import metadata_load
4
  from gradio_client import Client
5
  from PIL import Image, ImageDraw, ImageFont
6
 
7
- from datetime import date
8
  import time
9
 
10
  import os
11
  import sys
 
12
  import pandas as pd
13
  import json
14
  import shutil
@@ -22,6 +23,9 @@ CERTIFIED_USERS_FILENAME = "certified.csv"
22
 
23
  ORGANIZATION = "pseudolab"
24
 
 
 
 
25
 
26
  def has_contributions(repo_type, hf_username, organization, likes=10):
27
  """
@@ -38,7 +42,7 @@ def has_contributions(repo_type, hf_username, organization, likes=10):
38
  }
39
 
40
  for repo in repo_list[repo_type](author=organization):
41
- if len(api.list_repo_likers(repo.id, repo_type=repo_type)) < likes:
42
  continue
43
  commits = api.list_repo_commits(repo.id, repo_type=repo_type)
44
  if any(hf_username in commit.authors for commit in commits):
@@ -69,10 +73,11 @@ def check_if_passed(hf_username):
69
  certificate_type = ""
70
 
71
  # If the user contributed to models, datasets and spaces then assign excellence
72
- if all(get_hub_footprint(hf_username, ORGANIZATION)):
 
73
  passed = True
74
  certificate_type = "excellence"
75
- elif any(get_hub_footprint(hf_username, ORGANIZATION)):
76
  passed = True
77
  certificate_type = "completion"
78
 
@@ -230,7 +235,7 @@ def create_certificate(passed, certificate_type, hf_username, first_name, last_n
230
  Since you contributed to at least one model, dataset, or space- you get a Certificate of Completion 🎓.
231
  You can download your certificate below ⬇️
232
  https://huggingface.co/datasets/pseudolab/huggingface-krew-hackathon2023/resolve/main/certificates/{hf_username}.pdf\n
233
- Don't hesitate to share your certificate link above on Twitter and Linkedin (you can tag me @wonhseo, @pseudo-lab and @huggingface) 🤗 \n
234
  You can try to get a Certificate of Excellence if you contribute to all types of repos, please don't hesitate to do so.
235
  """
236
  else:
@@ -261,38 +266,147 @@ def certification(hf_username, first_name, last_name):
261
  return message, pdf, certificate, output_row.update(visible=visible)
262
 
263
 
264
- with gr.Blocks() as demo:
265
- gr.Markdown(
266
- f"""
267
- # Get your 2023 Hackathon Certificate 🎓
268
- The certification process is completely free:
269
- - To get a *certificate of completion*: you need to **contribute to at least one model, dataset, or space**.
270
- - To get a *certificate of excellence*: you need to **contribute to models, datasets, and spaces**. *(Yes, all three!)*
271
-
272
- For more information about the certification process [check the hackathon page on certification](https://pseudo-lab.github.io/huggingface-hackathon23/submit.html#certification).
 
 
 
 
 
 
 
 
 
273
 
274
- Don't hesitate to share your certificate on Twitter (tag me [@wonhseo](https://twitter.com/wonhseo), [@pseudo-lab](https://twitter.com/pseudo-lab), and [@huggingface](https://twitter.com/huggingface)) and on LinkedIn.
 
 
 
 
275
  """
276
- )
 
 
 
 
277
 
278
- hf_username = gr.Textbox(
279
- placeholder="wseo", label="Your Hugging Face Username (case sensitive)"
280
- )
281
- first_name = gr.Textbox(placeholder="Wonhyeong", label="Your First Name")
282
- last_name = gr.Textbox(placeholder="Seo", label="Your Last Name")
 
 
283
 
284
- check_progress_button = gr.Button(value="Check if I pass and get the certificate")
285
- output_text = gr.components.Textbox(label="Your Result")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
 
287
- with gr.Row(visible=True) as output_row:
288
- output_pdf = gr.File()
289
- output_img = gr.components.Image(type="pil")
290
 
291
- check_progress_button.click(
292
- fn=certification,
293
- inputs=[hf_username, first_name, last_name],
294
- outputs=[output_text, output_pdf, output_img, output_row],
 
295
  )
296
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
 
298
  demo.launch(debug=True)
 
4
  from gradio_client import Client
5
  from PIL import Image, ImageDraw, ImageFont
6
 
7
+ from datetime import datetime, timezone, timedelta
8
  import time
9
 
10
  import os
11
  import sys
12
+ from collections import defaultdict
13
  import pandas as pd
14
  import json
15
  import shutil
 
23
 
24
  ORGANIZATION = "pseudolab"
25
 
26
+ START_DATE = datetime(2023, 10, 20, tzinfo=timezone(timedelta(hours=9)))
27
+ END_DATE = datetime(2023, 11, 10, tzinfo=timezone(timedelta(hours=9)))
28
+
29
 
30
  def has_contributions(repo_type, hf_username, organization, likes=10):
31
  """
 
42
  }
43
 
44
  for repo in repo_list[repo_type](author=organization):
45
+ if repo.likes < likes:
46
  continue
47
  commits = api.list_repo_commits(repo.id, repo_type=repo_type)
48
  if any(hf_username in commit.authors for commit in commits):
 
73
  certificate_type = ""
74
 
75
  # If the user contributed to models, datasets and spaces then assign excellence
76
+ has_models, has_datasets, has_spaces = get_hub_footprint(hf_username, ORGANIZATION)
77
+ if all(has_models, has_datasets, has_spaces):
78
  passed = True
79
  certificate_type = "excellence"
80
+ elif any(has_models, has_datasets, has_spaces):
81
  passed = True
82
  certificate_type = "completion"
83
 
 
235
  Since you contributed to at least one model, dataset, or space- you get a Certificate of Completion 🎓.
236
  You can download your certificate below ⬇️
237
  https://huggingface.co/datasets/pseudolab/huggingface-krew-hackathon2023/resolve/main/certificates/{hf_username}.pdf\n
238
+ Don't hesitate to share your certificate link above on Twitter and Linkedin (you can tag me @wonhseo and @huggingface) 🤗
239
  You can try to get a Certificate of Excellence if you contribute to all types of repos, please don't hesitate to do so.
240
  """
241
  else:
 
266
  return message, pdf, certificate, output_row.update(visible=visible)
267
 
268
 
269
+ def make_clickable_repo(name, repo_type):
270
+ if repo_type == "space":
271
+ link = "https://huggingface.co/" + "spaces/" + name
272
+ elif repo_type == "model":
273
+ link = "https://huggingface.co/" + name
274
+ elif repo_type == "dataset":
275
+ link = "https://huggingface.co/" + "datasets/" + name
276
+ return f'<a target="_blank" href="{link}">{name.split("/")[-1]}</a>'
277
+
278
+
279
+ def make_clickable_user(user_id):
280
+ link = "https://huggingface.co/" + user_id
281
+ return f'<a target="_blank" href="{link}">{user_id}</a>'
282
+
283
+
284
+ def leaderboard():
285
+ """
286
+ Get the leaderboard of the hackathon.
287
 
288
+ The leaderboard is a Pandas DataFrame with the following columns:
289
+ - Rank: the rank of the user in the leaderboard
290
+ - User: the Hugging Face username of the user
291
+ - Contributions: the list of contributions of the user (models, datasets, spaces)
292
+ - Likes: the total number of likes of the user's contributions
293
  """
294
+ repo_list = {
295
+ 'model': api.list_models,
296
+ 'dataset': api.list_datasets,
297
+ 'space': api.list_spaces
298
+ }
299
 
300
+ # Repos that should not be included in the leaderboard
301
+ not_included = [
302
+ 'README',
303
+ '2023-Hackathon-Certification',
304
+ 'huggingface-krew-hackathon2023',
305
+ # template repos as well
306
+ ]
307
 
308
+ contributions = defaultdict(list)
309
+
310
+ for repo_type in repo_list:
311
+ for repo in repo_list[repo_type](author=ORGANIZATION):
312
+ if repo.id.split('/')[-1] in not_included:
313
+ continue
314
+ commits = api.list_repo_commits(repo.id, repo_type=repo_type)
315
+ for author in set(author for commit in commits if START_DATE < commit.created_at < END_DATE for author in commit.authors):
316
+ contributions[author].append((repo_type, repo.id, repo.likes))
317
+
318
+ leaderboard = []
319
+ for user, repo_likes in contributions.items():
320
+ repos = []
321
+ user_likes = 0
322
+ for repo_type, repo, likes in repo_likes:
323
+ repos.append(make_clickable_repo(repo, repo_type))
324
+ user_likes += likes
325
+ leaderboard.append([make_clickable_user(user), '- ' + '\n- '.join(repos), user_likes])
326
+
327
+ df = pd.DataFrame(data=leaderboard, columns=["User 👤", "Contributions 🛠️", "Likes ❤️"])
328
+ df.sort_values(by=["Likes ❤️"], ascending=False, inplace=True)
329
+ df.insert(0, "Rank 🏆", list(range(1, len(df) + 1)))
330
+
331
+ return df
332
 
 
 
 
333
 
334
+ with gr.Blocks() as demo:
335
+ gr.Markdown(
336
+ '<img style="display: block; margin-left: auto; margin-right: auto; height: 10em;"'
337
+ ' src="file/hfkr_logo.png"/>\n\n'
338
+ '<h1 style="text-align: center;">Hugging Face KREW Hackathon 2023: Everyday AI</h1>'
339
  )
340
+ with gr.Row():
341
+ with gr.Column() as certificate_column:
342
+ gr.Markdown(
343
+ f"""
344
+ ## Get your 2023 Hackathon Certificate 🎓
345
+ The certification process is completely free:
346
+ - To get a *certificate of completion*: you need to **contribute to at least one model, dataset, or space**.
347
+ - To get a *certificate of excellence*: you need to **contribute to models, datasets, and spaces**. *(Yes, all three!)*
348
+
349
+ For more information about the certification process [check the hackathon page on certification](https://pseudo-lab.github.io/huggingface-hackathon23/tutorials/project-roadmap.html#certification).
350
+ Don't hesitate to share your certificate on Twitter (tag me [@wonhseo](https://twitter.com/wonhseo) and [@huggingface](https://twitter.com/huggingface)) and on LinkedIn.
351
+ """
352
+ )
353
+
354
+ hf_username = gr.Textbox(
355
+ placeholder="wseo", label="Your Hugging Face Username (case sensitive)"
356
+ )
357
+ first_name = gr.Textbox(placeholder="Wonhyeong", label="Your First Name")
358
+ last_name = gr.Textbox(placeholder="Seo", label="Your Last Name")
359
+
360
+ check_progress_button = gr.Button(value="Check if I pass and get the certificate")
361
+ output_text = gr.components.Textbox(label="Your Result")
362
+
363
+ with gr.Row(visible=True) as output_row:
364
+ output_pdf = gr.File()
365
+ output_img = gr.components.Image(type="pil")
366
+
367
+ check_progress_button.click(
368
+ fn=certification,
369
+ inputs=[hf_username, first_name, last_name],
370
+ outputs=[output_text, output_pdf, output_img, output_row],
371
+ )
372
+ with gr.Column() as leaderboard_column:
373
+ gr.Markdown(
374
+ f"""
375
+ ## ❤️ Leaderboard
376
+ The leaderboard showcases your contributions for easy sharing on SNS platforms:
377
+
378
+ - Event #1: *1 repo 1 share* - **share your contributions to the world!**
379
+ - (more on the way!)
380
+
381
+ For more information about the offline event [check our event-us page](https://event-us.kr/huggingfacekrew/event/72612).
382
+ 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.
383
+
384
+ <a class="twitter-share-button" data-size="large"
385
+ data-text="I'm participating in the Hugging Face KREW Hackathon 2023: Everyday AI! @wonhseo @huggingface"
386
+ data-url="https://huggingface.co/spaces/pseudolab/2023-Hackathon-Certification"
387
+ data-hashtags="huggingface,krewhackathon2023"
388
+ href="https://twitter.com/intent/tweet">
389
+ Tweet</a>
390
+ """
391
+ )
392
+ with gr.Row():
393
+ repos_data = gr.components.Dataframe(
394
+ type="pandas", datatype=["number", "markdown", "markdown", "number"]
395
+ )
396
+ with gr.Row():
397
+ data_run = gr.Button("Refresh")
398
+ data_run.click(
399
+ leaderboard, outputs=repos_data
400
+ )
401
+
402
+ scripts = """
403
+ async () => {
404
+ const twitter = await import("https://platform.twitter.com/widgets.js");
405
+ globalThis.twitter = twitter;
406
+ }
407
+ """
408
+
409
+ demo.load(leaderboard, outputs=repos_data)
410
+ demo.load(None, None, None, _js=scripts)
411
 
412
  demo.launch(debug=True)
hfkr_logo.png ADDED