Imane Momayiz commited on
Commit
c5139c6
1 Parent(s): 954f8b9

fix: load data config name

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -4,14 +4,16 @@ import csv
4
  import datetime as dt
5
  import random
6
  import os
7
- from huggingface_hub import Repository
8
 
9
 
10
  HF_API_KEY = os.environ.get("HF_TOKEN", None)
11
 
 
 
12
  REPO_ID = "imomayiz/darija-english"
13
  DATASET_REPO_URL = f"https://huggingface.co/datasets/{REPO_ID}"
14
- DATA_FILE = os.path.join("submissions", "submissions.csv")
15
 
16
  submissions_repo = Repository(
17
  local_dir="submissions", clone_from=DATASET_REPO_URL, use_auth_token=HF_API_KEY
@@ -31,7 +33,7 @@ def fetch_sentence(dataset, column_name="darija_ar"):
31
 
32
  def store_submission(sentence: str, translation: str, translation_fr: str):
33
  if sentence and (translation or translation_fr):
34
- with open(DATA_FILE, "a") as csvfile:
35
  writer = csv.DictWriter(csvfile,
36
  fieldnames=["darija", "eng", "darija_ar", "time"])
37
  writer.writerow(
@@ -40,10 +42,14 @@ def store_submission(sentence: str, translation: str, translation_fr: str):
40
  "darija": translation_fr,
41
  "time": str(dt.datetime.now())}
42
  )
43
- commit_url = submissions_repo.push_to_hub(
44
- commit_message="Add new submission"
45
- )
46
- print(commit_url)
 
 
 
 
47
 
48
 
49
  # Load the dataset
 
4
  import datetime as dt
5
  import random
6
  import os
7
+ from huggingface_hub import Repository, HfApi
8
 
9
 
10
  HF_API_KEY = os.environ.get("HF_TOKEN", None)
11
 
12
+ api = HfApi(token=HF_API_KEY)
13
+
14
  REPO_ID = "imomayiz/darija-english"
15
  DATASET_REPO_URL = f"https://huggingface.co/datasets/{REPO_ID}"
16
+ SUBMISSIONS_DATA_FILE = os.path.join("submissions", "submissions.csv")
17
 
18
  submissions_repo = Repository(
19
  local_dir="submissions", clone_from=DATASET_REPO_URL, use_auth_token=HF_API_KEY
 
33
 
34
  def store_submission(sentence: str, translation: str, translation_fr: str):
35
  if sentence and (translation or translation_fr):
36
+ with open(SUBMISSIONS_DATA_FILE, "a") as csvfile:
37
  writer = csv.DictWriter(csvfile,
38
  fieldnames=["darija", "eng", "darija_ar", "time"])
39
  writer.writerow(
 
42
  "darija": translation_fr,
43
  "time": str(dt.datetime.now())}
44
  )
45
+ api.upload_file(
46
+ path_or_fileobj=SUBMISSIONS_DATA_FILE,
47
+ path_in_repo=SUBMISSIONS_DATA_FILE,
48
+ repo_id=REPO_ID,
49
+ repo_type="dataset",
50
+ commit_message="New submission",
51
+ )
52
+ st.success(f"Submitted at {DATASET_REPO_URL}/{SUBMISSIONS_DATA_FILE}")
53
 
54
 
55
  # Load the dataset