Spaces:
Sleeping
Sleeping
=
commited on
Commit
·
8bda43d
1
Parent(s):
395e237
adding new modification method
Browse files
pages/provide_sentences_mongo.py
CHANGED
@@ -166,39 +166,13 @@ def modify_line():
|
|
166 |
st.warning("The line that you provided does not exist !")
|
167 |
|
168 |
else:
|
|
|
169 |
st.session_state.left_sentence = sentences.loc[number, sentences.columns.tolist()[1]]
|
170 |
|
171 |
st.session_state.right_sentence = sentences.loc[number, sentences.columns.tolist()[2]]
|
172 |
|
173 |
-
#
|
174 |
-
|
175 |
-
|
176 |
-
def update_sentences():
|
177 |
-
|
178 |
-
global sentences
|
179 |
-
|
180 |
-
number = st.session_state.line2
|
181 |
-
|
182 |
-
sentence_1 = st.session_state.left_sentence.strip()
|
183 |
-
|
184 |
-
sentence_2 = st.session_state.right_sentence.strip()
|
185 |
-
|
186 |
-
if number > len(sentences) - 1:
|
187 |
-
|
188 |
-
st.warning("The line that you provided does not exist !")
|
189 |
-
|
190 |
-
elif sentence_1 == '' or sentence_2 == '':
|
191 |
-
|
192 |
-
st.warning("You didn't provide a sentence ! Please provide before submitting.", icon= "🚨")
|
193 |
-
|
194 |
-
else:
|
195 |
-
st.write(sentence_1)
|
196 |
-
st.write(sentence_2)
|
197 |
-
db_manager.update_document(number,
|
198 |
-
{
|
199 |
-
'french': sentence_1,
|
200 |
-
'wolof': sentence_2
|
201 |
-
})
|
202 |
|
203 |
# recuperate the already saved sentences (for the moment french/wolof)
|
204 |
sentences = db_manager.load_data_frames()
|
@@ -231,7 +205,6 @@ st.sidebar.selectbox("Wolof sentences", key="wolof_sentence", options = wolof_ex
|
|
231 |
# add a submit button to add new sentences
|
232 |
st.button('Submit', 'submit_button', on_click=add_new_sentences, help="Place the new sentences without deleting them.")
|
233 |
st.button('Place', 'submit_button2', on_click=add_new_sentences2, help="Remove sentences when placing them inside the data set.")
|
234 |
-
st.button('Update', 'submit_button3', on_click=update_sentences, help="Modify the sentences at the index indicated to 'Provide line to modify'.")
|
235 |
|
236 |
st.markdown("""---""")
|
237 |
|
|
|
166 |
st.warning("The line that you provided does not exist !")
|
167 |
|
168 |
else:
|
169 |
+
|
170 |
st.session_state.left_sentence = sentences.loc[number, sentences.columns.tolist()[1]]
|
171 |
|
172 |
st.session_state.right_sentence = sentences.loc[number, sentences.columns.tolist()[2]]
|
173 |
|
174 |
+
# add the document to update to the updated documents
|
175 |
+
db_manager.update_document(number)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
|
177 |
# recuperate the already saved sentences (for the moment french/wolof)
|
178 |
sentences = db_manager.load_data_frames()
|
|
|
205 |
# add a submit button to add new sentences
|
206 |
st.button('Submit', 'submit_button', on_click=add_new_sentences, help="Place the new sentences without deleting them.")
|
207 |
st.button('Place', 'submit_button2', on_click=add_new_sentences2, help="Remove sentences when placing them inside the data set.")
|
|
|
208 |
|
209 |
st.markdown("""---""")
|
210 |
|
send_and_retrieve_data.ipynb
CHANGED
@@ -658,7 +658,7 @@
|
|
658 |
},
|
659 |
{
|
660 |
"cell_type": "code",
|
661 |
-
"execution_count":
|
662 |
"metadata": {},
|
663 |
"outputs": [
|
664 |
{
|
@@ -708,7 +708,7 @@
|
|
708 |
" \n",
|
709 |
" return results\n",
|
710 |
" \n",
|
711 |
-
" def update_document(self, id: int,
|
712 |
" \n",
|
713 |
" # recuperate the document to update\n",
|
714 |
" upd_sent = self.db[collection].find_one(\n",
|
@@ -719,15 +719,10 @@
|
|
719 |
" }\n",
|
720 |
" )\n",
|
721 |
" \n",
|
722 |
-
" #
|
723 |
-
"
|
724 |
-
" {\n",
|
725 |
-
" '_id': {\n",
|
726 |
-
" '$eq': id\n",
|
727 |
-
" }\n",
|
728 |
-
" },\n",
|
729 |
" {\n",
|
730 |
-
" '$
|
731 |
" }\n",
|
732 |
" )\n",
|
733 |
" \n",
|
|
|
658 |
},
|
659 |
{
|
660 |
"cell_type": "code",
|
661 |
+
"execution_count": 3,
|
662 |
"metadata": {},
|
663 |
"outputs": [
|
664 |
{
|
|
|
708 |
" \n",
|
709 |
" return results\n",
|
710 |
" \n",
|
711 |
+
" def update_document(self, id: int, collection: str = \"sentences\", update_collection: str = \"updated\"):\n",
|
712 |
" \n",
|
713 |
" # recuperate the document to update\n",
|
714 |
" upd_sent = self.db[collection].find_one(\n",
|
|
|
719 |
" }\n",
|
720 |
" )\n",
|
721 |
" \n",
|
722 |
+
" # delete the document\n",
|
723 |
+
" self.db[collection].delete_one(\n",
|
|
|
|
|
|
|
|
|
|
|
724 |
" {\n",
|
725 |
+
" '_id': {'$eq': del_sent['_id']}\n",
|
726 |
" }\n",
|
727 |
" )\n",
|
728 |
" \n",
|
wolof_translate/utils/database_manager.py
CHANGED
@@ -35,7 +35,7 @@ class TranslationMongoDBManager:
|
|
35 |
|
36 |
return results
|
37 |
|
38 |
-
def update_document(self, id: int,
|
39 |
|
40 |
# recuperate the document to update
|
41 |
upd_sent = self.db[collection].find_one(
|
@@ -46,15 +46,10 @@ class TranslationMongoDBManager:
|
|
46 |
}
|
47 |
)
|
48 |
|
49 |
-
#
|
50 |
-
|
51 |
-
{
|
52 |
-
'_id': {
|
53 |
-
'$eq': id
|
54 |
-
}
|
55 |
-
},
|
56 |
{
|
57 |
-
'$
|
58 |
}
|
59 |
)
|
60 |
|
|
|
35 |
|
36 |
return results
|
37 |
|
38 |
+
def update_document(self, id: int, collection: str = "sentences", update_collection: str = "updated"):
|
39 |
|
40 |
# recuperate the document to update
|
41 |
upd_sent = self.db[collection].find_one(
|
|
|
46 |
}
|
47 |
)
|
48 |
|
49 |
+
# delete the document
|
50 |
+
self.db[collection].delete_one(
|
|
|
|
|
|
|
|
|
|
|
51 |
{
|
52 |
+
'_id': {'$eq': del_sent['_id']}
|
53 |
}
|
54 |
)
|
55 |
|