File size: 9,085 Bytes
b83a10b
 
 
 
 
 
ddf8478
b83a10b
 
 
99daaed
ddf8478
99daaed
ddf8478
99daaed
b83a10b
ddf8478
b83a10b
 
ddf8478
b83a10b
99daaed
 
b83a10b
 
 
 
 
 
 
 
 
99daaed
 
 
 
 
 
 
 
 
 
 
 
 
b83a10b
99daaed
b83a10b
 
 
 
 
 
 
99daaed
 
 
 
 
 
 
 
 
 
 
 
b83a10b
 
 
 
 
 
 
 
 
99daaed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddf8478
99daaed
 
ddf8478
99daaed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b83a10b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddf8478
b83a10b
 
ddf8478
b83a10b
 
99daaed
 
 
 
 
 
 
b83a10b
 
 
99daaed
b83a10b
 
 
 
 
 
 
ddf8478
b83a10b
 
 
 
 
 
 
 
 
 
 
 
 
 
ddf8478
b83a10b
ddf8478
b83a10b
99daaed
 
 
 
 
 
 
 
 
 
ddf8478
99daaed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddf8478
99daaed
ddf8478
99daaed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b83a10b
99daaed
b83a10b
99daaed
 
 
 
 
 
b83a10b
 
 
99daaed
b83a10b
 
 
99daaed
 
b83a10b
 
 
99daaed
 
b83a10b
99daaed
b83a10b
99daaed
 
b83a10b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
95
96
97
98
99
100
101
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import streamlit as st
import pandas as pd

st.markdown("Provide your own 🤗 sentences")

# recuperate the already saved sentences (for the moment french/wolof)
sentences_ = pd.read_csv('wolof_translate/data/sentences/wolof_french.csv')

sentences = sentences_.copy()

# get french and wolof sentences
french_examples = pd.read_csv('wolof_translate/data/sentences/french.csv')

wolof_examples = pd.read_csv('wolof_translate/data/sentences/wolof_2.csv')

# add special characters from Wolof
sp_wolof_chars = pd.read_csv('wolof_translate/data/wolof_writing/wolof_special_chars.csv')

# add definitions
sp_wolof_words = pd.read_csv('wolof_translate/data/wolof_writing/definitions.csv')

sp_wolof_words.sort_values(by = ['french', 'wolof'], inplace = True)

# initialize the input texts
st.title("Provide sentences below ⤵️")

st.markdown("""---""")

# create three columns
left, right = st.columns(2)

# let us add a callback functions to change the input text
def add_symbol_to_french():
    
    st.session_state.left_sentence += st.session_state.fr_symbol
    
def add_symbol_to_wolof():
    
    st.session_state.right_sentence += st.session_state.wf_symbol

def add_special_token_french():
    
    st.session_state.left_sentence += '<mask>'
    
def add_special_token_wolof():
    
    st.session_state.right_sentence += '<mask>'

def add_word_to_text():
    
    word = st.session_state.word.split('/')[0].strip()
    
    st.session_state.right_sentence += word

def add_french_sentence_to_text():
    
    sentence = st.session_state.french_sentence.strip()
    
    st.session_state.left_sentence = sentence
    
def add_wolof_sentence_to_text():
    
    sentence = st.session_state.wolof_sentence.strip()
    
    st.session_state.right_sentence = sentence

# let us create a callback which permit us to add sentences inside a DataFrame
def add_new_sentences():
    
    global sentences
    
    sentence_1 = st.session_state.left_sentence.strip()
    
    sentence_2 = st.session_state.right_sentence.strip()
    
    if sentence_1 == '' or sentence_2 == '':
        
        st.warning("You didn't provide a sentence ! Please provide before submitting.", icon= "🚨")
    
    else:
        
        if not sentences.empty > 0:
        
            sentences = pd.concat((sentences, pd.DataFrame({sentences.columns.tolist()[0]: [sentence_1], 
                                                   sentences.columns.tolist()[1]: [sentence_2]})))
        
        else:
            
            sentences = pd.DataFrame({sentences.columns.tolist()[0]: [sentence_1], 
                                                   sentences.columns.tolist()[1]: [sentence_2]})
        ## save the result
        sentences.to_csv('wolof_translate/data/sentences/wolof_french.csv', index=False)
        
        # recuperate the already saved sentences (for the moment french/wolof)
        sentences = pd.read_csv('wolof_translate/data/sentences/wolof_french.csv')
        
        # add the last position to delete and modify
        st.session_state.line1 = len(sentences) - 1
        
        st.session_state.line2 = len(sentences) - 1
        
