Imane Momayiz commited on
Commit
9bfca27
·
1 Parent(s): 5ef45dd

fix: sumbimissions saving

Browse files
Files changed (1) hide show
  1. app.py +38 -34
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import streamlit as st
2
  from datasets import load_dataset
3
- import csv
4
  import datetime as dt
5
  import random
6
  import os
@@ -32,30 +31,38 @@ def fetch_sentence(dataset, column_name="darija_ar"):
32
  return random_sentence
33
 
34
  def store_submission(api: HfApi, sentence: str, translation: str, translation_fr: str):
35
-
36
- if sentence and (translation or translation_fr):
37
-
38
- ts = dt.datetime.now().strftime("%Y-%m-%d_%H-%M-%S-%f")
39
- folder_path = "submissions"
40
- os.makedirs(folder_path, exist_ok=True)
41
- filename = os.path.join(folder_path, f"submissions_{ts}.txt")
42
-
43
- with open(filename, "w", encoding="utf-8") as f:
44
- f.write(f"darija,eng,darija_ar\n{sentence},{translation},{translation_fr}")
45
-
46
- print(REPO_ID)
47
- print(filename)
48
- api.upload_folder(
49
- folder_path=folder_path,
50
- path_in_repo=folder_path,
51
- repo_id=REPO_ID,
52
- repo_type="dataset",
53
- commit_message="New submission",
54
- )
55
- st.success(
56
- f"""Translation submitted successfully to
57
- {DATASET_REPO_URL}/tree/main/{folder_path}"""
58
- )
 
 
 
 
 
 
 
 
59
 
60
 
61
  # Load the dataset
@@ -118,12 +125,9 @@ with translation_input_placeholder_fr.container():
118
  st.session_state.translation_input_fr = translation_input_fr
119
 
120
  # Submit button
121
- if st.button("Submit Translation"):
122
- if not translation_input and translation_input_fr:
123
- st.warning("Please enter a translation before submitting.")
124
- else:
125
- store_submission(api,
126
- st.session_state.sentence,
127
- st.session_state.translation_input,
128
- st.session_state.translation_input_fr
129
- )
 
1
  import streamlit as st
2
  from datasets import load_dataset
 
3
  import datetime as dt
4
  import random
5
  import os
 
31
  return random_sentence
32
 
33
  def store_submission(api: HfApi, sentence: str, translation: str, translation_fr: str):
34
+
35
+ if st.button("Submit Translation"):
36
+ if not translation_input and translation_input_fr:
37
+ st.warning("Please enter a translation before submitting.")
38
+ else:
39
+ ts = dt.datetime.now().strftime("%Y-%m-%d_%H-%M-%S-%f")
40
+ folder_path = "submissions"
41
+ os.makedirs(folder_path, exist_ok=True)
42
+ filename = os.path.join(folder_path, f"submissions_{ts}.txt")
43
+
44
+ with open(filename, "w", encoding="utf-8") as f:
45
+ f.write(f"darija,eng,darija_ar\n{sentence},{translation},{translation_fr}")
46
+
47
+ # api.upload_folder(
48
+ # folder_path=folder_path,
49
+ # path_in_repo=folder_path,
50
+ # repo_id=REPO_ID,
51
+ # repo_type="dataset",
52
+ # commit_message="New submission",
53
+ # )
54
+
55
+ api.upload_file(
56
+ path_or_fileobj=filename,
57
+ path_in_repo=filename,
58
+ repo_id=REPO_ID,
59
+ repo_type="dataset",
60
+ )
61
+
62
+ st.success(
63
+ f"""Translation submitted successfully to
64
+ {DATASET_REPO_URL}/tree/main/{folder_path}"""
65
+ )
66
 
67
 
68
  # Load the dataset
 
125
  st.session_state.translation_input_fr = translation_input_fr
126
 
127
  # Submit button
128
+
129
+ store_submission(api,
130
+ st.session_state.sentence,
131
+ st.session_state.translation_input,
132
+ st.session_state.translation_input_fr
133
+ )