burtenshaw commited on
Commit
abfd25a
·
1 Parent(s): 5181d14
Files changed (1) hide show
  1. app.py +33 -22
app.py CHANGED
@@ -20,7 +20,9 @@ DATASET_REPO_URL = "https://huggingface.co/datasets/agents-course/certificates"
20
  CERTIFIED_USERS_FILENAME = "certified_students.csv"
21
  CERTIFIED_USERS_DIR = "certificates"
22
  repo = Repository(
23
- local_dir=CERTIFIED_USERS_DIR, clone_from=DATASET_REPO_URL, use_auth_token=os.getenv("HF_TOKEN")
 
 
24
  )
25
 
26
  # Convert dataset to a list of dicts and randomly sort
@@ -66,24 +68,35 @@ def on_user_logged_in(token: gr.OAuthToken | None):
66
  None, # no token
67
  ]
68
 
 
69
  def add_certified_user(hf_username, pass_percentage, submission_time):
70
- """
71
- Add the certified user to the database
72
- """
73
- print("ADD CERTIFIED USER")
74
- repo.git_pull()
75
- history = pd.read_csv(os.path.join(CERTIFIED_USERS_DIR, CERTIFIED_USERS_FILENAME))
76
-
77
- # Check if this hf_username is already in our dataset:
78
- check = history.loc[history['hf_username'] == hf_username]
79
- if not check.empty:
80
- history = history.drop(labels=check.index[0], axis=0)
81
-
82
- new_row = pd.DataFrame({'hf_username': hf_username, 'pass_percentage': pass_percentage, 'datetime': submission_time}, index=[0])
83
- history = pd.concat([new_row, history[:]]).reset_index(drop=True)
84
-
85
- history.to_csv(os.path.join(CERTIFIED_USERS_DIR, CERTIFIED_USERS_FILENAME), index=False)
86
- repo.push_to_hub(commit_message="Update certified users list")
 
 
 
 
 
 
 
 
 
 
87
 
88
  def push_results_to_hub(user_answers, token: gr.OAuthToken | None):
89
  """
@@ -127,10 +140,8 @@ def push_results_to_hub(user_answers, token: gr.OAuthToken | None):
127
  print("ADD CERTIFIED USER")
128
  # Add this user to our database
129
  add_certified_user(sanitized_name, grade, submission_time)
130
-
131
- return f"Your responses have been submitted to the Hub! Final grade: {grade:.1%}"
132
-
133
 
 
134
 
135
 
136
  def handle_quiz(
@@ -170,7 +181,7 @@ def handle_quiz(
170
  return [
171
  "", # question_text
172
  gr.update(choices=[], visible=False), # hide radio choices
173
- f"{'🎉 Passed! Click now on ✅ Submit to save your exam score!' if grade >= float(EXAM_PASSING_SCORE) else '❌ Did not pass'}",
174
  question_idx,
175
  user_answers,
176
  gr.update(visible=False), # start button visibility
 
20
  CERTIFIED_USERS_FILENAME = "certified_students.csv"
21
  CERTIFIED_USERS_DIR = "certificates"
22
  repo = Repository(
23
+ local_dir=CERTIFIED_USERS_DIR,
24
+ clone_from=DATASET_REPO_URL,
25
+ use_auth_token=os.getenv("HF_TOKEN"),
26
  )
27
 
28
  # Convert dataset to a list of dicts and randomly sort
 
68
  None, # no token
69
  ]
70
 
71
+
72
  def add_certified_user(hf_username, pass_percentage, submission_time):
73
+ """
74
+ Add the certified user to the database
75
+ """
76
+ print("ADD CERTIFIED USER")
77
+ repo.git_pull()
78
+ history = pd.read_csv(os.path.join(CERTIFIED_USERS_DIR, CERTIFIED_USERS_FILENAME))
79
+
80
+ # Check if this hf_username is already in our dataset:
81
+ check = history.loc[history["hf_username"] == hf_username]
82
+ if not check.empty:
83
+ history = history.drop(labels=check.index[0], axis=0)
84
+
85
+ new_row = pd.DataFrame(
86
+ {
87
+ "hf_username": hf_username,
88
+ "pass_percentage": pass_percentage,
89
+ "datetime": submission_time,
90
+ },
91
+ index=[0],
92
+ )
93
+ history = pd.concat([new_row, history[:]]).reset_index(drop=True)
94
+
95
+ history.to_csv(
96
+ os.path.join(CERTIFIED_USERS_DIR, CERTIFIED_USERS_FILENAME), index=False
97
+ )
98
+ repo.push_to_hub(commit_message="Update certified users list")
99
+
100
 
101
  def push_results_to_hub(user_answers, token: gr.OAuthToken | None):
102
  """
 
140
  print("ADD CERTIFIED USER")
141
  # Add this user to our database
142
  add_certified_user(sanitized_name, grade, submission_time)
 
 
 
143
 
144
+ return f"Your responses have been submitted to the Hub! Final grade: {grade:.1%}"
145
 
146
 
147
  def handle_quiz(
 
181
  return [
182
  "", # question_text
183
  gr.update(choices=[], visible=False), # hide radio choices
184
+ f"{'🎉 Passed! Click now on ✅ Submit to save your exam score!' if grade >= float(EXAM_PASSING_SCORE) else '❌ Did not pass'}",
185
  question_idx,
186
  user_answers,
187
  gr.update(visible=False), # start button visibility