Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
burtenshaw
commited on
Commit
·
b4d0ff6
1
Parent(s):
b0bb8b4
add custom name button
Browse files
app.py
CHANGED
@@ -21,9 +21,7 @@ def download_profile_picture(profile_url: str):
|
|
21 |
return Image.open(BytesIO(response.content))
|
22 |
|
23 |
|
24 |
-
def generate_certificate(
|
25 |
-
certificate_path: str, first_name: str, last_name: str, profile_url: str
|
26 |
-
):
|
27 |
"""Generate certificate image and PDF."""
|
28 |
im = Image.open(certificate_path)
|
29 |
d = ImageDraw.Draw(im)
|
@@ -31,8 +29,6 @@ def generate_certificate(
|
|
31 |
name_font = ImageFont.truetype("Quattrocento-Regular.ttf", 100)
|
32 |
date_font = ImageFont.truetype("Quattrocento-Regular.ttf", 48)
|
33 |
|
34 |
-
name = f"{first_name} {last_name}"
|
35 |
-
|
36 |
# Capitalize first letter of each name
|
37 |
name = name.title()
|
38 |
|
@@ -133,25 +129,26 @@ def upload_certificate_to_hub(username: str, certificate_img) -> str:
|
|
133 |
return None
|
134 |
|
135 |
|
136 |
-
def check_certification(
|
|
|
|
|
|
|
|
|
137 |
"""Check certification status for logged-in user."""
|
138 |
if token is None or profile is None:
|
139 |
gr.Warning("Please log in to Hugging Face before checking certification!")
|
140 |
-
return None, None,
|
141 |
|
142 |
username = profile.username
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
except IndexError:
|
147 |
-
last_name = ""
|
148 |
profile_url = profile.picture
|
149 |
|
150 |
if not username:
|
151 |
return (
|
152 |
"Please login with your Hugging Face account to check certification status",
|
153 |
None,
|
154 |
-
None,
|
155 |
gr.Row.update(visible=False),
|
156 |
)
|
157 |
|
@@ -163,8 +160,7 @@ def check_certification(token: gr.OAuthToken | None, profile: gr.OAuthProfile |
|
|
163 |
if result.passed and result.certificate_path:
|
164 |
certificate_img, pdf_path = generate_certificate(
|
165 |
certificate_path=result.certificate_path,
|
166 |
-
|
167 |
-
last_name=last_name,
|
168 |
profile_url=profile_url,
|
169 |
)
|
170 |
|
@@ -193,12 +189,20 @@ with gr.Blocks() as demo:
|
|
193 |
|
194 |
To earn this certificate, you need to complete <a href="https://hf.co/learn/agents-course/unit1/introduction" alt="Agent Course Unit 1"/>Unit 1 of the Agents Course</a> and **pass 80% of the final quiz**.
|
195 |
|
196 |
-
Once you receive your certificate, don
|
197 |
"""
|
198 |
)
|
199 |
|
200 |
-
|
201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
|
203 |
check_progress_button = gr.Button(value="Get My Certificate")
|
204 |
|
@@ -207,6 +211,7 @@ with gr.Blocks() as demo:
|
|
207 |
|
208 |
check_progress_button.click(
|
209 |
fn=check_certification,
|
|
|
210 |
outputs=[output_text, output_img],
|
211 |
).then(
|
212 |
fn=join_finishers_org,
|
|
|
21 |
return Image.open(BytesIO(response.content))
|
22 |
|
23 |
|
24 |
+
def generate_certificate(certificate_path: str, name: str, profile_url: str):
|
|
|
|
|
25 |
"""Generate certificate image and PDF."""
|
26 |
im = Image.open(certificate_path)
|
27 |
d = ImageDraw.Draw(im)
|
|
|
29 |
name_font = ImageFont.truetype("Quattrocento-Regular.ttf", 100)
|
30 |
date_font = ImageFont.truetype("Quattrocento-Regular.ttf", 48)
|
31 |
|
|
|
|
|
32 |
# Capitalize first letter of each name
|
33 |
name = name.title()
|
34 |
|
|
|
129 |
return None
|
130 |
|
131 |
|
132 |
+
def check_certification(
|
133 |
+
token: gr.OAuthToken | None,
|
134 |
+
profile: gr.OAuthProfile | None,
|
135 |
+
custom_name: str | None = None,
|
136 |
+
):
|
137 |
"""Check certification status for logged-in user."""
|
138 |
if token is None or profile is None:
|
139 |
gr.Warning("Please log in to Hugging Face before checking certification!")
|
140 |
+
return None, None, gr.Row.update(visible=False)
|
141 |
|
142 |
username = profile.username
|
143 |
+
|
144 |
+
# Use custom name if provided, otherwise fall back to profile name
|
145 |
+
name = custom_name.strip() if custom_name and custom_name.strip() else profile.name
|
|
|
|
|
146 |
profile_url = profile.picture
|
147 |
|
148 |
if not username:
|
149 |
return (
|
150 |
"Please login with your Hugging Face account to check certification status",
|
151 |
None,
|
|
|
152 |
gr.Row.update(visible=False),
|
153 |
)
|
154 |
|
|
|
160 |
if result.passed and result.certificate_path:
|
161 |
certificate_img, pdf_path = generate_certificate(
|
162 |
certificate_path=result.certificate_path,
|
163 |
+
name=name,
|
|
|
164 |
profile_url=profile_url,
|
165 |
)
|
166 |
|
|
|
189 |
|
190 |
To earn this certificate, you need to complete <a href="https://hf.co/learn/agents-course/unit1/introduction" alt="Agent Course Unit 1"/>Unit 1 of the Agents Course</a> and **pass 80% of the final quiz**.
|
191 |
|
192 |
+
Once you receive your certificate, don't hesitate to share it on X (and tag @huggingface) as well as on LinkedIn so that we can congratulate you.
|
193 |
"""
|
194 |
)
|
195 |
|
196 |
+
with gr.Row():
|
197 |
+
# Add login button
|
198 |
+
gr.LoginButton()
|
199 |
+
|
200 |
+
# Add optional name input
|
201 |
+
custom_name_input = gr.Textbox(
|
202 |
+
label="Custom Name (Optional)",
|
203 |
+
placeholder="Enter your name as you want it to appear on the certificate",
|
204 |
+
info="Leave empty to use your Hugging Face profile name",
|
205 |
+
)
|
206 |
|
207 |
check_progress_button = gr.Button(value="Get My Certificate")
|
208 |
|
|
|
211 |
|
212 |
check_progress_button.click(
|
213 |
fn=check_certification,
|
214 |
+
inputs=[custom_name_input],
|
215 |
outputs=[output_text, output_img],
|
216 |
).then(
|
217 |
fn=join_finishers_org,
|