Commit
β’
421b84e
1
Parent(s):
92c1738
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import HfApi, hf_hub_download
|
3 |
from huggingface_hub.repocard import metadata_load
|
|
|
4 |
|
5 |
-
import
|
6 |
|
7 |
import os
|
|
|
8 |
|
9 |
from utils import *
|
10 |
|
11 |
api = HfApi()
|
12 |
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
from mailchimp_transactional.api_client import ApiClientError
|
16 |
-
|
17 |
-
print(os.environ.get('MAILCHIMP_API_KEY'))
|
18 |
-
|
19 |
-
def run():
|
20 |
-
try:
|
21 |
-
mailchimp = MailchimpTransactional.Client(os.environ.get('MAILCHIMP_API_KEY'))
|
22 |
-
response = mailchimp.users.ping()
|
23 |
-
print('API called successfully: {}'.format(response))
|
24 |
-
except ApiClientError as error:
|
25 |
-
print('An exception occurred: {}'.format(error.text))
|
26 |
|
27 |
-
|
|
|
|
|
28 |
|
29 |
def get_user_models(hf_username, env_tag, lib_tag):
|
30 |
"""
|
@@ -251,10 +247,95 @@ def certification(hf_username):
|
|
251 |
|
252 |
print(results_certification)
|
253 |
|
254 |
-
|
255 |
-
|
|
|
|
|
|
|
|
|
256 |
return df
|
257 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
|
259 |
with gr.Blocks() as demo:
|
260 |
gr.Markdown(f"""
|
@@ -271,10 +352,12 @@ with gr.Blocks() as demo:
|
|
271 |
Just type your Hugging Face Username π€ (in my case ThomasSimonini)
|
272 |
""")
|
273 |
|
274 |
-
hf_username = gr.Textbox(placeholder="ThomasSimonini", label="Your Hugging Face Username")
|
275 |
-
|
|
|
|
|
276 |
check_progress_button = gr.Button(value="Check my progress")
|
277 |
output = gr.components.Dataframe(value= certification(hf_username), headers=["Pass?", "Unit", "Environment", "Baseline", "Your best result", "Your best model id"], datatype=["markdown", "markdown", "markdown", "number", "number", "markdown", "bool"])
|
278 |
check_progress_button.click(fn=certification, inputs=hf_username, outputs=output)
|
279 |
|
280 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import HfApi, hf_hub_download
|
3 |
from huggingface_hub.repocard import metadata_load
|
4 |
+
from huggingface_hub import HfApi, Repository
|
5 |
|
6 |
+
import time
|
7 |
|
8 |
import os
|
9 |
+
import pandas as pd
|
10 |
|
11 |
from utils import *
|
12 |
|
13 |
api = HfApi()
|
14 |
|
15 |
+
DATASET_REPO_URL = "https://huggingface.co/datasets/huggingface-projects/Deep-RL-Course-Certification"
|
16 |
+
CERTIFIED_USERS_FILENAME = "certified_users.csv"
|
17 |
+
CERTIFIED_USERS_DIR = "certified_users"
|
18 |
|
19 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
repo = Repository(
|
22 |
+
local_dir=CERTIFIED_USERS_DIR, clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
23 |
+
)
|
24 |
|
25 |
def get_user_models(hf_username, env_tag, lib_tag):
|
26 |
"""
|
|
|
247 |
|
248 |
print(results_certification)
|
249 |
|
250 |
+
df1 = pd.DataFrame(results_certification)
|
251 |
+
|
252 |
+
df = df1[['passed', 'unit', 'env', 'min_result', 'best_result', 'best_model_id']]
|
253 |
+
|
254 |
+
verify_certification(results_certification, hf_username, first_name, last_name)
|
255 |
+
|
256 |
return df
|
257 |
|
258 |
+
"""
|
259 |
+
Verify that the user pass.
|
260 |
+
If yes:
|
261 |
+
- Generate the certification
|
262 |
+
- Send an email
|
263 |
+
- Print the certification
|
264 |
+
|
265 |
+
If no:
|
266 |
+
- Explain why the user didn't pass yet
|
267 |
+
"""
|
268 |
+
def verify_certification(df, hf_username, first_name, last_name):
|
269 |
+
# Check that we pass
|
270 |
+
model_pass_nb = 0
|
271 |
+
pass_percentage = 0
|
272 |
+
for unit in df:
|
273 |
+
if unit["passed_"] is True:
|
274 |
+
model_pass_nb += 1
|
275 |
+
|
276 |
+
pass_percentage = (model_pass_nb/12) * 100
|
277 |
+
print("pass_percentage", pass_percentage)
|
278 |
+
|
279 |
+
if pass_percentage == 100:
|
280 |
+
# Generate a certificate of excellence
|
281 |
+
generate_certificate("./certificate_models/certificate-excellence.png", first_name, last_name)
|
282 |
+
|
283 |
+
# Add this user to our database
|
284 |
+
add_certified_user(hf_username, first_name, last_name, pass_percentage)
|
285 |
+
|
286 |
+
# Output everything in gradio
|
287 |
+
|
288 |
+
|
289 |
+
elif pass_percentage < 100 and pass_percentage >= 80:
|
290 |
+
# Certificate of completion
|
291 |
+
generate_certificate("./certificate_models/certificate-completion.png", first_name, last_name)
|
292 |
+
|
293 |
+
# Add this user to our database
|
294 |
+
add_certified_user(hf_username, first_name, last_name, pass_percentage)
|
295 |
+
|
296 |
+
# Output everything in gradio
|
297 |
+
|
298 |
+
|
299 |
+
else:
|
300 |
+
# Not pass yet
|
301 |
+
print ("not pass yet")
|
302 |
+
|
303 |
+
def generate_certificate(certificate_model, first_name, last_name):
|
304 |
+
im = Image.open(certificate_model)
|
305 |
+
d = ImageDraw.Draw(im)
|
306 |
+
|
307 |
+
name_font = ImageFont.truetype("Quattrocento-Regular.ttf", 100)
|
308 |
+
date_font = ImageFont.truetype("Quattrocento-Regular.ttf", 48)
|
309 |
+
|
310 |
+
name = first_name + " " + last_name
|
311 |
+
|
312 |
+
# Debug line name
|
313 |
+
#d.line(((200, 740), (1800, 740)), "gray")
|
314 |
+
#d.line(((1000, 0), (1000, 1400)), "gray")
|
315 |
+
|
316 |
+
# Name
|
317 |
+
d.text((1000, 740), name, fill="black", anchor="mm", font=name_font)
|
318 |
+
|
319 |
+
# Debug line date
|
320 |
+
#d.line(((1500, 0), (1500, 1400)), "gray")
|
321 |
+
|
322 |
+
# Date of certification
|
323 |
+
d.text((1480, 1170), str(date.today()), fill="black", anchor="mm", font=date_font)
|
324 |
+
|
325 |
+
im.save("certificate_"+".png")
|
326 |
+
|
327 |
+
|
328 |
+
def add_certified_user(hf_username, first_name, last_name, pass_percentage):
|
329 |
+
repo.git_pull()
|
330 |
+
history = pd.read_csv(os.path.join(CERTIFIED_USERS_DIR, CERTIFIED_USERS_FILENAME))
|
331 |
+
new_row = {'hf_username': hf_username, 'first_name': first_name, 'last_name': last_name, 'pass_percentage': pass_percentage, 'datetime': time.time()}
|
332 |
+
new_history = pd.DataFrame(new_row)
|
333 |
+
history = pd.concat([history, new_history])
|
334 |
+
print("HISTORY", history)
|
335 |
+
history.to_csv(os.path.join(CERTIFIED_USERS_DIR, CERTIFIED_USERS_FILENAME), index=False)
|
336 |
+
df.to_csv(os.path.join(CERTIFIED_USERS_DIR, CERTIFIED_USERS_FILENAME), index=False)
|
337 |
+
repo.push_to_hub(commit_message="Update certified users list")
|
338 |
+
|
339 |
|
340 |
with gr.Blocks() as demo:
|
341 |
gr.Markdown(f"""
|
|
|
352 |
Just type your Hugging Face Username π€ (in my case ThomasSimonini)
|
353 |
""")
|
354 |
|
355 |
+
hf_username = gr.Textbox(placeholder="ThomasSimonini", label="Your Hugging Face Username (case sensitive)")
|
356 |
+
first_name = gr.Textbox(placeholder="Jane", label="Your First Name")
|
357 |
+
last_name = gr.Textbox(placeholder="Doe", label="Your Last Name")
|
358 |
+
#email = gr.Textbox(placeholder="jane.doe@gmail.com", label="Your Email (to receive your certificate)")
|
359 |
check_progress_button = gr.Button(value="Check my progress")
|
360 |
output = gr.components.Dataframe(value= certification(hf_username), headers=["Pass?", "Unit", "Environment", "Baseline", "Your best result", "Your best model id"], datatype=["markdown", "markdown", "markdown", "number", "number", "markdown", "bool"])
|
361 |
check_progress_button.click(fn=certification, inputs=hf_username, outputs=output)
|
362 |
|
363 |
+
demo.launch(debug=True)
|