# let us create a callback which permit us to add sentences inside a DataFrame
def add_new_sentences2():
    
    global sentences
    
    sentence_1 = st.session_state.left_sentence.strip()
    
    sentence_2 = st.session_state.right_sentence.strip()
    
    if sentence_1 == '' or sentence_2 == '':
        
        st.warning("You didn't provide a sentence ! Please provide before submitting.", icon= "🚨")
    
    else:
        
        if not sentences.empty > 0:
        
            sentences = pd.concat((sentences, pd.DataFrame({sentences.columns.tolist()[0]: [sentence_1], 
                                                   sentences.columns.tolist()[1]: [sentence_2]})))
        
        else:
            
            sentences = pd.DataFrame({sentences.columns.tolist()[0]: [sentence_1], 
                                                   sentences.columns.tolist()[1]: [sentence_2]})
        ## save the result
        sentences.to_csv('wolof_translate/data/sentences/wolof_french.csv', index=False)
        
        # recuperate the already saved sentences (for the moment french/wolof)
        sentences = pd.read_csv('wolof_translate/data/sentences/wolof_french.csv')
        
        # clean the inputs' contents
        st.session_state.left_sentence = ''
        st.session_state.right_sentence = ''
        
        # add the last position to delete and modify
        st.session_state.line1 = len(sentences) - 1
        
        st.session_state.line2 = len(sentences) - 1
        
def delete_line():
    
    number = st.session_state.line1
    
    if number > len(sentences) - 1:
        
        st.warning("The line that you provided does not exist !")
    
    else:
        
        deleted = pd.read_csv('wolof_translate/data/sentences/deleted_lines.csv')
        
        if not deleted.empty:
            
            deleted = pd.concat((deleted, pd.DataFrame({sentences.columns.tolist()[0]: [sentences.loc[number, sentences.columns.tolist()[0]]], 
                                                   sentences.columns.tolist()[1]: sentences.loc[number, sentences.columns.tolist()[1]]})))
        
        else:
            
            deleted = pd.DataFrame({sentences.columns.tolist()[0]: [sentences.loc[number, sentences.columns.tolist()[0]]], 
                                                   sentences.columns.tolist()[1]: sentences.loc[number, sentences.columns.tolist()[1]]})
        
        sentences.drop(index = number, inplace=True)
        
        ## save the result
        sentences.to_csv('wolof_translate/data/sentences/wolof_french.csv', index=False)
        
        deleted.to_csv('wolof_translate/data/sentences/deleted_lines.csv', index=False)

def modify_line():
    
    number = st.session_state.line2
    
    if number > len(sentences) - 1:
        
        st.warning("The line that you provided does not exist !")
    
    else:
        
        modified = pd.read_csv('wolof_translate/data/sentences/modified_lines.csv')
        
        if not modified.empty:
            
            modified = pd.concat((modified, pd.DataFrame({sentences.columns.tolist()[0]: [sentences.loc[number, sentences.columns.tolist()[0]]], 
                                                   sentences.columns.tolist()[1]: sentences.loc[number, sentences.columns.tolist()[1]]})))
        
        else:
            
            modified = pd.DataFrame({sentences.columns.tolist()[0]: [sentences.loc[number, sentences.columns.tolist()[0]]], 
                                                   sentences.columns.tolist()[1]: sentences.loc[number, sentences.columns.tolist()[1]]})
        
        st.session_state.left_sentence = sentences.loc[number, sentences.columns.tolist()[0]]
        
        st.session_state.right_sentence = sentences.loc[number, sentences.columns.tolist()[1]]
        
        sentences.drop(index = number, inplace=True)
        
        ## save the result
        sentences.to_csv('wolof_translate/data/sentences/wolof_french.csv', index=False)
        
        modified.to_csv('wolof_translate/data/sentences/deleted_lines.csv', index=False)


left.header("French")
left.text_area(sentences.columns.tolist()[0], key = "left_sentence")

right.header("Wolof")
right.text_area(sentences.columns.tolist()[1], key = "right_sentence")

fr_symbol = left.selectbox("French characters", key="fr_symbol", options = sp_wolof_chars['wolof_special_chars'])

wf_symbol = right.selectbox("Wolof characters", key="wf_symbol", options = sp_wolof_chars['wolof_special_chars'])

word = right.selectbox("Wolof words/Definitions", key="word", options = [sp_wolof_words.loc[i, 'wolof']+" / "+sp_wolof_words.loc[i, 'french'] for i in range(sp_wolof_words.shape[0])], on_change=add_word_to_text)

left.button("Add symbol", "add fr symbol", on_click=add_symbol_to_french)

left.button("Add mask", "french mask", on_click=add_special_token_french)

right.button("Add symbol", "add wf symbol", on_click=add_symbol_to_wolof)

right.button("Add mask", "wolof mask", on_click=add_special_token_wolof)

# add sentences at sidebar
st.sidebar.selectbox("French sentences", key="french_sentence", options = french_examples['sentences'], on_change=add_french_sentence_to_text)

st.sidebar.selectbox("Wolof sentences", key="wolof_sentence", options = wolof_examples['sentences'], on_change=add_wolof_sentence_to_text)

# add a submit button to add new sentences
st.button('Submit', 'submit_button', on_click=add_new_sentences)
st.button('Place', 'submit_button2', on_click=add_new_sentences2)

st.markdown("""---""")

# add delete button
number = st.number_input("Provide line to delete", key="line1", min_value=0)

st.button("Delete", 'delete_button', on_click=delete_line)

# add modify button
number = st.number_input("Provide line to modify", key="line2", min_value=0)

st.button("Modify", 'modify_button', on_click=modify_line)

# add data frame
st.dataframe(sentences, width=900)