Imane Momayiz
commited on
Commit
·
7f57b0a
1
Parent(s):
8fd4345
fix: refresh after submission
Browse files- app.py +12 -6
- src/__pycache__/components.cpython-310.pyc +0 -0
- src/__pycache__/layout.cpython-310.pyc +0 -0
- src/components.py +7 -3
app.py
CHANGED
@@ -79,13 +79,19 @@ translation_input_fr = st.text_input(
|
|
79 |
)
|
80 |
st.session_state.translation_input_fr = translation_input_fr
|
81 |
|
82 |
-
#
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
store_submission(scheduler,
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
)
|
90 |
else:
|
91 |
st.warning("Please enter a translation before submitting.")
|
|
|
79 |
)
|
80 |
st.session_state.translation_input_fr = translation_input_fr
|
81 |
|
82 |
+
# Save states before refreshing the page
|
83 |
+
sentence = st.session_state.sentence
|
84 |
+
translation_input = st.session_state.translation_input
|
85 |
+
translation_input_fr = st.session_state.translation_input_fr
|
86 |
+
|
87 |
+
submit_button = st.button("Submit Translation",
|
88 |
+
on_click=fetch_sentence, args=(dataset,))
|
89 |
+
if submit_button:
|
90 |
+
if translation_input_fr or translation_input:
|
91 |
store_submission(scheduler,
|
92 |
+
sentence,
|
93 |
+
translation_input,
|
94 |
+
translation_input_fr
|
95 |
)
|
96 |
else:
|
97 |
st.warning("Please enter a translation before submitting.")
|
src/__pycache__/components.cpython-310.pyc
ADDED
Binary file (2.07 kB). View file
|
|
src/__pycache__/layout.cpython-310.pyc
ADDED
Binary file (582 Bytes). View file
|
|
src/components.py
CHANGED
@@ -15,8 +15,12 @@ submissions_folder = "submissions"
|
|
15 |
submissions_file = os.path.join(submissions_folder, f"submissions_{uuid.uuid4()}.json")
|
16 |
|
17 |
|
18 |
-
def load_data(repo_id):
|
19 |
-
dataset = load_dataset(
|
|
|
|
|
|
|
|
|
20 |
return dataset
|
21 |
|
22 |
def fetch_sentence(dataset, column_name="darija_ar"):
|
@@ -41,7 +45,7 @@ def store_submission(
|
|
41 |
ts = dt.datetime.now().strftime("%Y-%m-%d_%H-%M-%S-%f")
|
42 |
|
43 |
with scheduler.lock:
|
44 |
-
with open(submissions_file, "a") as f:
|
45 |
f.write(json.dumps({
|
46 |
"darija": translation_fr,
|
47 |
"eng": translation,
|
|
|
15 |
submissions_file = os.path.join(submissions_folder, f"submissions_{uuid.uuid4()}.json")
|
16 |
|
17 |
|
18 |
+
def load_data(repo_id, column_name="darija_ar"):
|
19 |
+
dataset = load_dataset(
|
20 |
+
f'{repo_id}',
|
21 |
+
name='sentences',
|
22 |
+
split='sentences')
|
23 |
+
dataset = dataset.select_columns(column_name)
|
24 |
return dataset
|
25 |
|
26 |
def fetch_sentence(dataset, column_name="darija_ar"):
|
|
|
45 |
ts = dt.datetime.now().strftime("%Y-%m-%d_%H-%M-%S-%f")
|
46 |
|
47 |
with scheduler.lock:
|
48 |
+
with open(submissions_file, "a", encoding='utf-8') as f:
|
49 |
f.write(json.dumps({
|
50 |
"darija": translation_fr,
|
51 |
"eng": translation,
|