Imane Momayiz commited on
Commit
bcb5974
1 Parent(s): cac7ab2

fix: ongoing

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