MariaK commited on
Commit
f7db876
β€’
1 Parent(s): ce9fae3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -52
app.py CHANGED
@@ -28,23 +28,23 @@ def check_if_passed(username):
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):
@@ -116,44 +116,42 @@ def create_certificate(passed, certificate_type, hf_username, first_name, last_n
116
  :param last_name: last name entered by user
117
  """
118
 
119
- if passed and certificate_type == "excellence":
120
- # Generate a certificate of excellence
121
- certificate, pdf = generate_certificate("./certificate-excellence.png", first_name, last_name)
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 Hugging Face Audio Course πŸŽ‰! \n
127
- Since you pass 100% of the hands-on you get a Certificate of Excellence πŸŽ“. \n
128
- You can download your certificate below ⬇️ \n
129
- Don't hesitate to share your certificate image below on Twitter and Linkedin (you can tag me @mariakhalusova and @huggingface) πŸ€—
130
- """
131
- elif passed and certificate_type == "completion":
132
-
133
- # Generate a certificate of completion
134
- certificate, pdf = generate_certificate("./certificate-completion.png", first_name, last_name)
135
- # Add this user to our database
136
- add_certified_user(hf_username, first_name, last_name, certificate_type)
137
- # Add a message
138
- message = """
139
- Congratulations, you successfully completed the Hugging Face Deep Reinforcement Learning Course πŸŽ‰! \n
140
- Since you pass 80% of the hands-on you get a Certificate of Completion πŸŽ“. \n
141
- You can download your certificate below ⬇️ \n
142
- Don't hesitate to share your certificate image below on Twitter and Linkedin (you can tag me @mariakhalusova and @huggingface) πŸ€— \n
143
- You can try to get a Certificate of Excellence if you pass 100% of the hands-on, don't hesitate to check which unit you didn't pass and update these models.
144
- """
145
- else:
146
- # Not passed yet
147
- certificate = Image.new("RGB", (100, 100), (255, 255, 255))
148
- pdf = "./fail.pdf"
149
-
150
- # Add a message
151
- message = """
152
- You didn't pass the minimum of 3 out of 4 of the hands-on to get a certificate of completion.
153
- For more information about the certification process [check the course page on certification](https://huggingface.co/learn/audio-course/chapter8/certification).
154
- Use the [self-evaluation space](https://huggingface.co/spaces/MariaK/Check-my-progress-Audio-Course) to see which assignments have not been completed.
155
- """
156
- return certificate, message, pdf
157
 
158
 
159
  def certification(hf_username, first_name, last_name):
 
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):
 
116
  :param last_name: last name entered by user
117
  """
118
 
119
+ if passed and certificate_type == "excellence":
120
+ # Generate a certificate of
121
+ certificate, pdf = generate_certificate("./certificate-excellence.png", first_name, last_name)
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 Hugging Face Audio Course πŸŽ‰! \n
127
+ Since you pass 100% of the hands-on you get a Certificate of Excellence πŸŽ“. \n
128
+ You can download your certificate below ⬇️ \n
129
+ Don't hesitate to share your certificate image below on Twitter and Linkedin (you can tag me @mariakhalusova and @huggingface) πŸ€—
130
+ """
131
+ elif passed and certificate_type == "completion":
132
+ # Generate a certificate of completion
133
+ certificate, pdf = generate_certificate("./certificate-completion.png", first_name, last_name)
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 Hugging Face Deep Reinforcement Learning Course πŸŽ‰! \n
139
+ Since you pass 80% of the hands-on you get a Certificate of Completion πŸŽ“. \n
140
+ You can download your certificate below ⬇️ \n
141
+ Don't hesitate to share your certificate image below on Twitter and Linkedin (you can tag me @mariakhalusova and @huggingface) πŸ€— \n
142
+ You can try to get a Certificate of Excellence if you pass 100% of the hands-on, don't hesitate to check which unit you didn't pass and update these models.
143
+ """
144
+ else:
145
+ # Not passed yet
146
+ certificate = Image.new("RGB", (100, 100), (255, 255, 255))
147
+ pdf = "./fail.pdf"
148
+ # Add a message
149
+ message = """
150
+ You didn't pass the minimum of 3 out of 4 of the hands-on to get a certificate of completion.
151
+ For more information about the certification process [check the course page on certification](https://huggingface.co/learn/audio-course/chapter8/certification).
152
+ Use the [self-evaluation space](https://huggingface.co/spaces/MariaK/Check-my-progress-Audio-Course) to see which assignments have not been completed.
153
+ """
154
+ return certificate, message, pdf
 
 
155
 
156
 
157
  def certification(hf_username, first_name, last_name):