feat: check if user passed hackathon (#3)
Browse files- feat: check if user passed hackathon (06735809450dbaec195f09bab2aaaed56e34c24a)
app.py
CHANGED
|
@@ -19,23 +19,56 @@ HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
| 19 |
DATASET_REPO_URL = "https://huggingface.co/datasets/wseo/huggingface-krew-hackathon23"
|
| 20 |
CERTIFIED_USERS_FILENAME = "usernames.csv"
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
def check_if_passed(hf_username):
|
| 24 |
"""
|
| 25 |
-
Check if given user
|
| 26 |
-
:param hf_username:
|
| 27 |
"""
|
| 28 |
|
| 29 |
passed = False
|
| 30 |
certificate_type = ""
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
# TODO: If the user contributed to all repo types (model, dataset, space) then assign excellence
|
| 35 |
-
if True:
|
| 36 |
passed = True
|
| 37 |
certificate_type = "excellence"
|
| 38 |
-
elif
|
| 39 |
passed = True
|
| 40 |
certificate_type = "completion"
|
| 41 |
|
|
@@ -71,7 +104,7 @@ def generate_certificate(certificate_template, first_name, last_name, hf_usernam
|
|
| 71 |
#d.line(((863, 0), (863, 1400)), "gray")
|
| 72 |
|
| 73 |
# Date of certification
|
| 74 |
-
d.text((863, 336), f"
|
| 75 |
|
| 76 |
pdf = im.convert('RGB')
|
| 77 |
pdf.save('certificate.pdf')
|
|
|
|
| 19 |
DATASET_REPO_URL = "https://huggingface.co/datasets/wseo/huggingface-krew-hackathon23"
|
| 20 |
CERTIFIED_USERS_FILENAME = "usernames.csv"
|
| 21 |
|
| 22 |
+
ORGANIZATION = "pseudolab"
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def has_contributions(repo_type, hf_username, organization):
|
| 26 |
+
"""
|
| 27 |
+
Check if a user has contributions in the specified repository type.
|
| 28 |
+
:param repo_type: A repo type supported by the Hub
|
| 29 |
+
:param hf_username: HF Hub username
|
| 30 |
+
:param organization: HF Hub organization
|
| 31 |
+
"""
|
| 32 |
+
repo_list = {
|
| 33 |
+
'model': api.list_models,
|
| 34 |
+
'dataset': api.list_datasets,
|
| 35 |
+
'space': api.list_spaces
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
for repo in repo_list[repo_type](author=organization):
|
| 39 |
+
commits = api.list_repo_commits(repo.id, repo_type=repo_type)
|
| 40 |
+
if any(hf_username in commit.authors for commit in commits):
|
| 41 |
+
return True
|
| 42 |
+
return False
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def get_hub_footprint(hf_username, organization):
|
| 46 |
+
"""
|
| 47 |
+
Check the types of contributions a user has made.
|
| 48 |
+
:param hf_username: HF Hub username
|
| 49 |
+
:param organization: HF Hub organization
|
| 50 |
+
"""
|
| 51 |
+
has_models = has_contributions('model', hf_username, organization)
|
| 52 |
+
has_datasets = has_contributions('dataset', hf_username, organization)
|
| 53 |
+
has_spaces = has_contributions('space', hf_username, organization)
|
| 54 |
+
|
| 55 |
+
return (has_models, has_datasets, has_spaces)
|
| 56 |
+
|
| 57 |
|
| 58 |
def check_if_passed(hf_username):
|
| 59 |
"""
|
| 60 |
+
Check if given user contributed to hackathon
|
| 61 |
+
:param hf_username: HF Hub username
|
| 62 |
"""
|
| 63 |
|
| 64 |
passed = False
|
| 65 |
certificate_type = ""
|
| 66 |
|
| 67 |
+
# If the user contributed to models, datasets and spaces then assign excellence
|
| 68 |
+
if all(get_hub_footprint(hf_username, ORGANIZATION)):
|
|
|
|
|
|
|
| 69 |
passed = True
|
| 70 |
certificate_type = "excellence"
|
| 71 |
+
elif any(get_hub_footprint(hf_username, ORGANIZATION)):
|
| 72 |
passed = True
|
| 73 |
certificate_type = "completion"
|
| 74 |
|
|
|
|
| 104 |
#d.line(((863, 0), (863, 1400)), "gray")
|
| 105 |
|
| 106 |
# Date of certification
|
| 107 |
+
d.text((863, 336), f"HKH23-{username}", fill=(117,117,117), anchor="mm", font=username_font)
|
| 108 |
|
| 109 |
pdf = im.convert('RGB')
|
| 110 |
pdf.save('certificate.pdf')
|