wseo commited on
Commit
585af8d
β€’
1 Parent(s): 8bc3913

fix: fonts and content of certificate (#2)

Browse files

- fix: fonts and content of certificate (2fc3fc1b40c221d9e896af20903613116af2ed97)

Files changed (1) hide show
  1. app.py +25 -29
app.py CHANGED
@@ -8,75 +8,70 @@ from datetime import date
8
  import time
9
 
10
  import os
 
11
  import pandas as pd
12
  import json
13
 
14
  api = HfApi()
15
  HF_TOKEN = os.environ.get("HF_TOKEN")
16
 
17
- # Private dataset repo containing the list of already certified users
18
- DATASET_REPO_URL = "https://huggingface.co/datasets/MariaK/audio-course"
19
  CERTIFIED_USERS_FILENAME = "usernames.csv"
20
 
21
- # Private space to check if a user has passed.
22
- SPACE_ID = "MariaK/Check-Audio-Course-Progress"
23
 
24
-
25
- def check_if_passed(username):
26
  """
27
  Check if given user passed enough assignments
28
- :param username: User HF username
29
  """
30
 
31
  passed = False
32
  certificate_type = ""
33
 
34
- client = Client(SPACE_ID, hf_token=HF_TOKEN)
35
- result = client.predict(username, fn_index=0)
36
- with open(result) as json_data:
37
- data = json.load(json_data)
38
 
39
- df = pd.DataFrame(data['data'])
40
- if len(df[df.iloc[:,0] == 'βœ…']) == 4:
41
  passed = True
42
  certificate_type = "excellence"
43
- elif len(df[df.iloc[:,0] == 'βœ…']) == 3:
44
  passed = True
45
  certificate_type = "completion"
46
 
47
  return passed, certificate_type
48
 
49
 
50
- def generate_certificate(certificate_template, first_name, last_name):
51
  """
52
  Generates certificate from the template
53
  :param certificate_template: type of the certificate to generate
54
  :param first_name: first name entered by user
55
  :param last_name: last name entered by user
 
56
  """
57
 
58
  im = Image.open(certificate_template)
59
  d = ImageDraw.Draw(im)
60
 
61
- name_font = ImageFont.truetype("Quattrocento-Regular.ttf", 100)
62
- date_font = ImageFont.truetype("Quattrocento-Regular.ttf", 48)
63
 
64
  name = str(first_name) + " " + str(last_name)
65
  print("NAME", name)
66
 
67
  # Debug line name
68
- #d.line(((200, 740), (1800, 740)), "gray")
69
- #d.line(((1000, 0), (1000, 1400)), "gray")
70
 
71
  # Name
72
- d.text((1000, 740), name, fill="black", anchor="mm", font=name_font)
73
 
74
- # Debug line date
75
- #d.line(((1500, 0), (1500, 1400)), "gray")
76
 
77
  # Date of certification
78
- d.text((1480, 1170), str(date.today()), fill="black", anchor="mm", font=date_font)
79
-
80
 
81
  pdf = im.convert('RGB')
82
  pdf.save('certificate.pdf')
@@ -112,6 +107,7 @@ def create_certificate(passed, certificate_type, hf_username, first_name, last_n
112
  Generates certificate, adds message, saves username of the certified user
113
  :param passed: boolean whether the user passed enough assignments
114
  :param certificate_type: type of the certificate - completion or excellence
 
115
  :param first_name: first name entered by user
116
  :param last_name: last name entered by user
117
  """
@@ -120,7 +116,7 @@ def create_certificate(passed, certificate_type, hf_username, first_name, last_n
120
  # Generate a certificate of
121
  certificate, pdf = generate_certificate("./certificate-excellence.png", first_name, last_name, hf_username)
122
  # Add this user to our database
123
- add_certified_user(hf_username, first_name, last_name, certificate_type)
124
  # Add a message
125
  message = """
126
  Congratulations, you successfully completed the 2023 Hackathon πŸŽ‰! \n
@@ -132,7 +128,7 @@ def create_certificate(passed, certificate_type, hf_username, first_name, last_n
132
  # Generate a certificate of completion
133
  certificate, pdf = generate_certificate("./certificate-completion.png", first_name, last_name, hf_username)
134
  # Add this user to our database
135
- add_certified_user(hf_username, first_name, last_name, certificate_type)
136
  # Add a message
137
  message = """
138
  Congratulations, you successfully completed the 2023 Hackathon πŸŽ‰! \n
@@ -148,7 +144,7 @@ def create_certificate(passed, certificate_type, hf_username, first_name, last_n
148
  # Add a message
149
  message = """
150
  You didn't pass the minimum of one contribution to get a certificate of completion.
151
- For more information about the certification process, refer to the hackathon page.
152
  If the results here differ from your contributions, make sure you moved your space to the pseudolab organization.
153
  """
154
  return certificate, message, pdf
@@ -171,11 +167,11 @@ with gr.Blocks() as demo:
171
  # Get your 2023 Hackathon Certificate πŸŽ“
172
  The certification process is completely free:
173
  - To get a *certificate of completion*: you need to **contribute to at least one model, dataset, or space**.
174
- - To get a *certificate of excellence*: you need to **contribute to models, datasets, and spaces**. *(Yes, all three!)*
175
 
176
  For more information about the certification process [check the hackathon page on certification](https://pseudo-lab.github.io/huggingface-hackathon23/submit.html#certification).
177
 
178
- Don't hesitate to share your certificate on Twitter (tag me [@wonhseo](https://twitter.com/wonhseo), [@pseudolab](https://twitter.com/pseudolab), and [@huggingface](https://twitter.com/huggingface)) and on LinkedIn.
179
  """)
180
 
181
  hf_username = gr.Textbox(placeholder="wseo", label="Your Hugging Face Username (case sensitive)")
 
8
  import time
9
 
10
  import os
11
+ import sys
12
  import pandas as pd
13
  import json
14
 
15
  api = HfApi()
16
  HF_TOKEN = os.environ.get("HF_TOKEN")
17
 
18
+ # Public dataset repo containing the pdfs of already certified users
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 passed enough assignments
26
+ :param hf_username: Hugging Face Hub username
27
  """
28
 
29
  passed = False
30
  certificate_type = ""
31
 
32
+ # TODO: Get all the repos that the user contributed to in the organization using Git refs
 
 
 
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 False:
39
  passed = True
40
  certificate_type = "completion"
41
 
42
  return passed, certificate_type
43
 
44
 
45
+ def generate_certificate(certificate_template, first_name, last_name, hf_username):
46
  """
47
  Generates certificate from the template
48
  :param certificate_template: type of the certificate to generate
49
  :param first_name: first name entered by user
50
  :param last_name: last name entered by user
51
+ :param hf_username: Hugging Face Hub username entered by user
52
  """
53
 
54
  im = Image.open(certificate_template)
55
  d = ImageDraw.Draw(im)
56
 
57
+ name_font = ImageFont.truetype("HeiseiMinchoStdW7.otf", 60)
58
+ username_font = ImageFont.truetype("HeiseiMinchoStdW7.otf", 18)
59
 
60
  name = str(first_name) + " " + str(last_name)
61
  print("NAME", name)
62
 
63
  # Debug line name
64
+ #d.line(((0, 419), (1000, 419)), "gray")
65
+ #d.line(((538, 0), (538, 1400)), "gray")
66
 
67
  # Name
68
+ d.text((538, 419), name, fill=(87,87,87), anchor="mm", font=name_font)
69
 
70
+ # Debug line id
71
+ #d.line(((863, 0), (863, 1400)), "gray")
72
 
73
  # Date of certification
74
+ d.text((863, 336), f"psh23-{username}", fill=(117,117,117), anchor="mm", font=username_font)
 
75
 
76
  pdf = im.convert('RGB')
77
  pdf.save('certificate.pdf')
 
107
  Generates certificate, adds message, saves username of the certified user
108
  :param passed: boolean whether the user passed enough assignments
109
  :param certificate_type: type of the certificate - completion or excellence
110
+ :param hf_username: Hugging Face Hub username entered by user
111
  :param first_name: first name entered by user
112
  :param last_name: last name entered by user
113
  """
 
116
  # Generate a certificate of
117
  certificate, pdf = generate_certificate("./certificate-excellence.png", first_name, last_name, hf_username)
118
  # Add this user to our database
119
+ # add_certified_user(hf_username, first_name, last_name, certificate_type)
120
  # Add a message
121
  message = """
122
  Congratulations, you successfully completed the 2023 Hackathon πŸŽ‰! \n
 
128
  # Generate a certificate of completion
129
  certificate, pdf = generate_certificate("./certificate-completion.png", first_name, last_name, hf_username)
130
  # Add this user to our database
131
+ # add_certified_user(hf_username, first_name, last_name, certificate_type)
132
  # Add a message
133
  message = """
134
  Congratulations, you successfully completed the 2023 Hackathon πŸŽ‰! \n
 
144
  # Add a message
145
  message = """
146
  You didn't pass the minimum of one contribution to get a certificate of completion.
147
+ For more information about the certification process, refer to the submit page.
148
  If the results here differ from your contributions, make sure you moved your space to the pseudolab organization.
149
  """
150
  return certificate, message, pdf
 
167
  # Get your 2023 Hackathon Certificate πŸŽ“
168
  The certification process is completely free:
169
  - To get a *certificate of completion*: you need to **contribute to at least one model, dataset, or space**.
170
+ - To get a *certificate of excellence*: you need to **contribute to models, datasets, and spaces**.
171
 
172
  For more information about the certification process [check the hackathon page on certification](https://pseudo-lab.github.io/huggingface-hackathon23/submit.html#certification).
173
 
174
+ 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.
175
  """)
176
 
177
  hf_username = gr.Textbox(placeholder="wseo", label="Your Hugging Face Username (case sensitive)")