Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -206,13 +206,22 @@ def search_similar_information_page(model):
|
|
| 206 |
st.write("No embedding could be generated for the search query.")
|
| 207 |
|
| 208 |
# Page for translation
|
| 209 |
-
def translate_text_page(
|
| 210 |
-
st.subheader("Translate
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
st.
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
# Streamlit app
|
| 218 |
def main():
|
|
@@ -222,12 +231,17 @@ def main():
|
|
| 222 |
if 'fasttext_model' not in st.session_state:
|
| 223 |
st.session_state['fasttext_model'] = load_fasttext_model("Fast_text_50_dim")
|
| 224 |
|
| 225 |
-
if '
|
| 226 |
-
st.session_state['
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
fasttext_model = st.session_state['fasttext_model']
|
| 229 |
-
|
| 230 |
-
|
|
|
|
|
|
|
| 231 |
|
| 232 |
st.sidebar.title("Options")
|
| 233 |
option = st.sidebar.radio("Select an option", ("Clean Dataset", "Train Word Embedding", "Generate Embeddings", "Translate Text"))
|
|
@@ -284,8 +298,8 @@ def main():
|
|
| 284 |
search_similar_information_page(fasttext_model)
|
| 285 |
|
| 286 |
elif option == "Translate Text":
|
| 287 |
-
st.header("Translate Text
|
| 288 |
-
translate_text_page(
|
| 289 |
|
| 290 |
if __name__ == "__main__":
|
| 291 |
main()
|
|
|
|
| 206 |
st.write("No embedding could be generated for the search query.")
|
| 207 |
|
| 208 |
# Page for translation
|
| 209 |
+
def translate_text_page(tokenizer_shona_to_english, model_shona_to_english, tokenizer_english_to_shona, model_english_to_shona):
|
| 210 |
+
st.subheader("Translate Text")
|
| 211 |
+
translation_direction = st.radio("Select translation direction", ("Shona to English", "English to Shona"))
|
| 212 |
+
|
| 213 |
+
if translation_direction == "Shona to English":
|
| 214 |
+
text_to_translate = st.text_area("Enter Shona text to translate:")
|
| 215 |
+
if text_to_translate:
|
| 216 |
+
translated_text = translate_text(text_to_translate, tokenizer_shona_to_english, model_shona_to_english)
|
| 217 |
+
st.write("Translated text:")
|
| 218 |
+
st.write(translated_text)
|
| 219 |
+
else:
|
| 220 |
+
text_to_translate = st.text_area("Enter English text to translate:")
|
| 221 |
+
if text_to_translate:
|
| 222 |
+
translated_text = translate_text(text_to_translate, tokenizer_english_to_shona, model_english_to_shona)
|
| 223 |
+
st.write("Translated text:")
|
| 224 |
+
st.write(translated_text)
|
| 225 |
|
| 226 |
# Streamlit app
|
| 227 |
def main():
|
|
|
|
| 231 |
if 'fasttext_model' not in st.session_state:
|
| 232 |
st.session_state['fasttext_model'] = load_fasttext_model("Fast_text_50_dim")
|
| 233 |
|
| 234 |
+
if 'translation_model_shona_to_english' not in st.session_state:
|
| 235 |
+
st.session_state['tokenizer_shona_to_english'], st.session_state['translation_model_shona_to_english'] = load_translation_model("fine_tuned_shona_to_english_model")
|
| 236 |
+
|
| 237 |
+
if 'translation_model_english_to_shona' not in st.session_state:
|
| 238 |
+
st.session_state['tokenizer_english_to_shona'], st.session_state['translation_model_english_to_shona'] = load_translation_model("english_shona_model")
|
| 239 |
|
| 240 |
fasttext_model = st.session_state['fasttext_model']
|
| 241 |
+
tokenizer_shona_to_english = st.session_state['tokenizer_shona_to_english']
|
| 242 |
+
translation_model_shona_to_english = st.session_state['translation_model_shona_to_english']
|
| 243 |
+
tokenizer_english_to_shona = st.session_state['tokenizer_english_to_shona']
|
| 244 |
+
translation_model_english_to_shona = st.session_state['translation_model_english_to_shona']
|
| 245 |
|
| 246 |
st.sidebar.title("Options")
|
| 247 |
option = st.sidebar.radio("Select an option", ("Clean Dataset", "Train Word Embedding", "Generate Embeddings", "Translate Text"))
|
|
|
|
| 298 |
search_similar_information_page(fasttext_model)
|
| 299 |
|
| 300 |
elif option == "Translate Text":
|
| 301 |
+
st.header("Translate Text")
|
| 302 |
+
translate_text_page(tokenizer_shona_to_english, translation_model_shona_to_english, tokenizer_english_to_shona, translation_model_english_to_shona)
|
| 303 |
|
| 304 |
if __name__ == "__main__":
|
| 305 |
main()
|