Imane Momayiz
commited on
Commit
·
d853c9c
1
Parent(s):
7f57b0a
fix: added cache, fixed async caused by data reloading
Browse files- app.py +21 -19
- src/__pycache__/components.cpython-310.pyc +0 -0
- src/components.py +4 -5
app.py
CHANGED
|
@@ -22,6 +22,13 @@ scheduler = CommitScheduler(
|
|
| 22 |
every=10,
|
| 23 |
)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Load the dataset
|
| 26 |
dataset = load_data(REPO_ID)
|
| 27 |
|
|
@@ -35,12 +42,7 @@ if 'translation_input_fr' not in st.session_state:
|
|
| 35 |
if 'display_new' not in st.session_state:
|
| 36 |
st.session_state.display_new = False
|
| 37 |
|
| 38 |
-
# Set page config
|
| 39 |
-
st.set_page_config(page_title="DODa",
|
| 40 |
-
page_icon=DODA_LOGO,)
|
| 41 |
|
| 42 |
-
# add an image
|
| 43 |
-
st.image(DODA_LOGO, use_column_width=True)
|
| 44 |
|
| 45 |
# title
|
| 46 |
st.title("DODa Labeling App")
|
|
@@ -60,7 +62,7 @@ st.write(f"""
|
|
| 60 |
|
| 61 |
|
| 62 |
# Display new sentence button
|
| 63 |
-
st.session_state.display_new = st.button("
|
| 64 |
on_click=fetch_sentence,
|
| 65 |
args=(dataset,))
|
| 66 |
|
|
@@ -70,29 +72,29 @@ translation_input = st.text_input(
|
|
| 70 |
"Enter translation to english: ",
|
| 71 |
st.session_state.translation_input
|
| 72 |
)
|
| 73 |
-
st.session_state.translation_input = translation_input
|
| 74 |
|
| 75 |
# Input field for translation in latin characters
|
| 76 |
translation_input_fr = st.text_input(
|
| 77 |
"Enter translation to darija in latin characters: ",
|
| 78 |
st.session_state.translation_input_fr
|
| 79 |
)
|
|
|
|
|
|
|
| 80 |
st.session_state.translation_input_fr = translation_input_fr
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
translation_input_fr = st.session_state.translation_input_fr
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 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.")
|
| 98 |
-
|
|
|
|
| 22 |
every=10,
|
| 23 |
)
|
| 24 |
|
| 25 |
+
# Set page config
|
| 26 |
+
st.set_page_config(page_title="DODa",
|
| 27 |
+
page_icon=DODA_LOGO,)
|
| 28 |
+
|
| 29 |
+
# add an image
|
| 30 |
+
st.image(DODA_LOGO, use_column_width=True)
|
| 31 |
+
|
| 32 |
# Load the dataset
|
| 33 |
dataset = load_data(REPO_ID)
|
| 34 |
|
|
|
|
| 42 |
if 'display_new' not in st.session_state:
|
| 43 |
st.session_state.display_new = False
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# title
|
| 48 |
st.title("DODa Labeling App")
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
# Display new sentence button
|
| 65 |
+
st.session_state.display_new = st.button("Generate a new sentence",
|
| 66 |
on_click=fetch_sentence,
|
| 67 |
args=(dataset,))
|
| 68 |
|
|
|
|
| 72 |
"Enter translation to english: ",
|
| 73 |
st.session_state.translation_input
|
| 74 |
)
|
|
|
|
| 75 |
|
| 76 |
# Input field for translation in latin characters
|
| 77 |
translation_input_fr = st.text_input(
|
| 78 |
"Enter translation to darija in latin characters: ",
|
| 79 |
st.session_state.translation_input_fr
|
| 80 |
)
|
| 81 |
+
|
| 82 |
+
st.session_state.translation_input = translation_input
|
| 83 |
st.session_state.translation_input_fr = translation_input_fr
|
| 84 |
|
| 85 |
+
print(st.session_state.sentence)
|
| 86 |
+
print(st.session_state.translation_input)
|
| 87 |
+
print(st.session_state.translation_input_fr)
|
|
|
|
| 88 |
|
| 89 |
+
# Save states before refreshing the page
|
| 90 |
+
submit_button = st.button("Submit Translation")
|
| 91 |
if submit_button:
|
| 92 |
+
if st.session_state.translation_input_fr or st.session_state.translation_input:
|
| 93 |
store_submission(scheduler,
|
| 94 |
+
st.session_state.sentence,
|
| 95 |
+
st.session_state.translation_input,
|
| 96 |
+
st.session_state.translation_input_fr
|
| 97 |
)
|
| 98 |
+
_ = fetch_sentence(dataset)
|
| 99 |
else:
|
| 100 |
+
st.warning("Please enter a translation before submitting.")
|
|
|
src/__pycache__/components.cpython-310.pyc
CHANGED
|
Binary files a/src/__pycache__/components.cpython-310.pyc and b/src/__pycache__/components.cpython-310.pyc differ
|
|
|
src/components.py
CHANGED
|
@@ -5,16 +5,16 @@ import json
|
|
| 5 |
import os
|
| 6 |
from huggingface_hub import CommitScheduler
|
| 7 |
from datasets import load_dataset
|
| 8 |
-
import uuid
|
| 9 |
|
|
|
|
| 10 |
|
| 11 |
REPO_ID = "imomayiz/darija-english"
|
| 12 |
DATASET_REPO_URL = f"https://huggingface.co/datasets/{REPO_ID}"
|
| 13 |
|
| 14 |
submissions_folder = "submissions"
|
| 15 |
-
submissions_file = os.path.join(submissions_folder, f"submissions_{
|
| 16 |
-
|
| 17 |
|
|
|
|
| 18 |
def load_data(repo_id, column_name="darija_ar"):
|
| 19 |
dataset = load_dataset(
|
| 20 |
f'{repo_id}',
|
|
@@ -32,7 +32,6 @@ def fetch_sentence(dataset, column_name="darija_ar"):
|
|
| 32 |
st.session_state.sentence = random_sentence
|
| 33 |
st.session_state.translation_input = ""
|
| 34 |
st.session_state.translation_input_fr = ""
|
| 35 |
-
|
| 36 |
return random_sentence
|
| 37 |
|
| 38 |
def store_submission(
|
|
@@ -57,7 +56,7 @@ def store_submission(
|
|
| 57 |
|
| 58 |
st.success(
|
| 59 |
f"""Translation submitted successfully.
|
| 60 |
-
You will see your commit in
|
| 61 |
{DATASET_REPO_URL}/tree/main/{submissions_folder}.
|
| 62 |
You can submit another translation or check the dataset."""
|
| 63 |
)
|
|
|
|
| 5 |
import os
|
| 6 |
from huggingface_hub import CommitScheduler
|
| 7 |
from datasets import load_dataset
|
|
|
|
| 8 |
|
| 9 |
+
today = dt.datetime.now().strftime("%Y%m%d_%H%M")
|
| 10 |
|
| 11 |
REPO_ID = "imomayiz/darija-english"
|
| 12 |
DATASET_REPO_URL = f"https://huggingface.co/datasets/{REPO_ID}"
|
| 13 |
|
| 14 |
submissions_folder = "submissions"
|
| 15 |
+
submissions_file = os.path.join(submissions_folder, f"submissions_{today}.json")
|
|
|
|
| 16 |
|
| 17 |
+
@st.cache_data
|
| 18 |
def load_data(repo_id, column_name="darija_ar"):
|
| 19 |
dataset = load_dataset(
|
| 20 |
f'{repo_id}',
|
|
|
|
| 32 |
st.session_state.sentence = random_sentence
|
| 33 |
st.session_state.translation_input = ""
|
| 34 |
st.session_state.translation_input_fr = ""
|
|
|
|
| 35 |
return random_sentence
|
| 36 |
|
| 37 |
def store_submission(
|
|
|
|
| 56 |
|
| 57 |
st.success(
|
| 58 |
f"""Translation submitted successfully.
|
| 59 |
+
You will see your commit in a few minutes at
|
| 60 |
{DATASET_REPO_URL}/tree/main/{submissions_folder}.
|
| 61 |
You can submit another translation or check the dataset."""
|
| 62 |
)
|