Update app.py
Browse files
app.py
CHANGED
|
@@ -28,23 +28,23 @@ def check_if_passed(username):
|
|
| 28 |
:param username: User HF username
|
| 29 |
"""
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
| 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 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 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):
|