ThomasSimonini HF Staff commited on
Commit
a13afb6
·
verified ·
1 Parent(s): 42d1834

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -25,14 +25,23 @@ def has_certificate_entry(username):
25
 
26
  # Function to add certificate entry
27
  def add_certificate_entry(username, name):
 
 
 
 
 
 
 
28
  new_entry = {
29
  "username": username,
30
  "name": name,
31
- "timestamp": datetime.now().strftime("%Y-%m-%d"),
32
  }
33
- ds = load_dataset(CERTIFICATES_DATASET, split="train")
34
- ds = ds.add_item(new_entry)
35
- ds.push_to_hub(CERTIFICATES_DATASET)
 
 
36
 
37
  # Function to generate certificate PDF
38
  def generate_certificate(name, score):
 
25
 
26
  # Function to add certificate entry
27
  def add_certificate_entry(username, name):
28
+ # Load current dataset
29
+ ds = load_dataset(CERTIFICATES_DATASET, split="train", download_mode="force_redownload")
30
+
31
+ # Remove any existing entry with the same username
32
+ filtered_rows = [row for row in ds if row["username"] != username]
33
+
34
+ # Append the updated/new entry
35
  new_entry = {
36
  "username": username,
37
  "name": name,
38
+ "timestamp": datetime.now().isoformat()
39
  }
40
+ filtered_rows.append(new_entry)
41
+
42
+ # Rebuild dataset and push
43
+ updated_ds = Dataset.from_list(filtered_rows)
44
+ updated_ds.push_to_hub(CERTIFICATES_DATASET)
45
 
46
  # Function to generate certificate PDF
47
  def generate_certificate(name, score):