Imane Momayiz
commited on
Commit
·
5ef45dd
1
Parent(s):
2ce4d20
fix: sumbimissions saving
Browse files
app.py
CHANGED
@@ -62,73 +62,68 @@ def store_submission(api: HfApi, sentence: str, translation: str, translation_fr
|
|
62 |
dataset = load_data(REPO_ID)
|
63 |
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
<p style="font-size: 20px;">{st.session_state.sentence}.</p>
|
95 |
-
</div>""", unsafe_allow_html=True)
|
96 |
-
|
97 |
-
|
98 |
-
# Display new sentence button
|
99 |
-
st.session_state.display_new = st.button("New Sentence",
|
100 |
-
on_click=fetch_sentence,
|
101 |
-
args=(dataset,))
|
102 |
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
62 |
dataset = load_data(REPO_ID)
|
63 |
|
64 |
|
65 |
+
if "sentence" not in st.session_state:
|
66 |
+
st.session_state.sentence = fetch_sentence(dataset)
|
67 |
+
if 'translation_input' not in st.session_state:
|
68 |
+
st.session_state.translation_input = ""
|
69 |
+
if 'translation_input_fr' not in st.session_state:
|
70 |
+
st.session_state.translation_input_fr = ""
|
71 |
+
if 'display_new' not in st.session_state:
|
72 |
+
st.session_state.display_new = False
|
73 |
+
|
74 |
+
st.title("Translate From Arabic to English")
|
75 |
+
|
76 |
+
st.markdown(
|
77 |
+
"""This mini-app allows you to contribute to the **darija-english** dataset
|
78 |
+
as part of [DODa](https://darija-open-dataset.github.io/)
|
79 |
+
project. To contribute, simply translate the given sentence from Arabic to English.
|
80 |
+
The translated sentence will be submitted to the dataset
|
81 |
+
[here](https://huggingface.co/datasets/imomayiz/darija-english)."""
|
82 |
+
)
|
83 |
+
|
84 |
+
st.text("")
|
85 |
+
|
86 |
+
st.write(f"""
|
87 |
+
<div style="
|
88 |
+
padding: 5px;
|
89 |
+
border: 1px solid #000000;
|
90 |
+
border-radius: 5px;
|
91 |
+
">
|
92 |
+
<p style="font-size: 20px;">{st.session_state.sentence}.</p>
|
93 |
+
</div>""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
|
96 |
+
# Display new sentence button
|
97 |
+
st.session_state.display_new = st.button("New Sentence",
|
98 |
+
on_click=fetch_sentence,
|
99 |
+
args=(dataset,))
|
100 |
+
|
101 |
+
|
102 |
+
# Input field for translation
|
103 |
+
translation_input_placeholder = st.empty()
|
104 |
+
|
105 |
+
with translation_input_placeholder.container():
|
106 |
+
translation_input = st.text_input("Enter translation to english: ",
|
107 |
+
st.session_state.translation_input)
|
108 |
+
st.session_state.translation_input = translation_input
|
109 |
+
|
110 |
+
# Input field for translation
|
111 |
+
translation_input_placeholder_fr = st.empty()
|
112 |
+
|
113 |
+
with translation_input_placeholder_fr.container():
|
114 |
+
translation_input_fr = st.text_input(
|
115 |
+
"Enter translation to darija in latin characters: ",
|
116 |
+
st.session_state.translation_input_fr
|
117 |
+
)
|
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 |
+
)
|